]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logindefs: change getlogindefs_num() to return unsigned long
authorSami Kerola <kerolasa@iki.fi>
Sat, 2 Jun 2012 09:57:42 +0000 (11:57 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sat, 2 Jun 2012 09:57:42 +0000 (11:57 +0200)
Where ever getlogindefs_num() is called return value is always
expected to be unsigned, such as sleep() input, gid_t or mode_t.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/login.c
login-utils/logindefs.c
login-utils/logindefs.h
login-utils/su.c

index 346f23bdbc4e254909b84d6389873746d158d076..9db4f0fe6da1915f39520a8785b6bf13b16dbbc0 100644 (file)
@@ -127,7 +127,7 @@ struct login_context {
  * This bounds the time given to login.  Not a define so it can
  * be patched on machines where it's too small.
  */
-static int timeout = LOGIN_TIMEOUT;
+static unsigned int timeout = LOGIN_TIMEOUT;
 static int child_pid = 0;
 static volatile int got_sig = 0;
 
@@ -172,8 +172,8 @@ static void timedout(int sig __attribute__ ((__unused__)))
 {
        signal(SIGALRM, timedout2);
        alarm(10);
-       /* TRANSLATORS: The standard value for %d is 60. */
-       warnx(_("timed out after %d seconds"), timeout);
+       /* TRANSLATORS: The standard value for %u is 60. */
+       warnx(_("timed out after %u seconds"), timeout);
        signal(SIGALRM, SIG_IGN);
        alarm(0);
        timedout2(0);
@@ -203,7 +203,7 @@ static void sig_handler(int signal)
  */
 static void __attribute__ ((__noreturn__)) sleepexit(int eval)
 {
-       sleep(getlogindefs_num("FAIL_DELAY", LOGIN_EXIT_TIMEOUT));
+       sleep((unsigned int)getlogindefs_num("FAIL_DELAY", LOGIN_EXIT_TIMEOUT));
        exit(eval);
 }
 
@@ -320,7 +320,7 @@ static void chown_tty(struct login_context *cxt)
        grname = getlogindefs_str("TTYGROUP", TTYGRPNAME);
        if (grname && *grname) {
                if (*grname >= 0 && *grname <= 9)               /* group by ID */
-                       gid = getlogindefs_num("TTYGROUP", gid);
+                       gid = (gid_t)getlogindefs_num("TTYGROUP", gid);
                else {                                          /* group by name */
                        struct group *gr = getgrnam(grname);
                        if (gr)
@@ -772,7 +772,8 @@ static pam_handle_t *init_loginpam(struct login_context *cxt)
 
 static void loginpam_auth(struct login_context *cxt)
 {
-       int rc, failcount = 0, show_unknown, retries;
+       int rc, failcount = 0, show_unknown;
+       unsigned long retries;
        const char *hostname = cxt->hostname ? cxt->hostname :
                               cxt->tty_name ? cxt->tty_name : "<unknown>";
        pam_handle_t *pamh = cxt->pamh;
@@ -1235,11 +1236,11 @@ int main(int argc, char **argv)
                .conv = { misc_conv, NULL }     /* PAM conversation function */
        };
 
-       timeout = getlogindefs_num("LOGIN_TIMEOUT", LOGIN_TIMEOUT);
+       timeout = (unsigned int)getlogindefs_num("LOGIN_TIMEOUT", LOGIN_TIMEOUT);
 
        signal(SIGALRM, timedout);
        siginterrupt(SIGALRM, 1);       /* we have to interrupt syscalls like ioclt() */
-       alarm((unsigned int)timeout);
+       alarm(timeout);
        signal(SIGQUIT, SIG_IGN);
        signal(SIGINT, SIG_IGN);
 
index 6117936b89c2f33cfa3a42af243831309c5f3c36..84f8d9352f7c5b97346119b5d0114adea92992db 100644 (file)
@@ -186,17 +186,17 @@ int getlogindefs_bool(const char *name, int dflt)
        return ptr && ptr->value ? (strcasecmp(ptr->value, "yes") == 0) : dflt;
 }
 
-long getlogindefs_num(const char *name, long dflt)
+unsigned long getlogindefs_num(const char *name, long dflt)
 {
        struct item *ptr = search(name);
        char *end = NULL;
-       long retval;
+       unsigned long retval;
 
        if (!ptr || !ptr->value)
                return dflt;
 
        errno = 0;
-       retval = strtol(ptr->value, &end, 0);
+       retval = strtoul(ptr->value, &end, 0);
        if (end && *end == '\0' && !errno)
                return retval;
 
index 24e946ef58682c5321da60180972bcb582580970..c5ccbc91bdc2e687e250603f5869766c0eb7b570 100644 (file)
@@ -4,7 +4,7 @@
 extern void logindefs_load_file(const char *filename);
 extern void (*logindefs_load_defaults)(void);
 extern int getlogindefs_bool(const char *name, int dflt);
-extern long getlogindefs_num(const char *name, long dflt);
+extern unsigned long getlogindefs_num(const char *name, long dflt);
 extern const char *getlogindefs_str(const char *name, const char *dflt);
 extern void free_getlogindefs_data(void);
 extern int logindefs_setenv(const char *name, const char *conf, const char *dflt);
index 0e896323388e5072058db5e862bfcc4bd5639e97..7bc85b7988940809140b8b2807e4e12c93f4c6d6 100644 (file)
@@ -776,7 +776,7 @@ main (int argc, char **argv)
   if (!correct_password (pw))
     {
       log_su (pw, false);
-      sleep (getlogindefs_num ("FAIL_DELAY", 1));
+      sleep ((unsigned int)getlogindefs_num ("FAIL_DELAY", 1));
       error (EXIT_FAIL, 0, _("incorrect password"));
     }
   else