From: thib Date: Sun, 3 Jun 2007 17:52:34 +0000 (+0000) Subject: better getpwnam() error handling X-Git-Tag: ver3_0_3-rc1^0 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f26f588f14cf99304cfd837881824258e30650d;p=fcron better getpwnam() error handling --- diff --git a/allow.c b/allow.c index 090d71c..e3c6a8d 100644 --- a/allow.c +++ b/allow.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: allow.c,v 1.17 2007-04-14 18:04:24 thib Exp $ */ + /* $Id: allow.c,v 1.18 2007-06-03 17:53:02 thib Exp $ */ #include "fcrontab.h" @@ -75,15 +75,14 @@ in_file(char *str, char *file) int is_allowed(char *user) - /* return 1 if user is allowed to use this soft + /* return 1 if user is allowed to use this software * otherwise return 0 */ { int allow = 0; int deny = 0; /* check if user is in passwd file */ - errno = 0; - if ( ( ! getpwnam(user) ) || errno != 0 ) + if ( getpwnam(user) == NULL ) return 0; /* check if user is in fcron.allow and/or in fcron.deny files */ diff --git a/conf.c b/conf.c index 705491a..9f7bc1d 100644 --- a/conf.c +++ b/conf.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: conf.c,v 1.72 2007-04-14 18:04:16 thib Exp $ */ + /* $Id: conf.c,v 1.73 2007-06-03 17:52:34 thib Exp $ */ #include "fcron.h" @@ -142,6 +142,7 @@ synchronize_dir(const char *dir_name) /* then add normal files, if any, to database */ for (list_cur = file_list; list_cur; list_cur = list_cur->next ) { + errno = 0; if ( getpwnam(list_cur->str) #ifdef SYSFCRONTAB || strcmp(list_cur->str, SYSFCRONTAB) == 0 @@ -151,12 +152,13 @@ synchronize_dir(const char *dir_name) synchronize_file(list_cur->str); } else - error("ignoring file \"%s\" : not in passwd file.", list_cur->str); + error_e("ignoring file \"%s\" : not in passwd file.", list_cur->str); } /* finally add new files */ for (list_cur = new_list; list_cur; list_cur = list_cur->next ) { /* len("new.") = 4 : */ + errno = 0; if ( getpwnam(list_cur->str + 4) #ifdef SYSFCRONTAB || strcmp(list_cur->str + 4, SYSFCRONTAB) == 0 @@ -166,7 +168,7 @@ synchronize_dir(const char *dir_name) synchronize_file(list_cur->str); } else - error("ignoring file %s : not in passwd file.", + error_e("ignoring file %s : not in passwd file.", (list_cur->str + 4)); } @@ -505,9 +507,11 @@ read_file(const char *file_name, cf_t *cf) * the user cron job. It performs an entrypoint * permission check for this purpose. */ +#ifdef SYSFCRONTAB if(!strcmp(cf->cf_user, SYSFCRONTAB)) user_name = "system_u"; else +#endif /* def SYSFCRONTAB */ user_name = cf->cf_user; if(flask_enabled) { diff --git a/socket.c b/socket.c index 389248d..666258b 100644 --- a/socket.c +++ b/socket.c @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: socket.c,v 1.23 2007-04-14 18:04:26 thib Exp $ */ + /* $Id: socket.c,v 1.24 2007-06-03 17:53:30 thib Exp $ */ /* This file contains all fcron's code (server) to handle communication with fcrondyn */ @@ -214,6 +214,7 @@ auth_client(struct fcrondyn_cl *client) pass_sys = pass_sp->sp_pwdp; #else struct passwd *pass = NULL; + errno = 0; if ( (pass = getpwnam((char *) client->fcl_cmd )) == NULL ) { error_e("could not getpwnam %s", (char *) client->fcl_cmd); send(client->fcl_sock_fd, "0", sizeof("0"), 0); diff --git a/subs.c b/subs.c index d7431b3..219f867 100644 --- a/subs.c +++ b/subs.c @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: subs.c,v 1.27 2007-04-14 18:04:23 thib Exp $ */ + /* $Id: subs.c,v 1.28 2007-06-03 17:52:53 thib Exp $ */ #include "global.h" #include "subs.h" @@ -52,7 +52,7 @@ get_user_uid_safe(char *username) errno = 0; pass = getpwnam(username); - if ( errno != 0 || pass == NULL ) { + if ( pass == NULL ) { die_e("Unable to get the uid of user %s (is user in passwd file?)", username); }