diff options
author | Niels Provos <provos@cvs.openbsd.org> | 1997-04-10 20:05:51 +0000 |
---|---|---|
committer | Niels Provos <provos@cvs.openbsd.org> | 1997-04-10 20:05:51 +0000 |
commit | 7a02f414dc6f989144a8f018cb232adca87a76fa (patch) | |
tree | 62be27d57d5de7aba7a8c67c1901cec558b83158 /lib/libutil | |
parent | 7c3e6355d81da957652eb37576bac673327a4321 (diff) |
give only default values when asked for.
Diffstat (limited to 'lib/libutil')
-rw-r--r-- | lib/libutil/passwd.c | 72 | ||||
-rw-r--r-- | lib/libutil/pw_getconf.3 | 11 |
2 files changed, 42 insertions, 41 deletions
diff --git a/lib/libutil/passwd.c b/lib/libutil/passwd.c index 63df2ab7af9..e7ed1758891 100644 --- a/lib/libutil/passwd.c +++ b/lib/libutil/passwd.c @@ -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); diff --git a/lib/libutil/pw_getconf.3 b/lib/libutil/pw_getconf.3 index 671ad8e01d7..cffa555c7f2 100644 --- a/lib/libutil/pw_getconf.3 +++ b/lib/libutil/pw_getconf.3 @@ -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 |