From f7a00a2334b0240d8b2a505304785bb75d02df12 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Sat, 21 Aug 2010 15:32:53 +0000 Subject: [PATCH] * libmisc/console.c, libmisc/motd.c, libmisc/setupenv.c, 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. --- lib/commonio.c | 3 ++- lib/commonio.h | 6 +++--- lib/prototypes.h | 4 ++-- libmisc/console.c | 3 ++- libmisc/failure.c | 2 +- libmisc/hushed.c | 2 +- libmisc/list.c | 18 +++++++++++++++--- libmisc/loginprompt.c | 6 +++--- libmisc/motd.c | 28 +++++++++++++++++++++------- libmisc/pam_pass_non_interractive.c | 2 +- libmisc/setupenv.c | 2 +- libmisc/sulog.c | 6 ++++-- libmisc/system.c | 4 ++-- libmisc/ttytype.c | 2 +- src/login.c | 2 +- src/userdel.c | 2 +- src/vipw.c | 22 +++++++++++----------- 17 files changed, 72 insertions(+), 42 deletions(-) diff --git a/lib/commonio.c b/lib/commonio.c index 4eae17d1..d72a74c8 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -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; diff --git a/lib/commonio.h b/lib/commonio.h index d320ca15..5febfcce 100644 --- a/lib/commonio.h +++ b/lib/commonio.h @@ -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 diff --git a/lib/prototypes.h b/lib/prototypes.h index 6e8998e1..b8e19ec3 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -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 */ diff --git a/libmisc/console.c b/libmisc/console.c index 20fbd7f5..ed6026d7 100644 --- a/libmisc/console.c +++ b/libmisc/console.c @@ -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, diff --git a/libmisc/failure.c b/libmisc/failure.c index 1a1e3d4a..6363fb83 100644 --- a/libmisc/failure.c +++ b/libmisc/failure.c @@ -296,7 +296,7 @@ void failtmp (const char *username, #endif /* !USE_UTMPX */ ) { - char *ftmp; + const char *ftmp; int fd; /* diff --git a/libmisc/hushed.c b/libmisc/hushed.c index c849ebfe..d1aa06ea 100644 --- a/libmisc/hushed.c +++ b/libmisc/hushed.c @@ -50,7 +50,7 @@ bool hushed (const char *username) { struct passwd *pw; - char *hushfile; + const char *hushfile; char buf[BUFSIZ]; bool found; FILE *fp; diff --git a/libmisc/list.c b/libmisc/list.c index 28ea4cec..2da734a7 100644 --- a/libmisc/list.c +++ b/libmisc/list.c @@ -141,7 +141,13 @@ 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; @@ -163,7 +169,13 @@ 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); diff --git a/libmisc/loginprompt.c b/libmisc/loginprompt.c index 9373e610..27f76224 100644 --- a/libmisc/loginprompt.c +++ b/libmisc/loginprompt.c @@ -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); diff --git a/libmisc/motd.c b/libmisc/motd.c index 65db7cbf..6ba7e128 100644 --- a/libmisc/motd.c +++ b/libmisc/motd.c @@ -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 @@ -47,21 +48,34 @@ 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; + } - strncpy (motdlist, mb, sizeof (motdlist)); - motdlist[sizeof (motdlist) - 1] = '\0'; + motdlist = xstrdup (motdfile); - for (mb = motdlist; (motdfile = strtok (mb, ":")) != NULL; mb = NULL) { - if ((fp = fopen (motdfile, "r")) != NULL) { - while ((c = getc (fp)) != EOF) + for (mb = motdlist; ;mb = NULL) { + motdfile = strtok (mb, ":"); + if (NULL == motdfile) { + break; + } + + fp = fopen (motdfile, "r"); + if (NULL != fp) { + while ((c = getc (fp)) != EOF) { putchar (c); + } fclose (fp); } } fflush (stdout); + + free (motdlist); } + diff --git a/libmisc/pam_pass_non_interractive.c b/libmisc/pam_pass_non_interractive.c index 8bdb3426..f68770e7 100644 --- a/libmisc/pam_pass_non_interractive.c +++ b/libmisc/pam_pass_non_interractive.c @@ -39,7 +39,7 @@ #include #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, diff --git a/libmisc/setupenv.c b/libmisc/setupenv.c index 36feb9b1..b9489dc0 100644 --- a/libmisc/setupenv.c +++ b/libmisc/setupenv.c @@ -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 diff --git a/libmisc/sulog.c b/libmisc/sulog.c index 76ae556a..6d187cc3 100644 --- a/libmisc/sulog.c +++ b/libmisc/sulog.c @@ -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); diff --git a/libmisc/system.c b/libmisc/system.c index 14221d1c..bcd7bb7e 100644 --- a/libmisc/system.c +++ b/libmisc/system.c @@ -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); diff --git a/libmisc/ttytype.c b/libmisc/ttytype.c index fdaf2dcd..7df0d9e6 100644 --- a/libmisc/ttytype.c +++ b/libmisc/ttytype.c @@ -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]; diff --git a/src/login.c b/src/login.c index 8c4d9101..f6ced023 100644 --- a/src/login.c +++ b/src/login.c @@ -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; diff --git a/src/userdel.c b/src/userdel.c index 929c7265..631cedd6 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -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; diff --git a/src/vipw.c b/src/vipw.c index d3246e32..535338ee 100644 --- a/src/vipw.c +++ b/src/vipw.c @@ -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); }