version 1.19, 2003/07/02 21:04:10 |
version 1.20, 2004/03/15 02:50:29 |
|
|
|
|
#ifndef lint |
#ifndef lint |
/*static char sccsid[] = "from: @(#)util.c 5.14 (Berkeley) 1/17/91";*/ |
/*static char sccsid[] = "from: @(#)util.c 5.14 (Berkeley) 1/17/91";*/ |
static char rcsid[] = "$OpenBSD$"; |
static const char rcsid[] = "$OpenBSD$"; |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
|
|
/* ampersands get replaced by the login name */ |
/* ampersands get replaced by the login name */ |
if (!(p = strtok(p, ","))) |
if (!(p = strtok(p, ","))) |
return(0); |
return (0); |
expandusername(p, pw->pw_name, name, sizeof(name)); |
expandusername(p, pw->pw_name, name, sizeof(name)); |
for (t = name; (p = strtok(t, "\t ")) != NULL; t = NULL) |
for (t = name; (p = strtok(t, "\t ")) != NULL; t = NULL) |
if (!strcasecmp(p, user)) |
if (!strcasecmp(p, user)) |
return(1); |
return (1); |
return(0); |
return (0); |
} |
} |
|
|
/* inspired by usr.sbin/sendmail/util.c::buildfname */ |
/* inspired by usr.sbin/sendmail/util.c::buildfname */ |
|
|
PERSON *pn, **pp; |
PERSON *pn, **pp; |
|
|
for (pp = htab + hash(pw->pw_name); |
for (pp = htab + hash(pw->pw_name); |
*pp != NULL && strcmp((*pp)->name, pw->pw_name) != 0; |
*pp != NULL && strcmp((*pp)->name, pw->pw_name) != 0; |
pp = &(*pp)->hlink) |
pp = &(*pp)->hlink) |
; |
; |
if ((pn = *pp) == NULL) { |
if ((pn = *pp) == NULL) { |
pn = palloc(); |
pn = palloc(); |
|
|
userinfo(pn, pw); |
userinfo(pn, pw); |
pn->whead = NULL; |
pn->whead = NULL; |
} |
} |
return(pn); |
return (pn); |
} |
} |
|
|
PERSON * |
PERSON * |
|
|
|
|
/* name may be only UT_NAMESIZE long and not terminated */ |
/* name may be only UT_NAMESIZE long and not terminated */ |
for (pn = htab[hash(name)]; |
for (pn = htab[hash(name)]; |
pn != NULL && strncmp(pn->name, name, UT_NAMESIZE) != 0; |
pn != NULL && strncmp(pn->name, name, UT_NAMESIZE) != 0; |
pn = pn->hlink) |
pn = pn->hlink) |
; |
; |
return(pn); |
return (pn); |
} |
} |
|
|
int |
int |
|
|
/* name may be only UT_NAMESIZE long and not terminated */ |
/* name may be only UT_NAMESIZE long and not terminated */ |
for (i = UT_NAMESIZE; --i >= 0 && *name;) |
for (i = UT_NAMESIZE; --i >= 0 && *name;) |
h = ((h << 2 | h >> (HBITS - 2)) ^ *name++) & HMASK; |
h = ((h << 2 | h >> (HBITS - 2)) ^ *name++) & HMASK; |
return(h); |
return (h); |
} |
} |
|
|
PERSON * |
PERSON * |
|
|
|
|
if ((p = (PERSON *)malloc((u_int) sizeof(PERSON))) == NULL) |
if ((p = (PERSON *)malloc((u_int) sizeof(PERSON))) == NULL) |
err(1, "malloc"); |
err(1, "malloc"); |
return(p); |
return (p); |
} |
} |
|
|
WHERE * |
WHERE * |
|
|
pn->wtail = w; |
pn->wtail = w; |
} |
} |
w->next = NULL; |
w->next = NULL; |
return(w); |
return (w); |
} |
} |
|
|
char * |
char * |
|
|
/* don't touch anything if the user has their own formatting */ |
/* don't touch anything if the user has their own formatting */ |
for (p = num; *p; ++p) |
for (p = num; *p; ++p) |
if (!isdigit(*p)) |
if (!isdigit(*p)) |
return(num); |
return (num); |
len = p - num; |
len = p - num; |
p = pbuf; |
p = pbuf; |
switch(len) { |
switch (len) { |
case 11: /* +0-123-456-7890 */ |
case 11: /* +0-123-456-7890 */ |
*p++ = '+'; |
*p++ = '+'; |
*p++ = *num++; |
*p++ = *num++; |
|
|
*p++ = *num++; |
*p++ = *num++; |
break; |
break; |
default: |
default: |
return(num); |
return (num); |
} |
} |
if (len != 4) { |
if (len != 4) { |
*p++ = '-'; |
*p++ = '-'; |
|
|
*p++ = *num++; |
*p++ = *num++; |
*p++ = *num++; |
*p++ = *num++; |
*p = '\0'; |
*p = '\0'; |
return(pbuf); |
return (pbuf); |
} |
} |
|
|
/* Like strvis(), but use malloc() to get the space and return a pointer |
/* Like strvis(), but use malloc() to get the space and return a pointer |
|
|
err(1, "malloc failed"); |
err(1, "malloc failed"); |
|
|
strvis(dst, src, VIS_SAFE|VIS_NOSLASH); |
strvis(dst, src, VIS_SAFE|VIS_NOSLASH); |
return(dst); |
return (dst); |
} |
} |