|
@ -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 |
|
|
* Copyright (c) 1987, 1993, 1994, 1995 |
|
@ -34,7 +34,7 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
#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 */ |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
|
|
|
|
|
|
#include <sys/types.h> |
|
|
#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" |
|
|
#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); |
|
|
static void pw_cont(int sig); |
|
|
|
|
|
|
|
@ -98,9 +98,10 @@ static int |
|
|
read_line(fp, line, max) |
|
|
read_line(fp, line, max) |
|
|
FILE *fp; |
|
|
FILE *fp; |
|
|
char *line; |
|
|
char *line; |
|
|
int max; |
|
|
|
|
|
|
|
|
int max; |
|
|
{ |
|
|
{ |
|
|
char *p; |
|
|
char *p; |
|
|
|
|
|
|
|
|
/* Read one line of config */ |
|
|
/* Read one line of config */ |
|
|
if (fgets(line, max, fp) == 0) |
|
|
if (fgets(line, max, fp) == 0) |
|
|
return 0; |
|
|
return 0; |
|
@ -123,7 +124,8 @@ static const char * |
|
|
pw_default(option) |
|
|
pw_default(option) |
|
|
char *option; |
|
|
char *option; |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
|
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_OPTIONS; i++) |
|
|
for (i = 0; i < NUM_OPTIONS; i++) |
|
|
if (!strcmp(options[i][0], option)) |
|
|
if (!strcmp(options[i][0], option)) |
|
|
return options[i][1]; |
|
|
return options[i][1]; |
|
@ -153,7 +155,7 @@ pw_file(nm) |
|
|
* Retrieve password information from the /etc/passwd.conf file, |
|
|
* Retrieve password information from the /etc/passwd.conf file, |
|
|
* at the moment this is only for choosing the cipher to use. |
|
|
* at the moment this is only for choosing the cipher to use. |
|
|
* It could easily be used for other authentication methods as |
|
|
* It could easily be used for other authentication methods as |
|
|
* well. |
|
|
|
|
|
|
|
|
* well. |
|
|
*/ |
|
|
*/ |
|
|
void |
|
|
void |
|
|
pw_getconf(data, max, key, option) |
|
|
pw_getconf(data, max, key, option) |
|
@ -166,8 +168,8 @@ pw_getconf(data, max, key, option) |
|
|
char line[LINE_MAX]; |
|
|
char line[LINE_MAX]; |
|
|
static char result[LINE_MAX]; |
|
|
static char result[LINE_MAX]; |
|
|
char *p; |
|
|
char *p; |
|
|
int got = 0; |
|
|
|
|
|
int found = 0; |
|
|
|
|
|
|
|
|
int got = 0; |
|
|
|
|
|
int found = 0; |
|
|
|
|
|
|
|
|
result[0] = '\0'; |
|
|
result[0] = '\0'; |
|
|
|
|
|
|
|
@ -175,7 +177,7 @@ pw_getconf(data, max, key, option) |
|
|
if (!p || (fp = fopen(p, "r")) == NULL) { |
|
|
if (!p || (fp = fopen(p, "r")) == NULL) { |
|
|
if (p) |
|
|
if (p) |
|
|
free(p); |
|
|
free(p); |
|
|
if((p = (char *)pw_default(option))) { |
|
|
|
|
|
|
|
|
if ((p = (char *)pw_default(option))) { |
|
|
strncpy(data, p, max - 1); |
|
|
strncpy(data, p, max - 1); |
|
|
data[max - 1] = '\0'; |
|
|
data[max - 1] = '\0'; |
|
|
} else |
|
|
} else |
|
@ -192,35 +194,36 @@ pw_getconf(data, max, key, option) |
|
|
|
|
|
|
|
|
/* Now we found our specified key */ |
|
|
/* Now we found our specified key */ |
|
|
while (read_line(fp, line, LINE_MAX)) { |
|
|
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); |
|
|
fclose(fp); |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
|
/* |
|
|
* If we got no result and were looking for a default |
|
|
* If we got no result and were looking for a default |
|
|
* value, try hard coded defaults. |
|
|
* value, try hard coded defaults. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
if (!strlen(result) && !strcmp(key,"default") && |
|
|
if (!strlen(result) && !strcmp(key,"default") && |
|
|
(p=(char *)pw_default(option))) |
|
|
|
|
|
|
|
|
(p = (char *)pw_default(option))) |
|
|
strncpy(data, p, max - 1); |
|
|
strncpy(data, p, max - 1); |
|
|
else |
|
|
|
|
|
|
|
|
else |
|
|
strncpy(data, result, max - 1); |
|
|
strncpy(data, result, max - 1); |
|
|
data[max - 1] = '\0'; |
|
|
data[max - 1] = '\0'; |
|
|
} |
|
|
} |
|
@ -581,7 +584,7 @@ pw_scan(bp, pw, flags) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
if (!strcmp(p, sh)) |
|
|
if (!strcmp(p, sh)) |
|
|
break; |
|
|
|
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
endusershell(); |
|
|
endusershell(); |
|
|
} |
|
|
} |
|
|