libndb: open internal file-descriptors with OCEXEC flag
parent
5e59c57bb1
commit
1a900513fb
|
@ -25,10 +25,10 @@ csgetvalue(char *netroot, char *attr, char *val, char *rattr, Ndbtuple **pp)
|
||||||
snprint(line, sizeof(line), "%s/cs", netroot);
|
snprint(line, sizeof(line), "%s/cs", netroot);
|
||||||
else
|
else
|
||||||
strcpy(line, "/net/cs");
|
strcpy(line, "/net/cs");
|
||||||
fd = open(line, ORDWR);
|
fd = open(line, ORDWR|OCEXEC);
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
return nil;
|
return nil;
|
||||||
seek(fd, 0, 0);
|
|
||||||
snprint(line, sizeof(line), "!%s=%s %s=*", attr, val, rattr);
|
snprint(line, sizeof(line), "!%s=%s %s=*", attr, val, rattr);
|
||||||
if(write(fd, line, strlen(line)) < 0){
|
if(write(fd, line, strlen(line)) < 0){
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
@ -23,10 +23,10 @@ csipinfo(char *netroot, char *attr, char *val, char **list, int n)
|
||||||
snprint(line, sizeof(line), "%s/cs", netroot);
|
snprint(line, sizeof(line), "%s/cs", netroot);
|
||||||
else
|
else
|
||||||
strcpy(line, "/net/cs");
|
strcpy(line, "/net/cs");
|
||||||
fd = open(line, ORDWR);
|
fd = open(line, ORDWR|OCEXEC);
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
return 0;
|
return nil;
|
||||||
seek(fd, 0, 0);
|
|
||||||
e = line + sizeof(line);
|
e = line + sizeof(line);
|
||||||
p = seprint(line, e, "!ipinfo %s=%s", attr, val);
|
p = seprint(line, e, "!ipinfo %s=%s", attr, val);
|
||||||
for(i = 0; i < n; i++){
|
for(i = 0; i < n; i++){
|
||||||
|
@ -37,11 +37,11 @@ csipinfo(char *netroot, char *attr, char *val, char **list, int n)
|
||||||
|
|
||||||
if(write(fd, line, strlen(line)) < 0){
|
if(write(fd, line, strlen(line)) < 0){
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return nil;
|
||||||
}
|
}
|
||||||
seek(fd, 0, 0);
|
seek(fd, 0, 0);
|
||||||
|
|
||||||
first = last = 0;
|
first = last = nil;
|
||||||
for(;;){
|
for(;;){
|
||||||
n = read(fd, line, sizeof(line)-2);
|
n = read(fd, line, sizeof(line)-2);
|
||||||
if(n <= 0)
|
if(n <= 0)
|
||||||
|
@ -50,15 +50,15 @@ csipinfo(char *netroot, char *attr, char *val, char **list, int n)
|
||||||
line[n+1] = 0;
|
line[n+1] = 0;
|
||||||
|
|
||||||
t = _ndbparseline(line);
|
t = _ndbparseline(line);
|
||||||
if(t == 0)
|
if(t == nil)
|
||||||
continue;
|
continue;
|
||||||
if(first)
|
if(first != nil)
|
||||||
last->entry = t;
|
last->entry = t;
|
||||||
else
|
else
|
||||||
first = t;
|
first = t;
|
||||||
last = t;
|
last = t;
|
||||||
|
|
||||||
while(last->entry)
|
while(last->entry != nil)
|
||||||
last = last->entry;
|
last = last->entry;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
@ -29,7 +29,7 @@ dnsquery(char *net, char *val, char *type)
|
||||||
net = "/net";
|
net = "/net";
|
||||||
|
|
||||||
snprint(buf, sizeof(buf), "%s/dns", net);
|
snprint(buf, sizeof(buf), "%s/dns", net);
|
||||||
if((fd = open(buf, ORDWR)) < 0)
|
if((fd = open(buf, ORDWR|OCEXEC)) < 0)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
/* zero out the error string */
|
/* zero out the error string */
|
||||||
|
@ -84,7 +84,6 @@ doquery(int fd, char *dn, char *type)
|
||||||
int n;
|
int n;
|
||||||
Ndbtuple *t, *first, *last;
|
Ndbtuple *t, *first, *last;
|
||||||
|
|
||||||
seek(fd, 0, 0);
|
|
||||||
snprint(buf, sizeof(buf), "!%s %s", dn, type);
|
snprint(buf, sizeof(buf), "!%s %s", dn, type);
|
||||||
if(write(fd, buf, strlen(buf)) < 0)
|
if(write(fd, buf, strlen(buf)) < 0)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
|
@ -57,42 +57,42 @@ hfopen(Ndb *db, char *attr)
|
||||||
|
|
||||||
/* try opening the data base if it's closed */
|
/* try opening the data base if it's closed */
|
||||||
if(db->mtime==0 && ndbreopen(db) < 0)
|
if(db->mtime==0 && ndbreopen(db) < 0)
|
||||||
return 0;
|
return nil;
|
||||||
|
|
||||||
/* if the database has changed, throw out hash files and reopen db */
|
/* if the database has changed, throw out hash files and reopen db */
|
||||||
if((d = dirfstat(Bfildes(&db->b))) == nil || db->qid.path != d->qid.path
|
if((d = dirfstat(Bfildes(&db->b))) == nil || db->qid.path != d->qid.path
|
||||||
|| db->qid.vers != d->qid.vers){
|
|| db->qid.vers != d->qid.vers){
|
||||||
if(ndbreopen(db) < 0){
|
if(ndbreopen(db) < 0){
|
||||||
free(d);
|
free(d);
|
||||||
return 0;
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(d);
|
free(d);
|
||||||
|
|
||||||
if(db->nohash)
|
if(db->nohash)
|
||||||
return 0;
|
return nil;
|
||||||
|
|
||||||
/* see if a hash file exists for this attribute */
|
/* see if a hash file exists for this attribute */
|
||||||
for(hf = db->hf; hf; hf= hf->next){
|
for(hf = db->hf; hf != nil; hf= hf->next){
|
||||||
if(strcmp(hf->attr, attr) == 0)
|
if(strcmp(hf->attr, attr) == 0)
|
||||||
return hf;
|
return hf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a new one */
|
/* create a new one */
|
||||||
hf = (Ndbhf*)malloc(sizeof(Ndbhf));
|
hf = (Ndbhf*)malloc(sizeof(Ndbhf));
|
||||||
if(hf == 0)
|
if(hf == nil)
|
||||||
return 0;
|
return nil;
|
||||||
memset(hf, 0, sizeof(Ndbhf));
|
memset(hf, 0, sizeof(Ndbhf));
|
||||||
|
|
||||||
/* compare it to the database file */
|
/* compare it to the database file */
|
||||||
strncpy(hf->attr, attr, sizeof(hf->attr)-1);
|
strncpy(hf->attr, attr, sizeof(hf->attr)-1);
|
||||||
sprint(buf, "%s.%s", db->file, hf->attr);
|
sprint(buf, "%s.%s", db->file, hf->attr);
|
||||||
hf->fd = open(buf, OREAD);
|
hf->fd = open(buf, OREAD|OCEXEC);
|
||||||
if(hf->fd >= 0){
|
if(hf->fd >= 0){
|
||||||
hf->len = 0;
|
hf->len = 0;
|
||||||
hf->off = 0;
|
hf->off = 0;
|
||||||
p = hfread(hf, 0, 2*NDBULLEN);
|
p = hfread(hf, 0, 2*NDBULLEN);
|
||||||
if(p){
|
if(p != nil){
|
||||||
hf->dbmtime = NDBGETUL(p);
|
hf->dbmtime = NDBGETUL(p);
|
||||||
hf->hlen = NDBGETUL(p+NDBULLEN);
|
hf->hlen = NDBGETUL(p+NDBULLEN);
|
||||||
if(hf->dbmtime == db->mtime){
|
if(hf->dbmtime == db->mtime){
|
||||||
|
@ -105,7 +105,7 @@ hfopen(Ndb *db, char *attr)
|
||||||
}
|
}
|
||||||
|
|
||||||
free(hf);
|
free(hf);
|
||||||
return 0;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -162,7 +162,7 @@ match(Ndbtuple *t, char *attr, char *val)
|
||||||
if(strcmp(attr, nt->attr) == 0
|
if(strcmp(attr, nt->attr) == 0
|
||||||
&& strcmp(val, nt->val) == 0)
|
&& strcmp(val, nt->val) == 0)
|
||||||
return nt;
|
return nt;
|
||||||
return 0;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -99,7 +99,7 @@ ndbreopen(Ndb *db)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* try the open again */
|
/* try the open again */
|
||||||
fd = open(db->file, OREAD);
|
fd = open(db->file, OREAD|OCEXEC);
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
d = dirfstat(fd);
|
d = dirfstat(fd);
|
||||||
|
|
Loading…
Reference in New Issue