]> granicus.if.org Git - shadow/commitdiff
* libmisc/console.c, libmisc/motd.c, libmisc/setupenv.c,
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 21 Aug 2010 15:32:53 +0000 (15:32 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 21 Aug 2010 15:32:53 +0000 (15:32 +0000)
libmisc/sulog.c, libmisc/hushed.c, libmisc/failure.c,
libmisc/loginprompt.c, libmisc/ttytype.c,
libmisc/pam_pass_non_interractive.c, src/userdel.c, src/login.c,
lib/commonio.c, lib/commonio.h: Fix some const issues.
* libmisc/motd.c: Avoid multi-statements lines.
* libmisc/motd.c: Support long MOTD_FILE.
* libmisc/list.c, lib/prototypes.h: Revert previous change.
dup_list and is_on_list are used with members as defined for the
group structure, and thus even if the list is not modified, the
list elements cannot be constant strings.
* libmisc/system.c: Avoid C++ comments.
* src/vipw.c: WITH_TCB cannot be tested inside a gettextized
string. Split the Usage string.
* lib/commonio.h: Re-indent.

17 files changed:
lib/commonio.c
lib/commonio.h
lib/prototypes.h
libmisc/console.c
libmisc/failure.c
libmisc/hushed.c
libmisc/list.c
libmisc/loginprompt.c
libmisc/motd.c
libmisc/pam_pass_non_interractive.c
libmisc/setupenv.c
libmisc/sulog.c
libmisc/system.c
libmisc/ttytype.c
src/login.c
src/userdel.c
src/vipw.c

index 4eae17d182d6b76d7a53fadb69322a1d8478c4cb..d72a74c88f9e9a02a8a5bf724a85f6f61f1978f5 100644 (file)
@@ -780,7 +780,8 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *))
 /*
  * Sort entries in db according to order in another.
  */
-int commonio_sort_wrt (struct commonio_db *shadow, struct commonio_db *passwd)
+int commonio_sort_wrt (struct commonio_db *shadow,
+                       const struct commonio_db *passwd)
 {
        struct commonio_entry *head = NULL, *pw_ptr, *spw_ptr;
        const char *name;
index d320ca15b6bd2ed258d4f69b05966e196da0ec31..5febfccebd222c2511567fa6f2eecf85b7d59bc3 100644 (file)
@@ -151,10 +151,10 @@ extern /*@observer@*/ /*@null@*/const void *commonio_next (struct commonio_db *)
 extern int commonio_close (struct commonio_db *);
 extern int commonio_unlock (struct commonio_db *);
 extern void commonio_del_entry (struct commonio_db *,
-                               const struct commonio_entry *);
+                                const struct commonio_entry *);
 extern int commonio_sort_wrt (struct commonio_db *shadow,
-                             struct commonio_db *passwd);
+                              const struct commonio_db *passwd);
 extern int commonio_sort (struct commonio_db *db,
-                         int (*cmp) (const void *, const void *));
+                          int (*cmp) (const void *, const void *));
 
 #endif
index 6e8998e184574a711d35f6a00019ff92925c18ac..b8e19ec319bf475e3e7c9b90ec0439e61126086c 100644 (file)
@@ -214,8 +214,8 @@ extern void setup_limits (const struct passwd *);
 /* list.c */
 extern /*@only@*/ /*@out@*/char **add_list (/*@returned@*/ /*@only@*/char **, const char *);
 extern /*@only@*/ /*@out@*/char **del_list (/*@returned@*/ /*@only@*/char **, const char *);
-extern /*@only@*/ /*@out@*/char **dup_list (const char *const *);
-extern bool is_on_list (const char *const *list, const char *member);
+extern /*@only@*/ /*@out@*/char **dup_list (char *const *);
+extern bool is_on_list (char *const *list, const char *member);
 extern /*@only@*/char **comma_to_list (const char *);
 
 /* log.c */
index 20fbd7f5eb333d16a3e694aa3392466566f414b2..ed6026d75644af4287efaebcecbf8516b778d24c 100644 (file)
@@ -50,7 +50,8 @@ static bool is_listed (const char *cfgin, const char *tty, bool def);
 static bool is_listed (const char *cfgin, const char *tty, bool def)
 {
        FILE *fp;
-       char buf[200], *cons, *s;
+       char buf[200], *s;
+       const char *cons;
 
        /*
         * If the CONSOLE configuration definition isn't given,
index 1a1e3d4a7e07649823a892403d2876d8b2108630..6363fb83bbdd4ecc29e604a7afa9f05063a5c4fb 100644 (file)
@@ -296,7 +296,7 @@ void failtmp (const char *username,
 #endif                         /* !USE_UTMPX */
     )
 {
-       char *ftmp;
+       const char *ftmp;
        int fd;
 
        /*
index c849ebfea011c3e525ab8a4fd3a0ec7a95e49e43..d1aa06ea7d7d9746f5eef5eb9b98abcf1f7a97a4 100644 (file)
@@ -50,7 +50,7 @@
 bool hushed (const char *username)
 {
        struct passwd *pw;
-       char *hushfile;
+       const char *hushfile;
        char buf[BUFSIZ];
        bool found;
        FILE *fp;
index 28ea4cec59f4b8dd8bc0993882e85d91744f4d45..2da734a74d3cbb74c640df252e49808cd963049f 100644 (file)
        return tmp;
 }
 
-/*@only@*/ /*@out@*/char **dup_list (const char *const *list)
+/*
+ * Duplicate a list.
+ * The input list is not modified, but in order to allow the use of this
+ * function with list of members, the list elements are not enforced to be
+ * constant strings here.
+ */
+/*@only@*/ /*@out@*/char **dup_list (char *const *list)
 {
        int i;
        char **tmp;
        return tmp;
 }
 
-bool is_on_list (const char *const *list, const char *member)
+/*
+ * Check if member is part of the input list
+ * The input list is not modified, but in order to allow the use of this
+ * function with list of members, the list elements are not enforced to be
+ * constant strings here.
+ */
+bool is_on_list (char *const *list, const char *member)
 {
        assert (NULL != member);
        assert (NULL != list);
@@ -187,7 +199,7 @@ bool is_on_list (const char *const *list, const char *member)
        char *members;
        char **array;
        int i;
-       const char *cp;
+       char *cp;
        char *cp2;
 
        assert (NULL != comma);
index 9373e610af29da0cfa2d4a1c8e1241fa518fdc5e..27f7622459de3efee28cea669ecaa80e00100fa4 100644 (file)
@@ -87,9 +87,9 @@ void login_prompt (const char *prompt, char *name, int namesize)
         */
 
        if (NULL != prompt) {
-               cp = getdef_str ("ISSUE_FILE");
-               if (NULL != cp) {
-                       fp = fopen (cp, "r");
+               const char *fname = getdef_str ("ISSUE_FILE");
+               if (NULL != fname) {
+                       fp = fopen (fname, "r");
                        if (NULL != fp) {
                                while ((i = getc (fp)) != EOF) {
                                        (void) putc (i, stdout);
index 65db7cbf01d26d9f7dab090ed5a704cae2ae00ec..6ba7e1285959ba47b7e02477dd4df3debaa156f4 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright (c) 1989 - 1991, Julianne Frances Haugh
  * Copyright (c) 1996 - 1997, Marek Michałkiewicz
  * Copyright (c) 2003 - 2005, Tomasz Kłoczko
+ * Copyright (c) 2010       , Nicolas François
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 void motd (void)
 {
        FILE *fp;
-       char motdlist[BUFSIZ], *motdfile, *mb;
+       char *motdlist;
+       const char *motdfile;
+       char *mb;
        register int c;
 
-       if ((mb = getdef_str ("MOTD_FILE")) == NULL)
+       motdfile = getdef_str ("MOTD_FILE");
+       if (NULL == motdfile) {
                return;
+       }
+
+       motdlist = xstrdup (motdfile);
 
-       strncpy (motdlist, mb, sizeof (motdlist));
-       motdlist[sizeof (motdlist) - 1] = '\0';
+       for (mb = motdlist; ;mb = NULL) {
+               motdfile = strtok (mb, ":");
+               if (NULL == motdfile) {
+                       break;
+               }
 
-       for (mb = motdlist; (motdfile = strtok (mb, ":")) != NULL; mb = NULL) {
-               if ((fp = fopen (motdfile, "r")) != NULL) {
-                       while ((c = getc (fp)) != EOF)
+               fp = fopen (motdfile, "r");
+               if (NULL != fp) {
+                       while ((c = getc (fp)) != EOF) {
                                putchar (c);
+                       }
                        fclose (fp);
                }
        }
        fflush (stdout);
+
+       free (motdlist);
 }
+
index 8bdb3426e612c3c53cc3dcf67005ea376613f9ec..f68770e74545239f1d251e71095476245f3832dc 100644 (file)
@@ -39,7 +39,7 @@
 #include <security/pam_appl.h>
 #include "prototypes.h"
 
-/*@null@*/ /*@only@*/static char *non_interactive_password = NULL;
+/*@null@*/ /*@only@*/static const char *non_interactive_password = NULL;
 static int ni_conv (int num_msg,
                     const struct pam_message **msg,
                     struct pam_response **resp,
index 36feb9b16bb2d2b4b8f76b56723b200ea3bbefae..b9489dc07a78d3f754b1cb6c2820d8607b887753 100644 (file)
@@ -202,7 +202,7 @@ void setup_env (struct passwd *info)
 #ifndef USE_PAM
        char *envf;
 #endif
-       char *cp;
+       const char *cp;
 
        /*
         * Change the current working directory to be the home directory
index 76ae556ad3268839aebd3afed0131631d47e7063..6d187cc3eefca2daa015be6887cd7ec2929bf184 100644 (file)
@@ -47,7 +47,7 @@
  */
 void sulog (const char *tty, bool success, const char *oldname, const char *name)
 {
-       char *sulog_file;
+       const char *sulog_file;
        time_t now;
        struct tm *tm;
        FILE *fp;
@@ -62,8 +62,10 @@ void sulog (const char *tty, bool success, const char *oldname, const char *name
                        "FAILED su for %s by %s",name,oldname));
        }
 
-       if ((sulog_file = getdef_str ("SULOG_FILE")) == (char *) 0)
+       sulog_file = getdef_str ("SULOG_FILE");
+       if (NULL == sulog_file) {
                return;
+       }
 
        oldgid = getgid ();
        oldmask = umask (077);
index 14221d1c002cdc1560fb5b2d9b8e07e7da60e826..bcd7bb7e264de214bcc353e28fb1a6d2291081f7 100644 (file)
@@ -60,9 +60,9 @@ int safe_system (const char *command,
 
        fd = open ("/dev/null", O_RDWR);
        /* Child */
-       dup2 (fd, 0);   // Close Stdin
+       dup2 (fd, 0);           /* Close Stdin */
        if (ignore_stderr) {
-               dup2 (fd, 2);   // Close Stderr
+               dup2 (fd, 2);   /* Close Stderr */
        }
 
        execve (command, (char *const *) argv, (char *const *) env);
index fdaf2dcdb9a0dc49a5e5419466dd85b1ca3e02f7..7df0d9e6b53c640be64144a661782279942883f1 100644 (file)
@@ -45,7 +45,7 @@ void ttytype (const char *line)
 {
        FILE *fp;
        char buf[BUFSIZ];
-       char *typefile;
+       const char *typefile;
        char *cp;
        char type[BUFSIZ];
        char port[BUFSIZ];
index 8c4d9101d2bc8a8cafb158cf006f28b5f049bc80..f6ced0235e7034fffb15eec19a6cdbbb520fd94b 100644 (file)
@@ -533,7 +533,7 @@ int main (int argc, char **argv)
 #endif
        int err;
        const char *cp;
-       char *tmp;
+       const char *tmp;
        char fromhost[512];
        struct passwd *pwd = NULL;
        char **envp = environ;
index 929c7265ecd095972e3aa3e9803466d7d6e962a7..631cedd685b36fd69141ab0df7ee54397af3dee4 100644 (file)
@@ -596,7 +596,7 @@ static void update_user (void)
 
 static void user_cancel (const char *user)
 {
-       char *cmd;
+       const char *cmd;
        pid_t pid, wpid;
        int status;
 
index d3246e32dab05f5635099b668aa30e4104ffa2d2..535338ee17e1dca707d0e8f217c48795d0d6a626 100644 (file)
@@ -83,19 +83,19 @@ static void vipwedit (const char *, int (*)(void), int (*)(void));
  */
 static void usage (int status)
 {
-       (void)
-       fputs (_("Usage: vipw [options]\n"
-                "\n"
-                "Options:\n"
-                "  -g, --group                   edit group database\n"
-                "  -h, --help                    display this help message and exit\n"
-                "  -p, --passwd                  edit passwd database\n"
-                "  -q, --quiet                   quiet mode\n"
-                "  -s, --shadow                  edit shadow or gshadow database\n"
+       FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
+       (void) fputs (_("Usage: vipw [options]\n"
+                       "\n"
+                       "Options:\n"), usageout);
+       (void) fputs (_("  -g, --group                   edit group database\n"), usageout);
+       (void) fputs (_("  -h, --help                    display this help message and exit\n"), usageout);
+       (void) fputs (_("  -p, --passwd                  edit passwd database\n"), usageout);
+       (void) fputs (_("  -q, --quiet                   quiet mode\n"), usageout);
+       (void) fputs (_("  -s, --shadow                  edit shadow or gshadow database\n"), usageout);
 #ifdef WITH_TCB
-                "  -u, --user                    which user's tcb shadow file to edit\n"
+       (void) fputs (_("  -u, --user                    which user's tcb shadow file to edit\n"), usageout);
 #endif                         /* WITH_TCB */
-                "\n"), (E_SUCCESS != status) ? stderr : stdout);
+       (void) fputs (_("\n"), usageout);
        exit (status);
 }