version 1.7, 1994/03/06 07:54:35 |
version 1.40, 2004/04/23 14:47:52 |
|
|
|
/* $NetBSD$ */ |
|
|
/*- |
/*- |
* Copyright (c) 1992 The Regents of the University of California. |
* Copyright (c) 1992, 1993 |
* All rights reserved. |
* The Regents of the University of California. All rights reserved. |
* |
* |
* This code is derived from software contributed to Berkeley by |
* This code is derived from software contributed to Berkeley by |
* Casey Leedom of Lawrence Livermore National Laboratory. |
* Casey Leedom of Lawrence Livermore National Laboratory. |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
* 3. All advertising materials mentioning features or use of this software |
* 3. Neither the name of the University nor the names of its contributors |
* must display the following acknowledgement: |
|
* This product includes software developed by the University of |
|
* California, Berkeley and its contributors. |
|
* 4. Neither the name of the University nor the names of its contributors |
|
* may be used to endorse or promote products derived from this software |
* may be used to endorse or promote products derived from this software |
* without specific prior written permission. |
* without specific prior written permission. |
* |
* |
|
|
* SUCH DAMAGE. |
* SUCH DAMAGE. |
*/ |
*/ |
|
|
|
#if HAVE_NBTOOL_CONFIG_H |
|
#include "nbtool_config.h" |
|
#endif |
|
|
|
#include <sys/cdefs.h> |
#if defined(LIBC_SCCS) && !defined(lint) |
#if defined(LIBC_SCCS) && !defined(lint) |
/*static char *sccsid = "from: @(#)getcap.c 5.15 (Berkeley) 3/19/93";*/ |
#if 0 |
static char *rcsid = "$Id$"; |
static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; |
|
#else |
|
__RCSID("$NetBSD$"); |
|
#endif |
#endif /* LIBC_SCCS and not lint */ |
#endif /* LIBC_SCCS and not lint */ |
|
|
|
#include "namespace.h" |
#include <sys/types.h> |
#include <sys/types.h> |
|
#include <sys/param.h> |
|
|
|
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <db.h> |
#include <db.h> |
#include <errno.h> |
#include <errno.h> |
Line 51 static char *rcsid = "$Id$"; |
|
Line 60 static char *rcsid = "$Id$"; |
|
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
|
#ifdef __weak_alias |
|
__weak_alias(cgetcap,_cgetcap) |
|
__weak_alias(cgetclose,_cgetclose) |
|
__weak_alias(cgetent,_cgetent) |
|
__weak_alias(cgetfirst,_cgetfirst) |
|
__weak_alias(cgetmatch,_cgetmatch) |
|
__weak_alias(cgetnext,_cgetnext) |
|
__weak_alias(cgetnum,_cgetnum) |
|
__weak_alias(cgetset,_cgetset) |
|
__weak_alias(cgetstr,_cgetstr) |
|
__weak_alias(cgetustr,_cgetustr) |
|
#endif |
|
|
#define BFRAG 1024 |
#define BFRAG 1024 |
#define BSIZE 1024 |
#define BSIZE 1024 |
#define ESC ('[' & 037) /* ASCII ESC */ |
#define ESC ('[' & 037) /* ASCII ESC */ |
Line 65 static size_t topreclen; /* toprec leng |
|
Line 87 static size_t topreclen; /* toprec leng |
|
static char *toprec; /* Additional record specified by cgetset() */ |
static char *toprec; /* Additional record specified by cgetset() */ |
static int gottoprec; /* Flag indicating retrieval of toprecord */ |
static int gottoprec; /* Flag indicating retrieval of toprecord */ |
|
|
static int cdbget __P((DB *, char **, char *)); |
static int cdbget(DB *, char **, const char *); |
static int getent __P((char **, u_int *, char **, int, char *, int, char *)); |
static int getent(char **, size_t *, const char * const *, int, |
static int nfcmp __P((char *, char *)); |
const char *, int, char *); |
|
static int nfcmp(char *, char *); |
|
|
/* |
/* |
* Cgetset() allows the addition of a user specified buffer to be added |
* Cgetset() allows the addition of a user specified buffer to be added |
Line 75 static int nfcmp __P((char *, char *)); |
|
Line 98 static int nfcmp __P((char *, char *)); |
|
* virtual database. 0 is returned on success, -1 on failure. |
* virtual database. 0 is returned on success, -1 on failure. |
*/ |
*/ |
int |
int |
cgetset(ent) |
cgetset(const char *ent) |
char *ent; |
|
{ |
{ |
|
const char *source, *check; |
|
char *dest; |
|
|
if (ent == NULL) { |
if (ent == NULL) { |
if (toprec) |
if (toprec) |
free(toprec); |
free(toprec); |
|
|
return (-1); |
return (-1); |
} |
} |
gottoprec = 0; |
gottoprec = 0; |
(void)strcpy(toprec, ent); |
|
|
source=ent; |
|
dest=toprec; |
|
while (*source) { /* Strip whitespace */ |
|
*dest++ = *source++; /* Do not check first field */ |
|
while (*source == ':') { |
|
check=source+1; |
|
while (*check && (isspace((unsigned char)*check) || |
|
(*check=='\\' && isspace((unsigned char)check[1])))) |
|
++check; |
|
if( *check == ':' ) |
|
source=check; |
|
else |
|
break; |
|
|
|
} |
|
} |
|
*dest=0; |
|
|
return (0); |
return (0); |
} |
} |
|
|
|
|
*/ |
*/ |
char * |
char * |
cgetcap(buf, cap, type) |
cgetcap(buf, cap, type) |
char *buf, *cap; |
char *buf; |
|
const char *cap; |
int type; |
int type; |
{ |
{ |
register char *bp, *cp; |
char *bp; |
|
const char *cp; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(cap != NULL); |
|
|
bp = buf; |
bp = buf; |
for (;;) { |
for (;;) { |
Line 160 cgetcap(buf, cap, type) |
|
Line 208 cgetcap(buf, cap, type) |
|
* reference loop is detected. |
* reference loop is detected. |
*/ |
*/ |
int |
int |
cgetent(buf, db_array, name) |
cgetent(char **buf, const char * const *db_array, const char *name) |
char **buf, **db_array, *name; |
|
{ |
{ |
u_int dummy; |
size_t dummy; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(db_array != NULL); |
|
_DIAGASSERT(name != NULL); |
|
|
return (getent(buf, &dummy, db_array, -1, name, 0, NULL)); |
return (getent(buf, &dummy, db_array, -1, name, 0, NULL)); |
} |
} |
Line 187 cgetent(buf, db_array, name) |
|
Line 238 cgetent(buf, db_array, name) |
|
* MAX_RECURSION. |
* MAX_RECURSION. |
*/ |
*/ |
static int |
static int |
getent(cap, len, db_array, fd, name, depth, nfield) |
getent(char **cap, size_t *len, const char * const *db_array, int fd, |
char **cap, **db_array, *name, *nfield; |
const char *name, int depth, char *nfield) |
u_int *len; |
|
int fd, depth; |
|
{ |
{ |
DB *capdbp; |
DB *capdbp; |
DBT key, data; |
char *r_end, *rp = NULL; /* pacify gcc */ |
register char *r_end, *rp, **db_p; |
const char * const *db_p; |
int myfd, eof, foundit, retval, clen; |
int myfd = 0, eof, foundit, retval; |
char *record, *cbuf; |
size_t clen; |
|
char *record, *cbuf, *newrecord; |
int tc_not_resolved; |
int tc_not_resolved; |
char pbuf[_POSIX_PATH_MAX]; |
char pbuf[MAXPATHLEN]; |
|
|
|
_DIAGASSERT(cap != NULL); |
|
_DIAGASSERT(len != NULL); |
|
_DIAGASSERT(db_array != NULL); |
|
/* fd may be -1 */ |
|
_DIAGASSERT(name != NULL); |
|
/* nfield may be NULL */ |
|
|
/* |
/* |
* Return with ``loop detected'' error if we've recursed more than |
* Return with ``loop detected'' error if we've recursed more than |
* MAX_RECURSION times. |
* MAX_RECURSION times. |
Line 215 getent(cap, len, db_array, fd, name, dep |
|
Line 272 getent(cap, len, db_array, fd, name, dep |
|
errno = ENOMEM; |
errno = ENOMEM; |
return (-2); |
return (-2); |
} |
} |
(void)strcpy(record, toprec); |
(void)strcpy(record, toprec); /* XXX: strcpy is safe */ |
myfd = 0; |
|
db_p = db_array; |
db_p = db_array; |
rp = record + topreclen + 1; |
rp = record + topreclen + 1; |
r_end = rp + BFRAG; |
r_end = rp + BFRAG; |
Line 243 getent(cap, len, db_array, fd, name, dep |
|
Line 299 getent(cap, len, db_array, fd, name, dep |
|
*/ |
*/ |
|
|
if (fd >= 0) { |
if (fd >= 0) { |
(void)lseek(fd, (off_t)0, L_SET); |
(void)lseek(fd, (off_t)0, SEEK_SET); |
myfd = 0; |
|
} else { |
} else { |
(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); |
(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); |
if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) |
if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) |
!= NULL) { |
!= NULL) { |
free(record); |
free(record); |
retval = cdbget(capdbp, &record, name); |
retval = cdbget(capdbp, &record, name); |
clen = strlen(record); |
if (retval < 0) { |
if ((cbuf = malloc(clen + 1)) == NULL) { |
/* no record available */ |
errno = ENOMEM; |
(void)capdbp->close(capdbp); |
return (-2); |
return (retval); |
} |
} |
|
/* save the data; close frees it */ |
|
clen = strlen(record); |
|
cbuf = malloc(clen + 1); |
memmove(cbuf, record, clen + 1); |
memmove(cbuf, record, clen + 1); |
if (capdbp->close(capdbp) < 0) { |
if (capdbp->close(capdbp) < 0) { |
|
int serrno = errno; |
|
|
free(cbuf); |
free(cbuf); |
|
errno = serrno; |
return (-2); |
return (-2); |
} |
} |
*len = clen; |
*len = clen; |
Line 268 getent(cap, len, db_array, fd, name, dep |
|
Line 329 getent(cap, len, db_array, fd, name, dep |
|
fd = open(*db_p, O_RDONLY, 0); |
fd = open(*db_p, O_RDONLY, 0); |
if (fd < 0) { |
if (fd < 0) { |
/* No error on unfound file. */ |
/* No error on unfound file. */ |
if (errno == ENOENT) |
continue; |
continue; |
|
free(record); |
|
return (-2); |
|
} |
} |
myfd = 1; |
myfd = 1; |
} |
} |
Line 281 getent(cap, len, db_array, fd, name, dep |
|
Line 339 getent(cap, len, db_array, fd, name, dep |
|
*/ |
*/ |
{ |
{ |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
register char *b_end, *bp; |
char *b_end, *bp, *cp; |
register int c; |
int c, slash; |
|
|
/* |
/* |
* Loop invariants: |
* Loop invariants: |
Line 291 getent(cap, len, db_array, fd, name, dep |
|
Line 349 getent(cap, len, db_array, fd, name, dep |
|
* Rp always points just past last character in record. |
* Rp always points just past last character in record. |
* B_end always points just past last character in buf. |
* B_end always points just past last character in buf. |
* Bp always points at next character in buf. |
* Bp always points at next character in buf. |
|
* Cp remembers where the last colon was. |
*/ |
*/ |
b_end = buf; |
b_end = buf; |
bp = buf; |
bp = buf; |
|
cp = 0; |
|
slash = 0; |
for (;;) { |
for (;;) { |
|
|
/* |
/* |
Line 310 getent(cap, len, db_array, fd, name, dep |
|
Line 371 getent(cap, len, db_array, fd, name, dep |
|
if (myfd) |
if (myfd) |
(void)close(fd); |
(void)close(fd); |
if (n < 0) { |
if (n < 0) { |
|
int serrno = errno; |
|
|
free(record); |
free(record); |
|
errno = serrno; |
return (-2); |
return (-2); |
} else { |
} else { |
fd = -1; |
fd = -1; |
Line 324 getent(cap, len, db_array, fd, name, dep |
|
Line 388 getent(cap, len, db_array, fd, name, dep |
|
|
|
c = *bp++; |
c = *bp++; |
if (c == '\n') { |
if (c == '\n') { |
if (rp > record && *(rp-1) == '\\') { |
if (slash) { |
|
slash = 0; |
rp--; |
rp--; |
continue; |
continue; |
} else |
} else |
break; |
break; |
} |
} |
|
if (slash) { |
|
slash = 0; |
|
cp = 0; |
|
} |
|
if (c == ':') { |
|
/* |
|
* If the field was `empty' (i.e. |
|
* contained only white space), back up |
|
* to the colon (eliminating the |
|
* field). |
|
*/ |
|
if (cp) |
|
rp = cp; |
|
else |
|
cp = rp; |
|
} else if (c == '\\') { |
|
slash = 1; |
|
} else if (c != ' ' && c != '\t') { |
|
/* |
|
* Forget where the colon was, as this |
|
* is not an empty field. |
|
*/ |
|
cp = 0; |
|
} |
*rp++ = c; |
*rp++ = c; |
|
|
/* |
/* |
Line 343 getent(cap, len, db_array, fd, name, dep |
|
Line 432 getent(cap, len, db_array, fd, name, dep |
|
|
|
pos = rp - record; |
pos = rp - record; |
newsize = r_end - record + BFRAG; |
newsize = r_end - record + BFRAG; |
record = realloc(record, newsize); |
newrecord = realloc(record, newsize); |
if (record == NULL) { |
if (newrecord == NULL) { |
errno = ENOMEM; |
free(record); |
if (myfd) |
if (myfd) |
(void)close(fd); |
(void)close(fd); |
|
errno = ENOMEM; |
return (-2); |
return (-2); |
} |
} |
|
record = newrecord; |
r_end = record + newsize; |
r_end = record + newsize; |
rp = record + pos; |
rp = record + pos; |
} |
} |
} |
} |
/* loop invariant let's us do this */ |
/* Eliminate any white space after the last colon. */ |
|
if (cp) |
|
rp = cp + 1; |
|
/* Loop invariant lets us do this. */ |
*rp++ = '\0'; |
*rp++ = '\0'; |
|
|
/* |
/* |
Line 392 getent(cap, len, db_array, fd, name, dep |
|
Line 486 getent(cap, len, db_array, fd, name, dep |
|
* references in it ... |
* references in it ... |
*/ |
*/ |
tc_exp: { |
tc_exp: { |
register char *newicap, *s; |
char *newicap, *s; |
register int newilen; |
size_t ilen, newilen; |
u_int ilen; |
|
int diff, iret, tclen; |
int diff, iret, tclen; |
char *icap, *scan, *tc, *tcstart, *tcend; |
char *icap, *scan, *tc, *tcstart, *tcend; |
|
|
|
|
newsize = r_end - record + diff + BFRAG; |
newsize = r_end - record + diff + BFRAG; |
tcpos = tcstart - record; |
tcpos = tcstart - record; |
tcposend = tcend - record; |
tcposend = tcend - record; |
record = realloc(record, newsize); |
newrecord = realloc(record, newsize); |
if (record == NULL) { |
if (newrecord == NULL) { |
errno = ENOMEM; |
free(record); |
if (myfd) |
if (myfd) |
(void)close(fd); |
(void)close(fd); |
free(icap); |
free(icap); |
|
errno = ENOMEM; |
return (-2); |
return (-2); |
} |
} |
|
record = newrecord; |
r_end = record + newsize; |
r_end = record + newsize; |
rp = record + pos; |
rp = record + pos; |
tcstart = record + tcpos; |
tcstart = record + tcpos; |
|
|
* Insert tc'ed record into our record. |
* Insert tc'ed record into our record. |
*/ |
*/ |
s = tcstart + newilen; |
s = tcstart + newilen; |
bcopy(tcend, s, rp - tcend); |
memmove(s, tcend, (size_t)(rp - tcend)); |
bcopy(newicap, tcstart, newilen); |
memmove(tcstart, newicap, newilen); |
rp += diff; |
rp += diff; |
free(icap); |
free(icap); |
|
|
|
|
if (myfd) |
if (myfd) |
(void)close(fd); |
(void)close(fd); |
*len = rp - record - 1; /* don't count NUL */ |
*len = rp - record - 1; /* don't count NUL */ |
if (r_end > rp) |
if (r_end > rp) { |
if ((record = |
if ((newrecord = |
realloc(record, (size_t)(rp - record))) == NULL) { |
realloc(record, (size_t)(rp - record))) == NULL) { |
|
free(record); |
errno = ENOMEM; |
errno = ENOMEM; |
return (-2); |
return (-2); |
} |
} |
|
record = newrecord; |
|
} |
|
|
*cap = record; |
*cap = record; |
if (tc_not_resolved) |
if (tc_not_resolved) |
|
|
} |
} |
|
|
static int |
static int |
cdbget(capdbp, bp, name) |
cdbget(DB *capdbp, char **bp, const char *name) |
DB *capdbp; |
|
char **bp, *name; |
|
{ |
{ |
DBT key, data; |
DBT key; |
char *buf; |
DBT data; |
int st; |
|
|
_DIAGASSERT(capdbp != NULL); |
|
_DIAGASSERT(bp != NULL); |
|
_DIAGASSERT(name != NULL); |
|
|
key.data = name; |
/* LINTED key is not modified */ |
|
key.data = (char *)name; |
key.size = strlen(name); |
key.size = strlen(name); |
|
|
for (;;) { |
for (;;) { |
Line 572 cdbget(capdbp, bp, name) |
|
Line 672 cdbget(capdbp, bp, name) |
|
* record buf, -1 if not. |
* record buf, -1 if not. |
*/ |
*/ |
int |
int |
cgetmatch(buf, name) |
cgetmatch(const char *buf, const char *name) |
char *buf, *name; |
|
{ |
{ |
register char *np, *bp; |
const char *np, *bp; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(name != NULL); |
|
|
/* |
/* |
* Start search at beginning of record. |
* Start search at beginning of record. |
Line 587 cgetmatch(buf, name) |
|
Line 689 cgetmatch(buf, name) |
|
*/ |
*/ |
np = name; |
np = name; |
for (;;) |
for (;;) |
if (*np == '\0') |
if (*np == '\0') { |
if (*bp == '|' || *bp == ':' || *bp == '\0') |
if (*bp == '|' || *bp == ':' || *bp == '\0') |
return (0); |
return (0); |
else |
else |
break; |
break; |
else |
} else |
if (*bp++ != *np++) |
if (*bp++ != *np++) |
break; |
break; |
|
|
/* |
/* |
* Match failed, skip to next name in record. |
* Match failed, skip to next name in record. |
*/ |
*/ |
bp--; /* a '|' or ':' may have stopped the match */ |
if (bp > buf) |
|
bp--; /* a '|' or ':' may have stopped the match */ |
|
else |
|
return (-1); |
for (;;) |
for (;;) |
if (*bp == '\0' || *bp == ':') |
if (*bp == '\0' || *bp == ':') |
return (-1); /* match failed totally */ |
return (-1); /* match failed totally */ |
Line 609 cgetmatch(buf, name) |
|
Line 714 cgetmatch(buf, name) |
|
} |
} |
} |
} |
|
|
|
|
|
|
|
|
|
|
int |
int |
cgetfirst(buf, db_array) |
cgetfirst(char **buf, const char * const *db_array) |
char **buf, **db_array; |
|
{ |
{ |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(db_array != NULL); |
|
|
(void)cgetclose(); |
(void)cgetclose(); |
return (cgetnext(buf, db_array)); |
return (cgetnext(buf, db_array)); |
} |
} |
|
|
static FILE *pfp; |
static FILE *pfp; |
static int slash; |
static int slash; |
static char **dbp; |
static const char * const *dbp; |
|
|
int |
int |
cgetclose() |
cgetclose(void) |
{ |
{ |
if (pfp != NULL) { |
if (pfp != NULL) { |
(void)fclose(pfp); |
(void)fclose(pfp); |
|
|
* upon returning an entry with more remaining, and -1 if an error occurs. |
* upon returning an entry with more remaining, and -1 if an error occurs. |
*/ |
*/ |
int |
int |
cgetnext(bp, db_array) |
cgetnext(char **bp, const char * const *db_array) |
register char **bp; |
|
char **db_array; |
|
{ |
{ |
size_t len; |
size_t len; |
int status, i, done; |
int status, done; |
char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; |
char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; |
u_int dummy; |
size_t dummy; |
|
|
|
_DIAGASSERT(bp != NULL); |
|
_DIAGASSERT(db_array != NULL); |
|
|
if (dbp == NULL) |
if (dbp == NULL) |
dbp = db_array; |
dbp = db_array; |
Line 667 cgetnext(bp, db_array) |
|
Line 772 cgetnext(bp, db_array) |
|
} else { |
} else { |
line = fgetln(pfp, &len); |
line = fgetln(pfp, &len); |
if (line == NULL && pfp) { |
if (line == NULL && pfp) { |
(void)fclose(pfp); |
|
if (ferror(pfp)) { |
if (ferror(pfp)) { |
(void)cgetclose(); |
(void)cgetclose(); |
return (-1); |
return (-1); |
} else { |
} else { |
|
(void)fclose(pfp); |
|
pfp = NULL; |
if (*++dbp == NULL) { |
if (*++dbp == NULL) { |
(void)cgetclose(); |
(void)cgetclose(); |
return (0); |
return (0); |
Line 688 cgetnext(bp, db_array) |
|
Line 794 cgetnext(bp, db_array) |
|
slash = 0; |
slash = 0; |
continue; |
continue; |
} |
} |
if (isspace(*line) || |
if (isspace((unsigned char)*line) || |
*line == ':' || *line == '#' || slash) { |
*line == ':' || *line == '#' || slash) { |
if (line[len - 2] == '\\') |
if (line[len - 2] == '\\') |
slash = 1; |
slash = 1; |
Line 706 cgetnext(bp, db_array) |
|
Line 812 cgetnext(bp, db_array) |
|
/* |
/* |
* Line points to a name line. |
* Line points to a name line. |
*/ |
*/ |
i = 0; |
if (len > sizeof(nbuf)) |
|
return -1; |
done = 0; |
done = 0; |
np = nbuf; |
np = nbuf; |
for (;;) { |
for (;;) { |
Line 726 cgetnext(bp, db_array) |
|
Line 833 cgetnext(bp, db_array) |
|
} else { /* name field extends beyond the line */ |
} else { /* name field extends beyond the line */ |
line = fgetln(pfp, &len); |
line = fgetln(pfp, &len); |
if (line == NULL && pfp) { |
if (line == NULL && pfp) { |
(void)fclose(pfp); |
|
if (ferror(pfp)) { |
if (ferror(pfp)) { |
(void)cgetclose(); |
(void)cgetclose(); |
return (-1); |
return (-1); |
} |
} |
|
(void)fclose(pfp); |
|
pfp = NULL; |
|
*np = '\0'; |
|
break; |
} else |
} else |
line[len - 1] = '\0'; |
line[len - 1] = '\0'; |
} |
} |
} |
} |
|
if (len > sizeof(buf)) |
|
return -1; |
rp = buf; |
rp = buf; |
for(cp = nbuf; *cp != NULL; cp++) |
for(cp = nbuf; *cp != '\0'; cp++) |
if (*cp == '|' || *cp == ':') |
if (*cp == '|' || *cp == ':') |
break; |
break; |
else |
else |
Line 770 cgetnext(bp, db_array) |
|
Line 882 cgetnext(bp, db_array) |
|
* allocation failure). |
* allocation failure). |
*/ |
*/ |
int |
int |
cgetstr(buf, cap, str) |
cgetstr(char *buf, const char *cap, char **str) |
char *buf, *cap; |
|
char **str; |
|
{ |
{ |
register u_int m_room; |
u_int m_room; |
register char *bp, *mp; |
const char *bp; |
|
char *mp; |
int len; |
int len; |
char *mem; |
char *mem, *newmem; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(cap != NULL); |
|
_DIAGASSERT(str != NULL); |
|
|
/* |
/* |
* Find string capability cap |
* Find string capability cap |
Line 814 cgetstr(buf, cap, str) |
|
Line 929 cgetstr(buf, cap, str) |
|
if (*bp == ':' || *bp == '\0') |
if (*bp == ':' || *bp == '\0') |
break; /* drop unfinished escape */ |
break; /* drop unfinished escape */ |
if ('0' <= *bp && *bp <= '7') { |
if ('0' <= *bp && *bp <= '7') { |
register int n, i; |
int n, i; |
|
|
n = 0; |
n = 0; |
i = 3; /* maximum of three octal digits */ |
i = 3; /* maximum of three octal digits */ |
Line 864 cgetstr(buf, cap, str) |
|
Line 979 cgetstr(buf, cap, str) |
|
if (m_room == 0) { |
if (m_room == 0) { |
size_t size = mp - mem; |
size_t size = mp - mem; |
|
|
if ((mem = realloc(mem, size + SFRAG)) == NULL) |
if ((newmem = realloc(mem, size + SFRAG)) == NULL) { |
|
free(mem); |
return (-2); |
return (-2); |
|
} |
|
mem = newmem; |
m_room = SFRAG; |
m_room = SFRAG; |
mp = mem + size; |
mp = mem + size; |
} |
} |
Line 877 cgetstr(buf, cap, str) |
|
Line 995 cgetstr(buf, cap, str) |
|
/* |
/* |
* Give back any extra memory and return value and success. |
* Give back any extra memory and return value and success. |
*/ |
*/ |
if (m_room != 0) |
if (m_room != 0) { |
if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL) |
if ((newmem = realloc(mem, (size_t)(mp - mem))) == NULL) { |
|
free(mem); |
return (-2); |
return (-2); |
|
} |
|
mem = newmem; |
|
} |
*str = mem; |
*str = mem; |
return (len); |
return (len); |
} |
} |
Line 895 cgetstr(buf, cap, str) |
|
Line 1017 cgetstr(buf, cap, str) |
|
* error was encountered (storage allocation failure). |
* error was encountered (storage allocation failure). |
*/ |
*/ |
int |
int |
cgetustr(buf, cap, str) |
cgetustr(char *buf, const char *cap, char **str) |
char *buf, *cap, **str; |
|
{ |
{ |
register u_int m_room; |
u_int m_room; |
register char *bp, *mp; |
const char *bp; |
|
char *mp; |
int len; |
int len; |
char *mem; |
char *mem, *newmem; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(cap != NULL); |
|
_DIAGASSERT(str != NULL); |
|
|
/* |
/* |
* Find string capability cap |
* Find string capability cap |
Line 937 cgetustr(buf, cap, str) |
|
Line 1063 cgetustr(buf, cap, str) |
|
if (m_room == 0) { |
if (m_room == 0) { |
size_t size = mp - mem; |
size_t size = mp - mem; |
|
|
if ((mem = realloc(mem, size + SFRAG)) == NULL) |
if ((newmem = realloc(mem, size + SFRAG)) == NULL) { |
|
free(mem); |
return (-2); |
return (-2); |
|
} |
|
mem = newmem; |
m_room = SFRAG; |
m_room = SFRAG; |
mp = mem + size; |
mp = mem + size; |
} |
} |
Line 950 cgetustr(buf, cap, str) |
|
Line 1079 cgetustr(buf, cap, str) |
|
/* |
/* |
* Give back any extra memory and return value and success. |
* Give back any extra memory and return value and success. |
*/ |
*/ |
if (m_room != 0) |
if (m_room != 0) { |
if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL) |
if ((newmem = realloc(mem, (size_t)(mp - mem))) == NULL) { |
|
free(mem); |
return (-2); |
return (-2); |
|
} |
|
mem = newmem; |
|
} |
*str = mem; |
*str = mem; |
return (len); |
return (len); |
} |
} |
Line 964 cgetustr(buf, cap, str) |
|
Line 1097 cgetustr(buf, cap, str) |
|
* numeric capability couldn't be found. |
* numeric capability couldn't be found. |
*/ |
*/ |
int |
int |
cgetnum(buf, cap, num) |
cgetnum(char *buf, const char *cap, long *num) |
char *buf, *cap; |
|
long *num; |
|
{ |
{ |
register long n; |
long n; |
register int base, digit; |
int base, digit; |
register char *bp; |
const char *bp; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(cap != NULL); |
|
_DIAGASSERT(num != NULL); |
|
|
/* |
/* |
* Find numeric capability cap |
* Find numeric capability cap |
Line 1028 cgetnum(buf, cap, num) |
|
Line 1163 cgetnum(buf, cap, num) |
|
* Compare name field of record. |
* Compare name field of record. |
*/ |
*/ |
static int |
static int |
nfcmp(nf, rec) |
nfcmp(char *nf, char *rec) |
char *nf, *rec; |
|
{ |
{ |
char *cp, tmp; |
char *cp, tmp; |
int ret; |
int ret; |
|
|
|
_DIAGASSERT(nf != NULL); |
|
_DIAGASSERT(rec != NULL); |
|
|
for (cp = rec; *cp != ':'; cp++) |
for (cp = rec; *cp != ':'; cp++) |
; |
; |
|
|