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