summaryrefslogtreecommitdiff
path: root/lib/libutil/passwd.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-05-24 21:27:39 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-05-24 21:27:39 +0000
commitcc5f18b1772325f94cc7f8a97f8ba4acc9a0d53c (patch)
tree6b25b4512284330913e9463986a55e6938a75ec2 /lib/libutil/passwd.c
parent0fa503dfa1d5a670e0eaa182afd000a479359f3a (diff)
strlcpy and KNF
Diffstat (limited to 'lib/libutil/passwd.c')
-rw-r--r--lib/libutil/passwd.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/lib/libutil/passwd.c b/lib/libutil/passwd.c
index b36620eba41..fa1830d3817 100644
--- a/lib/libutil/passwd.c
+++ b/lib/libutil/passwd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: passwd.c,v 1.32 2002/04/10 10:11:03 mpech Exp $ */
+/* $OpenBSD: passwd.c,v 1.33 2002/05/24 21:27:38 deraadt Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
@@ -34,7 +34,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: passwd.c,v 1.32 2002/04/10 10:11:03 mpech Exp $";
+static char rcsid[] = "$OpenBSD: passwd.c,v 1.33 2002/05/24 21:27:38 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -58,7 +58,7 @@ static char rcsid[] = "$OpenBSD: passwd.c,v 1.32 2002/04/10 10:11:03 mpech Exp $
#include "util.h"
-#define NUM_OPTIONS 2 /* Number of hardcoded defaults */
+#define NUM_OPTIONS 2 /* Number of hardcoded defaults */
static void pw_cont(int sig);
@@ -98,9 +98,10 @@ static int
read_line(fp, line, max)
FILE *fp;
char *line;
- int max;
+ int max;
{
char *p;
+
/* Read one line of config */
if (fgets(line, max, fp) == 0)
return 0;
@@ -123,7 +124,8 @@ static const char *
pw_default(option)
char *option;
{
- int i;
+ int i;
+
for (i = 0; i < NUM_OPTIONS; i++)
if (!strcmp(options[i][0], option))
return options[i][1];
@@ -153,7 +155,7 @@ pw_file(nm)
* Retrieve password information from the /etc/passwd.conf file,
* at the moment this is only for choosing the cipher to use.
* It could easily be used for other authentication methods as
- * well.
+ * well.
*/
void
pw_getconf(data, max, key, option)
@@ -166,8 +168,8 @@ pw_getconf(data, max, key, option)
char line[LINE_MAX];
static char result[LINE_MAX];
char *p;
- int got = 0;
- int found = 0;
+ int got = 0;
+ int found = 0;
result[0] = '\0';
@@ -175,7 +177,7 @@ pw_getconf(data, max, key, option)
if (!p || (fp = fopen(p, "r")) == NULL) {
if (p)
free(p);
- if((p = (char *)pw_default(option))) {
+ if ((p = (char *)pw_default(option))) {
strncpy(data, p, max - 1);
data[max - 1] = '\0';
} else
@@ -192,35 +194,36 @@ pw_getconf(data, max, key, option)
/* 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;
- trim_whitespace(p);
- if (!strncmp(p, option, strlen(option))) {
- trim_whitespace(p2);
- strcpy(result, p2);
- found = 1;
- break;
- }
+ char *p2;
+
+ /* Leaving key field */
+ if (strchr(line, ':')) {
+ got = 1;
+ break;
+ }
+ p2 = line;
+ if (!(p = strsep(&p2, "=")) || p2 == NULL)
+ continue;
+ trim_whitespace(p);
+ if (!strncmp(p, option, strlen(option))) {
+ trim_whitespace(p2);
+ strlcpy(result, p2, sizeof result);
+ found = 1;
+ break;
+ }
}
}
fclose(fp);
- /*
+ /*
* If we got no result and were looking for a default
* value, try hard coded defaults.
*/
if (!strlen(result) && !strcmp(key,"default") &&
- (p=(char *)pw_default(option)))
+ (p = (char *)pw_default(option)))
strncpy(data, p, max - 1);
- else
+ else
strncpy(data, result, max - 1);
data[max - 1] = '\0';
}
@@ -581,7 +584,7 @@ pw_scan(bp, pw, flags)
break;
}
if (!strcmp(p, sh))
- break;
+ break;
}
endusershell();
}