--- checkpassword-nolog.c Sat Jan 11 17:16:04 2003 +++ checkpassword.c Sat Jul 12 14:30:25 2003 @@ -1,5 +1,10 @@ +#define USELOG 1 + #include #include +#ifdef USELOG +#include +#endif #include "error.h" #include "pathexec.h" @@ -26,16 +31,34 @@ while(fgets(linebuf, LINELEN, fp) != NULL) { if((cp = strchr(linebuf, '\n')) != NULL) *cp = 0; - if((cp = strtok(linebuf, ":")) == NULL) + if((cp = strtok(linebuf, ":")) == NULL) { +#ifdef USELOG + syslog(LOG_ERR, "syntax error in \"%s\"", FILENAME); + closelog(); +#endif return(NULL); + } if(strcmp(cp, user) == 0) { - if((cp = strtok(NULL, ":")) == NULL) + if((cp = strtok(NULL, ":")) == NULL) { +#ifdef USELOG + syslog(LOG_WARNING, "no password found for \"%s\" in \"%s\"", user, FILENAME); + closelog(); +#endif return(NULL); + } fclose(fp); +#ifdef USELOG + syslog(LOG_INFO, "successful authentication of user \"%s\"", user); + closelog(); +#endif return(cp); } } fclose(fp); +#ifdef USELOG + syslog(LOG_NOTICE, "user \"%s\" could not be found", user); + closelog(); +#endif return(NULL); } @@ -49,6 +72,9 @@ if (!argv[1]) _exit(2); +#ifdef USELOG + openlog("checkpassword", 0, LOG_AUTH); +#endif uplen = 0; for (;;) { do @@ -57,7 +83,12 @@ if (r == -1) _exit(111); if (r == 0) break; uplen += r; - if (uplen >= sizeof(up)) _exit(1); + if (uplen >= sizeof(up)) { +#ifdef USELOG + syslog(LOG_ERR, "malformed input"); +#endif + _exit(1); + } } close(3); @@ -69,20 +100,38 @@ if (i >= uplen) _exit(2); while (up[i++]) if (i >= uplen) _exit(2); +/* +#ifdef USELOG + syslog(LOG_DEBUG, "authenticating user \"%s\"", login); +#endif +*/ pw = getpwnam(login); if(! pw) { if (errno == error_txtbsy) _exit(111); +#ifdef USELOG + syslog(LOG_NOTICE, "user \"%s\" does not exist", login); +#endif _exit(1); } stored = getpoppw(login); if (!stored) _exit(1); - if (!*stored || strcmp(password, stored)) _exit(1); + if (!*stored || strcmp(password, stored)) { +#ifdef USELOG + syslog(LOG_WARNING, "authentication failed for user \"%s\"", login); +#endif + _exit(1); + } if (prot_gid((int) pw->pw_gid) == -1) _exit(1); if (prot_uid((int) pw->pw_uid) == -1) _exit(1); - if (chdir(pw->pw_dir) == -1) _exit(111); + if (chdir(pw->pw_dir) == -1) { +#ifdef USELOG + syslog(LOG_ERR, "unable to change directory to \"%s\"", pw->pw_dir); +#endif + _exit(111); + } if (!pathexec_env("USER",pw->pw_name)) _exit(111); if (!pathexec_env("HOME",pw->pw_dir)) _exit(111);