Browse Source

give only default values when asked for.

OPENBSD_2_1
provos 28 years ago
parent
commit
ed82a932ef
2 changed files with 42 additions and 41 deletions
  1. +33
    -39
      src/lib/libutil/passwd.c
  2. +9
    -2
      src/lib/libutil/pw_getconf.3

+ 33
- 39
src/lib/libutil/passwd.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: passwd.c,v 1.8 1997/02/16 19:59:21 provos Exp $ */
/* $OpenBSD: passwd.c,v 1.9 1997/04/10 20:05:49 provos Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
* The Regents of the University of California. All rights reserved.
@ -138,9 +138,8 @@ pw_getconf(data, max, key, option)
char line[LINE_MAX];
static char result[LINE_MAX];
char *p;
int defaultw;
int keyw;
int got;
int got = 0;
int found = 0;
result[0] = '\0';
@ -152,47 +151,42 @@ pw_getconf(data, max, key, option)
data[0] = '\0';
return;
}
defaultw = 0;
keyw = 0;
got = 0;
while (!keyw && (got || read_line(fp, line, LINE_MAX))) {
while (!found && (got || read_line(fp, line, LINE_MAX))) {
got = 0;
if (!strcmp("default:", line))
defaultw = 1;
if (!strncmp(key, line, strlen(key)) &&
line[strlen(key)] == ':')
keyw = 1;
/* Now we found default or specified key */
if (defaultw || keyw) {
while (read_line(fp, line, LINE_MAX)) {
char *p2;
/* Leaving key field */
if (strchr(line, ':')) {
got = 1;
keyw = 0;
break;
}
p2 = line;
if (!(p = strsep(&p2, "=")) || p2 == NULL)
continue;
remove_trailing_space(p);
if (!strncmp(p, option, strlen(option))) {
remove_trailing_space(p2);
strcpy(result, p2);
break;
}
}
if (keyw)
break;
defaultw = 0;
if (strncmp(key, line, strlen(key)) ||
line[strlen(key)] != ':')
continue;
/* Now we found our specified key */
while (read_line(fp, line, LINE_MAX)) {
char *p2;
/* Leaving key field */
if (strchr(line, ':')) {
got = 1;
break;
}
p2 = line;
if (!(p = strsep(&p2, "=")) || p2 == NULL)
continue;
remove_trailing_space(p);
if (!strncmp(p, option, strlen(option))) {
remove_trailing_space(p2);
strcpy(result, p2);
found = 1;
break;
}
}
}
fclose(fp);
/* If we got no result and have a default use that */
/*
* If we got no result and were looking for a default
* value, try hard coded defaults.
*/
if (!strlen(result) && (p=(char *)pw_default(option)))
if (!strlen(result) && !strcmp(key,"default") &&
(p=(char *)pw_default(option)))
strncpy(data, p, max - 1);
else
strncpy(data, result, max - 1);


+ 9
- 2
src/lib/libutil/pw_getconf.3 View File

@ -49,11 +49,18 @@ from the section given be
If no suitable entry is found
for the
.Pa key
a default value or an empty string will be returned in data.
an empty string will be returned in data.
.Pp
For default values the key
.Pa default
can be used, this might be useful when no entry was found
for a specific key or option.
.Pp
An empty string is also returned for other errors.
.Sh FILES
.Bl -tag -width /etc/passwd.conf -compact
.It Pa /etc/passwd.conf
.El
.Sh SEE ALSO
.Xr passwd 5
.Xr passwd 5 ,
.Xr passwd.conf 5

Loading…
Cancel
Save