]> granicus.if.org Git - fcron/commitdiff
better getpwnam() error handling ver3_0_3-rc1
authorthib <thib>
Sun, 3 Jun 2007 17:52:34 +0000 (17:52 +0000)
committerthib <thib>
Sun, 3 Jun 2007 17:52:34 +0000 (17:52 +0000)
allow.c
conf.c
socket.c
subs.c

diff --git a/allow.c b/allow.c
index 090d71c450f7a746f23e543025c9ab7438dc3053..e3c6a8d8ccadf0306002e4857719815bc73712c5 100644 (file)
--- 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 705491af173caa919e1e83188a839a80bc90a1d5..9f7bc1dbe92cb75af53d335a1a37f85b14bba147 100644 (file)
--- 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)
     {
index 389248d6305aafd5478f12a9cbb0f3db0b9a56be..666258b6fb70e98f50749645f3b7d0d688ea8b61 100644 (file)
--- 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 d7431b37725cbd890a9dc513d97adc8708a18beb..219f867dbfa335586ceda02fab99ee465332cbce 100644 (file)
--- 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);
     }