diff options
Diffstat (limited to '')
-rw-r--r-- | lib/addgrps.c (renamed from libmisc/addgrps.c) | 18 | ||||
-rw-r--r-- | lib/age.c (renamed from libmisc/age.c) | 17 | ||||
-rw-r--r-- | lib/alloc.c (renamed from libmisc/xmalloc.c) | 57 | ||||
-rw-r--r-- | lib/audit_help.c (renamed from libmisc/audit_help.c) | 10 | ||||
-rw-r--r-- | lib/basename.c (renamed from libmisc/basename.c) | 4 | ||||
-rw-r--r-- | lib/btrfs.c (renamed from libmisc/btrfs.c) | 2 | ||||
-rw-r--r-- | lib/chkname.c (renamed from libmisc/chkname.c) | 57 | ||||
-rw-r--r-- | lib/chkname.h (renamed from libmisc/chkname.h) | 9 | ||||
-rw-r--r-- | lib/chowndir.c (renamed from libmisc/chowndir.c) | 0 | ||||
-rw-r--r-- | lib/chowntty.c (renamed from libmisc/chowntty.c) | 2 | ||||
-rw-r--r-- | lib/cleanup.c (renamed from libmisc/cleanup.c) | 0 | ||||
-rw-r--r-- | lib/cleanup_group.c (renamed from libmisc/cleanup_group.c) | 17 | ||||
-rw-r--r-- | lib/cleanup_user.c (renamed from libmisc/cleanup_user.c) | 23 | ||||
-rw-r--r-- | lib/console.c (renamed from libmisc/console.c) | 9 | ||||
-rw-r--r-- | lib/copydir.c (renamed from libmisc/copydir.c) | 333 | ||||
-rw-r--r-- | lib/env.c (renamed from libmisc/env.c) | 73 | ||||
-rw-r--r-- | lib/failure.c (renamed from libmisc/failure.c) | 126 | ||||
-rw-r--r-- | lib/failure.h (renamed from libmisc/failure.h) | 17 | ||||
-rw-r--r-- | lib/find_new_gid.c (renamed from libmisc/find_new_gid.c) | 53 | ||||
-rw-r--r-- | lib/find_new_sub_gids.c (renamed from libmisc/find_new_sub_gids.c) | 2 | ||||
-rw-r--r-- | lib/find_new_sub_uids.c (renamed from libmisc/find_new_sub_uids.c) | 2 | ||||
-rw-r--r-- | lib/find_new_uid.c (renamed from libmisc/find_new_uid.c) | 53 | ||||
-rw-r--r-- | lib/getdate.c (renamed from libmisc/getdate.c) | 229 | ||||
-rw-r--r-- | lib/getdate.h (renamed from libmisc/getdate.h) | 0 | ||||
-rw-r--r-- | lib/getdate.y (renamed from libmisc/getdate.y) | 23 | ||||
-rw-r--r-- | lib/getgr_nam_gid.c (renamed from libmisc/getgr_nam_gid.c) | 12 | ||||
-rw-r--r-- | lib/hushed.c (renamed from libmisc/hushed.c) | 17 | ||||
-rw-r--r-- | lib/idmapping.c (renamed from libmisc/idmapping.c) | 63 | ||||
-rw-r--r-- | lib/idmapping.h (renamed from libmisc/idmapping.h) | 0 | ||||
-rw-r--r-- | lib/isexpired.c (renamed from libmisc/isexpired.c) | 19 | ||||
-rw-r--r-- | lib/limits.c (renamed from libmisc/limits.c) | 138 | ||||
-rw-r--r-- | lib/list.c (renamed from libmisc/list.c) | 50 | ||||
-rw-r--r-- | lib/log.c (renamed from libmisc/log.c) | 36 | ||||
-rw-r--r-- | lib/mail.c (renamed from libmisc/mail.c) | 14 | ||||
-rw-r--r-- | lib/motd.c (renamed from libmisc/motd.c) | 4 | ||||
-rw-r--r-- | lib/myname.c (renamed from libmisc/myname.c) | 0 | ||||
-rw-r--r-- | lib/obscure.c (renamed from libmisc/obscure.c) | 112 | ||||
-rw-r--r-- | lib/pam_pass.c (renamed from libmisc/pam_pass.c) | 2 | ||||
-rw-r--r-- | lib/pam_pass_non_interactive.c (renamed from libmisc/pam_pass_non_interactive.c) | 20 | ||||
-rw-r--r-- | lib/prefix_flag.c (renamed from libmisc/prefix_flag.c) | 102 | ||||
-rw-r--r-- | lib/pwd2spwd.c (renamed from libmisc/pwd2spwd.c) | 9 | ||||
-rw-r--r-- | lib/pwd_init.c (renamed from libmisc/pwd_init.c) | 27 | ||||
-rw-r--r-- | lib/pwdcheck.c (renamed from libmisc/pwdcheck.c) | 8 | ||||
-rw-r--r-- | lib/remove_tree.c (renamed from libmisc/remove_tree.c) | 0 | ||||
-rw-r--r-- | lib/rlogin.c (renamed from libmisc/rlogin.c) | 104 | ||||
-rw-r--r-- | lib/root_flag.c (renamed from libmisc/root_flag.c) | 8 | ||||
-rw-r--r-- | lib/salt.c (renamed from libmisc/salt.c) | 142 | ||||
-rw-r--r-- | lib/setugid.c (renamed from libmisc/setugid.c) | 0 | ||||
-rw-r--r-- | lib/setupenv.c (renamed from libmisc/setupenv.c) | 29 | ||||
-rw-r--r-- | lib/shell.c (renamed from libmisc/shell.c) | 20 | ||||
-rw-r--r-- | lib/sub.c (renamed from libmisc/sub.c) | 18 | ||||
-rw-r--r-- | lib/sulog.c (renamed from libmisc/sulog.c) | 2 | ||||
-rw-r--r-- | lib/ttytype.c (renamed from libmisc/ttytype.c) | 8 | ||||
-rw-r--r-- | lib/tz.c (renamed from libmisc/tz.c) | 7 | ||||
-rw-r--r-- | lib/ulimit.c (renamed from libmisc/ulimit.c) | 20 | ||||
-rw-r--r-- | lib/user_busy.c (renamed from libmisc/user_busy.c) | 68 | ||||
-rw-r--r-- | lib/valid.c (renamed from libmisc/valid.c) | 0 | ||||
-rw-r--r-- | lib/xgetXXbyYY.c (renamed from libmisc/xgetXXbyYY.c) | 41 | ||||
-rw-r--r-- | lib/xgetgrgid.c (renamed from libmisc/xgetgrgid.c) | 4 | ||||
-rw-r--r-- | lib/xgetgrnam.c (renamed from libmisc/xgetgrnam.c) | 4 | ||||
-rw-r--r-- | lib/xgetpwnam.c (renamed from libmisc/xgetpwnam.c) | 4 | ||||
-rw-r--r-- | lib/xgetpwuid.c (renamed from libmisc/xgetpwuid.c) | 4 | ||||
-rw-r--r-- | lib/xgetspnam.c (renamed from libmisc/xgetspnam.c) | 2 | ||||
-rw-r--r-- | libmisc/.indent.pro | 5 | ||||
-rw-r--r-- | libmisc/Makefile.am | 80 | ||||
-rw-r--r-- | libmisc/Makefile.in | 927 | ||||
-rw-r--r-- | libmisc/date_to_str.c | 46 | ||||
-rw-r--r-- | libmisc/entry.c | 45 | ||||
-rw-r--r-- | libmisc/getrange.c | 101 | ||||
-rw-r--r-- | libmisc/gettime.c | 68 | ||||
-rw-r--r-- | libmisc/loginprompt.c | 155 | ||||
-rw-r--r-- | libmisc/strtoday.c | 220 | ||||
-rw-r--r-- | libmisc/utmp.c | 474 | ||||
-rw-r--r-- | libmisc/yesno.c | 56 |
74 files changed, 976 insertions, 3455 deletions
diff --git a/libmisc/addgrps.c b/lib/addgrps.c index 845d383..dae3dba 100644 --- a/libmisc/addgrps.c +++ b/lib/addgrps.c @@ -17,6 +17,8 @@ #include <stdio.h> #include <grp.h> #include <errno.h> + +#include "alloc.h" #include "shadowlog.h" #ident "$Id$" @@ -29,7 +31,7 @@ */ int add_groups (const char *list) { - GETGROUPS_T *grouplist, *tmp; + GETGROUPS_T *grouplist; size_t i; int ngroups; bool added; @@ -46,7 +48,7 @@ int add_groups (const char *list) i = 16; for (;;) { - grouplist = (gid_t *) malloc (i * sizeof (GETGROUPS_T)); + grouplist = MALLOC(i, GETGROUPS_T); if (NULL == grouplist) { return -1; } @@ -88,19 +90,17 @@ int add_groups (const char *list) fputs (_("Warning: too many groups\n"), shadow_logfd); break; } - tmp = (gid_t *) realloc (grouplist, (size_t)(ngroups + 1) * sizeof (GETGROUPS_T)); - if (NULL == tmp) { - free (grouplist); + grouplist = REALLOCF(grouplist, (size_t) ngroups + 1, GETGROUPS_T); + if (grouplist == NULL) { return -1; } - tmp[ngroups] = grp->gr_gid; + grouplist[ngroups] = grp->gr_gid; ngroups++; - grouplist = tmp; added = true; } if (added) { - ret = setgroups ((size_t)ngroups, grouplist); + ret = setgroups (ngroups, grouplist); free (grouplist); return ret; } @@ -109,6 +109,6 @@ int add_groups (const char *list) return 0; } #else /* HAVE_SETGROUPS && !USE_PAM */ -extern int errno; /* warning: ANSI C forbids an empty source file */ +extern int ISO_C_forbids_an_empty_translation_unit; #endif /* HAVE_SETGROUPS && !USE_PAM */ diff --git a/libmisc/age.c b/lib/age.c index d10f71b..72a13ea 100644 --- a/libmisc/age.c +++ b/lib/age.c @@ -13,12 +13,15 @@ #include <stdio.h> #include <time.h> #include <errno.h> -#include "prototypes.h" -#include "defines.h" -#include "exitcodes.h" #include <pwd.h> #include <grp.h> +#include "adds.h" +#include "defines.h" +#include "exitcodes.h" +#include "prototypes.h" + + #ident "$Id$" #ifndef PASSWD_PROGRAM @@ -112,7 +115,7 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp) _exit (126); } - (void) execl (PASSWD_PROGRAM, PASSWD_PROGRAM, pw->pw_name, (char *) 0); + (void) execl (PASSWD_PROGRAM, PASSWD_PROGRAM, pw->pw_name, (char *) NULL); err = errno; perror ("Can't execute " PASSWD_PROGRAM); _exit ((ENOENT == err) ? E_CMD_NOTFOUND : E_CMD_NOEXEC); @@ -139,7 +142,7 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp) void agecheck (/*@null@*/const struct spwd *sp) { - long now = (long) time ((time_t *) 0) / SCALE; + long now = time(NULL) / DAY; long remain; if (NULL == sp) { @@ -162,9 +165,9 @@ void agecheck (/*@null@*/const struct spwd *sp) return; } - remain = sp->sp_lstchg + sp->sp_max - now; + remain = addsl(sp->sp_lstchg, sp->sp_max, -now); + if (remain <= sp->sp_warn) { - remain /= DAY / SCALE; if (remain > 1) { (void) printf (_("Your password will expire in %ld days.\n"), remain); diff --git a/libmisc/xmalloc.c b/lib/alloc.c index 056d472..962f45a 100644 --- a/libmisc/xmalloc.c +++ b/lib/alloc.c @@ -3,6 +3,7 @@ * SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz * SPDX-FileCopyrightText: 2003 - 2006, Tomasz Kłoczko * SPDX-FileCopyrightText: 2008 , Nicolas François + * SPDX-FileCopyrightText: 2023 , Alejandro Colomar <alx@kernel.org> * * SPDX-License-Identifier: BSD-3-Clause */ @@ -11,7 +12,7 @@ to be worth copyrighting :-). I did that because a lot of code used malloc and strdup without checking for NULL pointer, and I like some message better than a core dump... --marekm - + Yeh, but. Remember that bailing out might leave the system in some bizarre state. You really want to put in error checking, then add some back-out failure recovery code. -- jfh */ @@ -20,27 +21,53 @@ #ident "$Id$" -#include <stdio.h> +#include "alloc.h" + #include <errno.h> +#include <stddef.h> +#include <stdio.h> + #include "defines.h" #include "prototypes.h" #include "shadowlog.h" -/*@maynotreturn@*/ /*@only@*//*@out@*//*@notnull@*/void *xmalloc (size_t size) + +extern inline void *xmalloc(size_t size); +extern inline void *xmallocarray(size_t nmemb, size_t size); +extern inline void *mallocarray(size_t nmemb, size_t size); +extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size); +extern inline char *xstrdup(const char *str); + + +void * +xcalloc(size_t nmemb, size_t size) { - void *ptr; - - ptr = malloc (size); - if (NULL == ptr) { - (void) fprintf (log_get_logfd(), - _("%s: failed to allocate memory: %s\n"), - log_get_progname(), strerror (errno)); - exit (13); - } - return ptr; + void *p; + + p = calloc(nmemb, size); + if (p == NULL) + goto x; + + return p; + +x: + fprintf(log_get_logfd(), _("%s: %s\n"), + log_get_progname(), strerror(errno)); + exit(13); } -/*@maynotreturn@*/ /*@only@*//*@notnull@*/char *xstrdup (const char *str) + +void * +xreallocarray(void *p, size_t nmemb, size_t size) { - return strcpy (xmalloc (strlen (str) + 1), str); + p = reallocarrayf(p, nmemb, size); + if (p == NULL) + goto x; + + return p; + +x: + fprintf(log_get_logfd(), _("%s: %s\n"), + log_get_progname(), strerror(errno)); + exit(13); } diff --git a/libmisc/audit_help.c b/lib/audit_help.c index e6c2006..54109f0 100644 --- a/libmisc/audit_help.c +++ b/lib/audit_help.c @@ -21,6 +21,8 @@ #include <libaudit.h> #include <errno.h> #include <stdio.h> + +#include "attr.h" #include "prototypes.h" #include "shadowlog.h" int audit_fd; @@ -54,7 +56,7 @@ void audit_help_open (void) * id - uid or gid that the operation is being performed on. This is used * only when user is NULL. */ -void audit_logger (int type, unused const char *pgname, const char *op, +void audit_logger (int type, MAYBE_UNUSED const char *pgname, const char *op, const char *name, unsigned int id, shadow_audit_result result) { @@ -62,7 +64,7 @@ void audit_logger (int type, unused const char *pgname, const char *op, return; } else { audit_log_acct_message (audit_fd, type, NULL, op, name, id, - NULL, NULL, NULL, (int) result); + NULL, NULL, NULL, result); } } @@ -77,11 +79,11 @@ void audit_logger_message (const char *message, shadow_audit_result result) NULL, /* hostname */ NULL, /* addr */ NULL, /* tty */ - (int) result); + result); } } #else /* WITH_AUDIT */ -extern int errno; /* warning: ANSI C forbids an empty source file */ +extern int ISO_C_forbids_an_empty_translation_unit; #endif /* WITH_AUDIT */ diff --git a/libmisc/basename.c b/lib/basename.c index fe91653..95a2f85 100644 --- a/libmisc/basename.c +++ b/lib/basename.c @@ -21,6 +21,10 @@ #include "prototypes.h" /*@observer@*/const char *Basename (const char *str) { + if (str == NULL) { + abort (); + } + char *cp = strrchr (str, '/'); return (NULL != cp) ? cp + 1 : str; diff --git a/libmisc/btrfs.c b/lib/btrfs.c index a2563f7..0391598 100644 --- a/libmisc/btrfs.c +++ b/lib/btrfs.c @@ -39,7 +39,7 @@ static int run_btrfs_subvolume_cmd(const char *subcmd, const char *arg1, const c NULL }; - if (access(cmd, X_OK)) { + if (!cmd || access(cmd, X_OK)) { return 1; } diff --git a/libmisc/chkname.c b/lib/chkname.c index e31ee8c..995562f 100644 --- a/libmisc/chkname.c +++ b/lib/chkname.c @@ -1,11 +1,10 @@ -/* - * SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2001 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2005 - 2008, Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-2000, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2001-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2005-2008, Nicolas François +// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org> +// SPDX-License-Identifier: BSD-3-Clause + /* * is_valid_user_name(), is_valid_group_name() - check the new user/group @@ -15,16 +14,39 @@ * false - bad name */ + #include <config.h> #ident "$Id$" #include <ctype.h> +#include <errno.h> +#include <limits.h> +#include <stdbool.h> +#include <stddef.h> +#include <unistd.h> + #include "defines.h" #include "chkname.h" + int allow_bad_names = false; + +size_t +login_name_max_size(void) +{ + long conf; + + errno = 0; + conf = sysconf(_SC_LOGIN_NAME_MAX); + if (conf == -1 && errno != 0) + return LOGIN_NAME_MAX; + + return conf; +} + + static bool is_valid_name (const char *name) { if (allow_bad_names) { @@ -32,8 +54,8 @@ static bool is_valid_name (const char *name) } /* - * User/group names must match gnu e-regex: - * [a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]? + * User/group names must match BRE regex: + * [a-zA-Z0-9_.][a-zA-Z0-9_.-]*$\? * * as a non-POSIX, extension, allow "$" as the last char for * sake of Samba 3.x "add machine script" @@ -72,19 +94,17 @@ static bool is_valid_name (const char *name) return !numeric; } -bool is_valid_user_name (const char *name) + +bool +is_valid_user_name(const char *name) { - /* - * User names are limited by whatever utmp can - * handle. - */ - if (strlen (name) > USER_NAME_MAX_LENGTH) { + if (strlen(name) >= login_name_max_size()) return false; - } - return is_valid_name (name); + return is_valid_name(name); } + bool is_valid_group_name (const char *name) { /* @@ -98,4 +118,3 @@ bool is_valid_group_name (const char *name) return is_valid_name (name); } - diff --git a/libmisc/chkname.h b/lib/chkname.h index 0771347..4306a8a 100644 --- a/libmisc/chkname.h +++ b/lib/chkname.h @@ -11,6 +11,7 @@ #ifndef _CHKNAME_H_ #define _CHKNAME_H_ + /* * is_valid_user_name(), is_valid_group_name() - check the new user/group * name for validity; @@ -19,8 +20,14 @@ * false - bad name */ -#include "defines.h" +#include <config.h> + +#include <stdbool.h> +#include <stddef.h> + + +extern size_t login_name_max_size(void); extern bool is_valid_user_name (const char *name); extern bool is_valid_group_name (const char *name); diff --git a/libmisc/chowndir.c b/lib/chowndir.c index d31618a..d31618a 100644 --- a/libmisc/chowndir.c +++ b/lib/chowndir.c diff --git a/libmisc/chowntty.c b/lib/chowntty.c index 8043d8c..70127f3 100644 --- a/libmisc/chowntty.c +++ b/lib/chowntty.c @@ -51,7 +51,7 @@ void chown_tty (const struct passwd *info) */ if ( (fchown (STDIN_FILENO, info->pw_uid, gid) != 0) - || (fchmod (STDIN_FILENO, (mode_t)getdef_num ("TTYPERM", 0600)) != 0)) { + || (fchmod (STDIN_FILENO, getdef_num ("TTYPERM", 0600)) != 0)) { int err = errno; FILE *shadow_logfd = log_get_logfd(); diff --git a/libmisc/cleanup.c b/lib/cleanup.c index c16f1bc..c16f1bc 100644 --- a/libmisc/cleanup.c +++ b/lib/cleanup.c diff --git a/libmisc/cleanup_group.c b/lib/cleanup_group.c index df3ebfd..50c7084 100644 --- a/libmisc/cleanup_group.c +++ b/lib/cleanup_group.c @@ -9,6 +9,7 @@ #include <assert.h> #include <stdio.h> +#include "attr.h" #include "defines.h" #include "groupio.h" #include "sgroupio.h" @@ -22,7 +23,7 @@ */ void cleanup_report_add_group (void *group_name) { - const char *name = (const char *)group_name; + const char *name = group_name; SYSLOG ((LOG_ERR, "failed to add group %s", name)); #ifdef WITH_AUDIT @@ -40,7 +41,7 @@ void cleanup_report_add_group (void *group_name) */ void cleanup_report_del_group (void *group_name) { - const char *name = (const char *)group_name; + const char *name = group_name; SYSLOG ((LOG_ERR, "failed to remove group %s", name)); #ifdef WITH_AUDIT @@ -95,7 +96,7 @@ void cleanup_report_mod_gshadow (void *cleanup_info) */ void cleanup_report_add_group_group (void *group_name) { - const char *name = (const char *)group_name; + const char *name = group_name; SYSLOG ((LOG_ERR, "failed to add group %s to %s", name, gr_dbname ())); #ifdef WITH_AUDIT @@ -115,7 +116,7 @@ void cleanup_report_add_group_group (void *group_name) */ void cleanup_report_add_group_gshadow (void *group_name) { - const char *name = (const char *)group_name; + const char *name = group_name; SYSLOG ((LOG_ERR, "failed to add group %s to %s", name, sgr_dbname ())); #ifdef WITH_AUDIT @@ -136,7 +137,7 @@ void cleanup_report_add_group_gshadow (void *group_name) */ void cleanup_report_del_group_group (void *group_name) { - const char *name = (const char *)group_name; + const char *name = group_name; SYSLOG ((LOG_ERR, "failed to remove group %s from %s", @@ -159,7 +160,7 @@ void cleanup_report_del_group_group (void *group_name) */ void cleanup_report_del_group_gshadow (void *group_name) { - const char *name = (const char *)group_name; + const char *name = group_name; SYSLOG ((LOG_ERR, "failed to remove group %s from %s", @@ -178,7 +179,7 @@ void cleanup_report_del_group_gshadow (void *group_name) * * It should be registered after the group file is successfully locked. */ -void cleanup_unlock_group (unused void *arg) +void cleanup_unlock_group (MAYBE_UNUSED void *arg) { if (gr_unlock () == 0) { fprintf (log_get_logfd(), @@ -198,7 +199,7 @@ void cleanup_unlock_group (unused void *arg) * * It should be registered after the gshadow file is successfully locked. */ -void cleanup_unlock_gshadow (unused void *arg) +void cleanup_unlock_gshadow (MAYBE_UNUSED void *arg) { if (sgr_unlock () == 0) { fprintf (log_get_logfd(), diff --git a/libmisc/cleanup_user.c b/lib/cleanup_user.c index 26675c6..9c4bda9 100644 --- a/libmisc/cleanup_user.c +++ b/lib/cleanup_user.c @@ -9,6 +9,7 @@ #include <assert.h> #include <stdio.h> +#include "attr.h" #include "defines.h" #include "pwio.h" #include "shadowio.h" @@ -16,13 +17,13 @@ #include "shadowlog.h" /* - * cleanup_report_add_user - Report failure to add an user to the system + * cleanup_report_add_user - Report failure to add a user to the system * - * It should be registered when it is decided to add an user to the system. + * It should be registered when it is decided to add a user to the system. */ void cleanup_report_add_user (void *user_name) { - const char *name = (const char *)user_name; + const char *name = user_name; SYSLOG ((LOG_ERR, "failed to add user %s", name)); #ifdef WITH_AUDIT @@ -51,15 +52,15 @@ void cleanup_report_mod_passwd (void *cleanup_info) } /* - * cleanup_report_add_user_passwd - Report failure to add an user to + * cleanup_report_add_user_passwd - Report failure to add a user to * /etc/passwd * - * It should be registered when it is decided to add an user to the + * It should be registered when it is decided to add a user to the * /etc/passwd database. */ void cleanup_report_add_user_passwd (void *user_name) { - const char *name = (const char *)user_name; + const char *name = user_name; SYSLOG ((LOG_ERR, "failed to add user %s to %s", name, pw_dbname ())); #ifdef WITH_AUDIT @@ -71,15 +72,15 @@ void cleanup_report_add_user_passwd (void *user_name) } /* - * cleanup_report_add_user_shadow - Report failure to add an user to + * cleanup_report_add_user_shadow - Report failure to add a user to * /etc/shadow * - * It should be registered when it is decided to add an user to the + * It should be registered when it is decided to add a user to the * /etc/shadow database. */ void cleanup_report_add_user_shadow (void *user_name) { - const char *name = (const char *)user_name; + const char *name = user_name; SYSLOG ((LOG_ERR, "failed to add user %s to %s", name, spw_dbname ())); #ifdef WITH_AUDIT @@ -95,7 +96,7 @@ void cleanup_report_add_user_shadow (void *user_name) * * It should be registered after the passwd database is successfully locked. */ -void cleanup_unlock_passwd (unused void *arg) +void cleanup_unlock_passwd (MAYBE_UNUSED void *arg) { if (pw_unlock () == 0) { fprintf (log_get_logfd(), @@ -114,7 +115,7 @@ void cleanup_unlock_passwd (unused void *arg) * * It should be registered after the shadow database is successfully locked. */ -void cleanup_unlock_shadow (unused void *arg) +void cleanup_unlock_shadow (MAYBE_UNUSED void *arg) { if (spw_unlock () == 0) { fprintf (log_get_logfd(), diff --git a/libmisc/console.c b/lib/console.c index c475aa2..92065d9 100644 --- a/libmisc/console.c +++ b/lib/console.c @@ -13,6 +13,7 @@ #include <stdio.h> #include "getdef.h" #include "prototypes.h" +#include "string/strtcpy.h" #ident "$Id$" @@ -44,8 +45,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def) if (*cons != '/') { char *pbuf; - strncpy (buf, cons, sizeof (buf)); - buf[sizeof (buf) - 1] = '\0'; + STRTCPY(buf, cons); pbuf = &buf[0]; while ((s = strtok (pbuf, ":")) != NULL) { if (strcmp (s, tty) == 0) { @@ -71,8 +71,9 @@ static bool is_listed (const char *cfgin, const char *tty, bool def) * See if this tty is listed in the console file. */ - while (fgets (buf, (int) sizeof (buf), fp) != NULL) { - buf[strlen (buf) - 1] = '\0'; + while (fgets (buf, sizeof (buf), fp) != NULL) { + /* Remove optional trailing '\n'. */ + buf[strcspn (buf, "\n")] = '\0'; if (strcmp (buf, tty) == 0) { (void) fclose (fp); return true; diff --git a/libmisc/copydir.c b/lib/copydir.c index b692aa9..926033a 100644 --- a/libmisc/copydir.c +++ b/lib/copydir.c @@ -17,6 +17,9 @@ #include <sys/time.h> #include <fcntl.h> #include <stdio.h> + +#include "alloc.h" +#include "attr.h" #include "prototypes.h" #include "defines.h" #ifdef WITH_SELINUX @@ -33,6 +36,7 @@ #include <attr/libattr.h> #endif /* WITH_ATTR */ #include "shadowlog.h" +#include "string/sprintf.h" static /*@null@*/const char *src_orig; @@ -64,12 +68,12 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst, gid_t old_gid, gid_t new_gid); static /*@null@*/char *readlink_malloc (const char *filename); static int copy_symlink (const struct path_info *src, const struct path_info *dst, - unused bool reset_selinux, + MAYBE_UNUSED bool reset_selinux, const struct stat *statp, const struct timespec mt[], uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid); static int copy_hardlink (const struct path_info *dst, - unused bool reset_selinux, + MAYBE_UNUSED bool reset_selinux, struct link_name *lp); static int copy_special (const struct path_info *src, const struct path_info *dst, bool reset_selinux, @@ -93,7 +97,7 @@ static int fchown_if_needed (int fdst, const struct stat *statp, * error_acl - format the error messages for the ACL and EQ libraries. */ format_attr(printf, 2, 3) -static void error_acl (unused struct error_context *ctx, const char *fmt, ...) +static void error_acl (MAYBE_UNUSED struct error_context *ctx, const char *fmt, ...) { va_list ap; FILE *shadow_logfd = log_get_logfd(); @@ -206,11 +210,7 @@ static void remove_link (/*@only@*/struct link_name *ln) static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, const struct stat *sb) { - struct link_name *lp; - size_t src_len; - size_t dst_len; - size_t name_len; - size_t len; + struct link_name *lp; /* copy_tree () must be the entry point */ assert (NULL != src_orig); @@ -226,16 +226,11 @@ static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c return NULL; } - lp = (struct link_name *) xmalloc (sizeof *lp); - src_len = strlen (src_orig); - dst_len = strlen (dst_orig); - name_len = strlen (name); + lp = XMALLOC(1, struct link_name); lp->ln_dev = sb->st_dev; lp->ln_ino = sb->st_ino; lp->ln_count = sb->st_nlink; - len = name_len - src_len + dst_len + 1; - lp->ln_name = (char *) xmalloc (len); - (void) snprintf (lp->ln_name, len, "%s%s", dst_orig, name + src_len); + xasprintf(&lp->ln_name, "%s%s", dst_orig, name + strlen(src_orig)); lp->ln_next = links; links = lp; @@ -312,51 +307,43 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info * set_orig = true; } while ((0 == err) && (ent = readdir (dir)) != NULL) { + char *src_name = NULL; + char *dst_name; + struct path_info src_entry, dst_entry; /* * Skip the "." and ".." entries */ - if ((strcmp (ent->d_name, ".") != 0) && - (strcmp (ent->d_name, "..") != 0)) { - char *src_name; - char *dst_name; - size_t src_len = strlen (ent->d_name) + 2; - size_t dst_len = strlen (ent->d_name) + 2; - src_len += strlen (src->full_path); - dst_len += strlen (dst->full_path); - - src_name = (char *) malloc (src_len); - dst_name = (char *) malloc (dst_len); - - if ((NULL == src_name) || (NULL == dst_name)) { - err = -1; - } else { - /* - * Build the filename for both the source and - * the destination files. - */ - struct path_info src_entry, dst_entry; - - (void) snprintf (src_name, src_len, "%s/%s", - src->full_path, ent->d_name); - (void) snprintf (dst_name, dst_len, "%s/%s", - dst->full_path, ent->d_name); - - src_entry.full_path = src_name; - src_entry.dirfd = dirfd(dir); - src_entry.name = ent->d_name; - - dst_entry.full_path = dst_name; - dst_entry.dirfd = dst_fd; - dst_entry.name = ent->d_name; - - err = copy_entry (&src_entry, &dst_entry, - reset_selinux, - old_uid, new_uid, - old_gid, new_gid); - } - free (src_name); - free (dst_name); + if (strcmp(ent->d_name, ".") == 0 || + strcmp(ent->d_name, "..") == 0) + { + continue; + } + + if (asprintf(&src_name, "%s/%s", src->full_path, ent->d_name) == -1) + { + err = -1; + continue; + } + if (asprintf(&dst_name, "%s/%s", dst->full_path, ent->d_name) == -1) + { + err = -1; + goto skip; } + + src_entry.full_path = src_name; + src_entry.dirfd = dirfd(dir); + src_entry.name = ent->d_name; + + dst_entry.full_path = dst_name; + dst_entry.dirfd = dst_fd; + dst_entry.name = ent->d_name; + + err = copy_entry(&src_entry, &dst_entry, reset_selinux, + old_uid, new_uid, old_gid, new_gid); + + free(dst_name); +skip: + free(src_name); } (void) closedir (dir); (void) close (dst_fd); @@ -413,78 +400,70 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst, { int err = 0; struct stat sb; + struct stat tmp_sb; struct link_name *lp; struct timespec mt[2]; if (fstatat(src->dirfd, src->name, &sb, AT_SYMLINK_NOFOLLOW) == -1) { /* If we cannot stat the file, do not care. */ - } else { -#ifdef HAVE_STRUCT_STAT_ST_ATIM - mt[0].tv_sec = sb.st_atim.tv_sec; - mt[0].tv_nsec = sb.st_atim.tv_nsec; -#else /* !HAVE_STRUCT_STAT_ST_ATIM */ - mt[0].tv_sec = sb.st_atime; -# ifdef HAVE_STRUCT_STAT_ST_ATIMENSEC - mt[0].tv_nsec = sb.st_atimensec; -# else /* !HAVE_STRUCT_STAT_ST_ATIMENSEC */ - mt[0].tv_nsec = 0; -# endif /* !HAVE_STRUCT_STAT_ST_ATIMENSEC */ -#endif /* !HAVE_STRUCT_STAT_ST_ATIM */ - -#ifdef HAVE_STRUCT_STAT_ST_MTIM - mt[1].tv_sec = sb.st_mtim.tv_sec; - mt[1].tv_nsec = sb.st_mtim.tv_nsec; -#else /* !HAVE_STRUCT_STAT_ST_MTIM */ - mt[1].tv_sec = sb.st_mtime; -# ifdef HAVE_STRUCT_STAT_ST_MTIMENSEC - mt[1].tv_nsec = sb.st_mtimensec; -# else /* !HAVE_STRUCT_STAT_ST_MTIMENSEC */ - mt[1].tv_nsec = 0; -# endif /* !HAVE_STRUCT_STAT_ST_MTIMENSEC */ -#endif /* !HAVE_STRUCT_STAT_ST_MTIM */ - - if (S_ISDIR (sb.st_mode)) { - err = copy_dir (src, dst, reset_selinux, &sb, mt, - old_uid, new_uid, old_gid, new_gid); - } + return 0; + } - /* - * Copy any symbolic links - */ + mt[0].tv_sec = sb.st_atim.tv_sec; + mt[0].tv_nsec = sb.st_atim.tv_nsec; - else if (S_ISLNK (sb.st_mode)) { - err = copy_symlink (src, dst, reset_selinux, &sb, mt, - old_uid, new_uid, old_gid, new_gid); - } + mt[1].tv_sec = sb.st_mtim.tv_sec; + mt[1].tv_nsec = sb.st_mtim.tv_nsec; - /* - * See if this is a previously copied link - */ + if (S_ISDIR (sb.st_mode)) { + err = copy_dir (src, dst, reset_selinux, &sb, mt, + old_uid, new_uid, old_gid, new_gid); + } - else if ((lp = check_link (src->full_path, &sb)) != NULL) { - err = copy_hardlink (dst, reset_selinux, lp); - } + /* + * If the destination already exists do nothing. + * This is after the copy_dir above to still iterate into subdirectories. + */ + if (fstatat(dst->dirfd, dst->name, &tmp_sb, AT_SYMLINK_NOFOLLOW) != -1) { + return err; + } - /* - * Deal with FIFOs and special files. The user really - * shouldn't have any of these, but it seems like it - * would be nice to copy everything ... - */ + /* + * Copy any symbolic links + */ - else if (!S_ISREG (sb.st_mode)) { - err = copy_special (src, dst, reset_selinux, &sb, mt, - old_uid, new_uid, old_gid, new_gid); - } + else if (S_ISLNK (sb.st_mode)) { + err = copy_symlink (src, dst, reset_selinux, &sb, mt, + old_uid, new_uid, old_gid, new_gid); + } - /* - * Create the new file and copy the contents. The new - * file will be owned by the provided UID and GID values. - */ + /* + * See if this is a previously copied link + */ - else { - err = copy_file (src, dst, reset_selinux, &sb, mt, - old_uid, new_uid, old_gid, new_gid); - } + else if ((lp = check_link (src->full_path, &sb)) != NULL) { + err = copy_hardlink (dst, reset_selinux, lp); + } + + /* + * Deal with FIFOs and special files. The user really + * shouldn't have any of these, but it seems like it + * would be nice to copy everything ... + */ + + else if (!S_ISREG (sb.st_mode)) { + err = copy_special (src, dst, reset_selinux, &sb, mt, + old_uid, new_uid, old_gid, new_gid); + } + + /* + * Create the new file and copy the contents. The new + * file will be owned by the provided UID and GID values. + */ + + else { + err = copy_file (src, dst, reset_selinux, &sb, mt, + old_uid, new_uid, old_gid, new_gid); } return err; @@ -507,6 +486,7 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst, gid_t old_gid, gid_t new_gid) { int err = 0; + struct stat dst_sb; /* * Create a new target directory, make it owned by @@ -518,6 +498,15 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst, return -1; } #endif /* WITH_SELINUX */ + /* + * If the destination is already a directory, don't change it + * but copy into it (recursively). + */ + if (fstatat(dst->dirfd, dst->name, &dst_sb, AT_SYMLINK_NOFOLLOW) == 0 && S_ISDIR(dst_sb.st_mode)) { + return (copy_tree_impl (src, dst, false, reset_selinux, + old_uid, new_uid, old_gid, new_gid) != 0); + } + if ( (mkdirat (dst->dirfd, dst->name, 0700) != 0) || (chownat_if_needed (dst, statp, old_uid, new_uid, old_gid, new_gid) != 0) @@ -559,7 +548,7 @@ static /*@null@*/char *readlink_malloc (const char *filename) while (true) { ssize_t nchars; - char *buffer = (char *) malloc (size); + char *buffer = MALLOC(size, char); if (NULL == buffer) { return NULL; } @@ -594,7 +583,7 @@ static /*@null@*/char *readlink_malloc (const char *filename) * Return 0 on success, -1 on error. */ static int copy_symlink (const struct path_info *src, const struct path_info *dst, - unused bool reset_selinux, + MAYBE_UNUSED bool reset_selinux, const struct stat *statp, const struct timespec mt[], uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid) @@ -622,13 +611,11 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds * create a link to the corresponding entry in the dst_orig * directory. */ - if (strncmp (oldlink, src_orig, strlen (src_orig)) == 0) { - size_t len = strlen (dst_orig) + strlen (oldlink) - strlen (src_orig) + 1; - char *dummy = (char *) xmalloc (len); - (void) snprintf (dummy, len, "%s%s", - dst_orig, - oldlink + strlen (src_orig)); - free (oldlink); + if (strncmp(oldlink, src_orig, strlen(src_orig)) == 0) { + char *dummy; + + xasprintf(&dummy, "%s%s", dst_orig, oldlink + strlen(src_orig)); + free(oldlink); oldlink = dummy; } @@ -668,7 +655,7 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds * Return 0 on success, -1 on error. */ static int copy_hardlink (const struct path_info *dst, - unused bool reset_selinux, + MAYBE_UNUSED bool reset_selinux, struct link_name *lp) { /* FIXME: selinux, ACL, Extended Attributes needed? */ @@ -687,6 +674,7 @@ static int copy_hardlink (const struct path_info *dst, return 0; } + /* * copy_special - copy a special file * @@ -697,29 +685,33 @@ static int copy_hardlink (const struct path_info *dst, * * Return 0 on success, -1 on error. */ -static int copy_special (const struct path_info *src, const struct path_info *dst, - bool reset_selinux, - const struct stat *statp, const struct timespec mt[], - uid_t old_uid, uid_t new_uid, - gid_t old_gid, gid_t new_gid) +static int +copy_special(const struct path_info *src, const struct path_info *dst, + bool reset_selinux, + const struct stat *statp, const struct timespec mt[], + uid_t old_uid, uid_t new_uid, + gid_t old_gid, gid_t new_gid) { - int err = 0; +#if defined(WITH_SELINUX) + if (set_selinux_file_context(dst->full_path, statp->st_mode & S_IFMT) != 0) + return -1; +#endif -#ifdef WITH_SELINUX - if (set_selinux_file_context (dst->full_path, statp->st_mode & S_IFMT) != 0) { + if (mknodat(dst->dirfd, dst->name, statp->st_mode & ~07777U, statp->st_rdev) == -1) return -1; - } -#endif /* WITH_SELINUX */ - if ( (mknodat (dst->dirfd, dst->name, statp->st_mode & ~07777U, statp->st_rdev) != 0) - || (chownat_if_needed (dst, statp, - old_uid, new_uid, old_gid, new_gid) != 0) - || (fchmodat (dst->dirfd, dst->name, statp->st_mode & 07777, AT_SYMLINK_NOFOLLOW) != 0) -#ifdef WITH_ACL - || ( (perm_copy_path (src, dst, &ctx) != 0) - && (errno != 0)) -#endif /* WITH_ACL */ -#ifdef WITH_ATTR + if (chownat_if_needed(dst, statp, old_uid, new_uid, old_gid, new_gid) == -1) + return -1; + + if (fchmodat(dst->dirfd, dst->name, statp->st_mode & 07777, AT_SYMLINK_NOFOLLOW) == -1) + return -1; + +#if defined(WITH_ACL) + if (perm_copy_path(src, dst, &ctx) == -1 && errno != 0) + return -1; +#endif + +#if defined(WITH_ATTR) /* * If the third parameter is NULL, all extended attributes * except those that define Access Control Lists are copied. @@ -727,51 +719,16 @@ static int copy_special (const struct path_info *src, const struct path_info *ds * file systems with and without ACL support needs some * additional logic so that no unexpected permissions result. */ - || ( !reset_selinux - && (attr_copy_path (src, dst, NULL, &ctx) != 0) - && (errno != 0)) -#endif /* WITH_ATTR */ - || (utimensat (dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) != 0)) { - err = -1; + if (!reset_selinux) { + if (attr_copy_path(src, dst, NULL, &ctx) == -1 && errno != 0) + return -1; } +#endif - return err; -} - -/* - * full_write - write entire buffer - * - * Write up to count bytes from the buffer starting at buf to the - * file referred to by the file descriptor fd. - * Retry in case of a short write. - * - * Returns the number of bytes written on success, -1 on error. - */ -static ssize_t full_write(int fd, const void *buf, size_t count) { - ssize_t written = 0; - - while (count > 0) { - ssize_t res; - - res = write(fd, buf, count); - if (res < 0) { - if (errno == EINTR) { - continue; - } - - return res; - } - - if (res == 0) { - break; - } - - written += res; - buf = (const unsigned char*)buf + res; - count -= (size_t)res; - } + if (utimensat(dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) == -1) + return -1; - return written; + return 0; } /* @@ -850,7 +807,7 @@ static int copy_file (const struct path_info *src, const struct path_info *dst, break; } - if (full_write (ofd, buf, (size_t)cnt) < 0) { + if (write_full(ofd, buf, cnt) == -1) { (void) close (ofd); (void) close (ifd); return -1; @@ -858,7 +815,7 @@ static int copy_file (const struct path_info *src, const struct path_info *dst, } (void) close (ifd); - if (close (ofd) != 0) { + if (close (ofd) != 0 && errno != EINTR) { return -1; } diff --git a/libmisc/env.c b/lib/env.c index fc6dbce..9b5fd32 100644 --- a/libmisc/env.c +++ b/lib/env.c @@ -15,9 +15,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> + +#include "alloc.h" #include "prototypes.h" #include "defines.h" #include "shadowlog.h" +#include "string/sprintf.h" + + /* * NEWENVP_STEP must be a power of two. This is the number * of (char *) pointers to allocate at a time, to avoid using @@ -26,7 +31,6 @@ #define NEWENVP_STEP 16 size_t newenvc = 0; /*@null@*/char **newenvp = NULL; -extern char **environ; static const char *const forbid[] = { "_RLD_=", @@ -42,7 +46,7 @@ static const char *const forbid[] = { "PATH=", "SHELL=", "SHLIB_PATH=", - (char *) 0 + NULL }; /* these are allowed, but with no slashes inside @@ -51,7 +55,7 @@ static const char *const noslash[] = { "LANG=", "LANGUAGE=", "LC_", /* anything with the LC_ prefix */ - (char *) 0 + NULL }; /* @@ -59,23 +63,18 @@ static const char *const noslash[] = { */ void initenv (void) { - newenvp = (char **) xmalloc (NEWENVP_STEP * sizeof (char *)); + newenvp = XMALLOC(NEWENVP_STEP, char *); *newenvp = NULL; } void addenv (const char *string, /*@null@*/const char *value) { - char *cp, *newstring; - size_t i; - size_t n; + char *cp, *newstring; + size_t i, n; if (NULL != value) { - size_t len = strlen (string) + strlen (value) + 2; - int wlen; - newstring = xmalloc (len); - wlen = snprintf (newstring, len, "%s=%s", string, value); - assert (wlen == (int) len -1); + xasprintf(&newstring, "%s=%s", string, value); } else { newstring = xstrdup (string); } @@ -87,7 +86,7 @@ void addenv (const char *string, /*@null@*/const char *value) cp = strchr (newstring, '='); if (NULL == cp) { - free (newstring); + free(newstring); return; } @@ -104,7 +103,7 @@ void addenv (const char *string, /*@null@*/const char *value) } if (i < newenvc) { - free (newenvp[i]); + free(newenvp[i]); newenvp[i] = newstring; return; } @@ -127,32 +126,19 @@ void addenv (const char *string, /*@null@*/const char *value) */ if ((newenvc & (NEWENVP_STEP - 1)) == 0) { - char **__newenvp; - size_t newsize; + bool update_environ; + + update_environ = (environ == newenvp); + + newenvp = XREALLOC(newenvp, newenvc + NEWENVP_STEP, char *); /* - * If the resize operation succeeds we can - * happily go on, else print a message. + * If this is our current environment, update + * environ so that it doesn't point to some + * free memory area (realloc() could move it). */ - - newsize = (newenvc + NEWENVP_STEP) * sizeof (char *); - __newenvp = (char **) realloc (newenvp, newsize); - - if (NULL != __newenvp) { - /* - * If this is our current environment, update - * environ so that it doesn't point to some - * free memory area (realloc() could move it). - */ - if (environ == newenvp) { - environ = __newenvp; - } - newenvp = __newenvp; - } else { - (void) fputs (_("Environment overflow\n"), log_get_logfd()); - newenvc--; - free (newenvp[newenvc]); - } + if (update_environ) + environ = newenvp; } /* @@ -168,9 +154,9 @@ void addenv (const char *string, /*@null@*/const char *value) */ void set_env (int argc, char *const *argv) { - int noname = 1; - char variable[1024]; - char *cp; + int noname = 1; + char variable[1024]; + char *cp; for (; argc > 0; argc--, argv++) { if (strlen (*argv) >= sizeof variable) { @@ -179,9 +165,7 @@ void set_env (int argc, char *const *argv) cp = strchr (*argv, '='); if (NULL == cp) { - int wlen; - wlen = snprintf (variable, sizeof variable, "L%d", noname); - assert (wlen < (int) sizeof(variable)); + assert(SNPRINTF(variable, "L%d", noname) != -1); noname++; addenv (variable, *argv); } else { @@ -194,8 +178,7 @@ void set_env (int argc, char *const *argv) } if (NULL != *p) { - strncpy (variable, *argv, (size_t)(cp - *argv)); - variable[cp - *argv] = '\0'; + stpcpy(mempcpy(variable, *argv, (size_t)(cp - *argv)), ""); printf (_("You may not change $%s\n"), variable); continue; diff --git a/libmisc/failure.c b/lib/failure.c index 1aab299..e42e710 100644 --- a/libmisc/failure.c +++ b/lib/failure.c @@ -14,10 +14,16 @@ #include <fcntl.h> #include <stdio.h> #include <unistd.h> + #include "defines.h" #include "faillog.h" -#include "getdef.h" #include "failure.h" +#include "memzero.h" +#include "prototypes.h" +#include "string/strftime.h" +#include "string/strtcpy.h" + + #define YEAR (365L*DAY) /* * failure - make failure entry @@ -41,7 +47,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) fd = open (FAILLOG_FILE, O_RDWR); if (fd < 0) { SYSLOG ((LOG_WARN, - "Can't write faillog entry for UID %lu in %s.", + "Can't write faillog entry for UID %lu in %s: %m", (unsigned long) uid, FAILLOG_FILE)); return; } @@ -53,7 +59,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) */ if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (read (fd, (char *) fl, sizeof *fl) != (ssize_t) sizeof *fl)) { + || (read (fd, fl, sizeof *fl) != (ssize_t) sizeof *fl)) { /* This is not necessarily a failure. The file is * initially zero length. * @@ -75,7 +81,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) fl->fail_cnt++; } - strncpy (fl->fail_line, tty, sizeof (fl->fail_line) - 1); + STRTCPY(fl->fail_line, tty); (void) time (&fl->fail_time); /* @@ -86,13 +92,26 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) */ if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (write (fd, (char *) fl, sizeof *fl) != (ssize_t) sizeof *fl) - || (close (fd) != 0)) { - SYSLOG ((LOG_WARN, - "Can't write faillog entry for UID %lu in %s.", - (unsigned long) uid, FAILLOG_FILE)); + || (write_full(fd, fl, sizeof *fl) == -1)) { + goto err_write; + } + + if (close (fd) != 0 && errno != EINTR) { + goto err_close; + } + + return; + +err_write: + { + int saved_errno = errno; (void) close (fd); + errno = saved_errno; } +err_close: + SYSLOG ((LOG_WARN, + "Can't write faillog entry for UID %lu to %s: %m", + (unsigned long) uid, FAILLOG_FILE)); } static bool too_many_failures (const struct faillog *fl) @@ -144,7 +163,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) fd = open (FAILLOG_FILE, failed?O_RDONLY:O_RDWR); if (fd < 0) { SYSLOG ((LOG_WARN, - "Can't open the faillog file (%s) to check UID %lu. " + "Can't open the faillog file (%s) to check UID %lu: %m; " "User access authorized.", FAILLOG_FILE, (unsigned long) uid)); return 1; @@ -163,7 +182,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) */ if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (read (fd, (char *) fl, sizeof *fl) != (ssize_t) sizeof *fl)) { + || (read (fd, fl, sizeof *fl) != (ssize_t) sizeof *fl)) { (void) close (fd); return 1; } @@ -185,18 +204,30 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) fail.fail_cnt = 0; if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (write (fd, (const void *) &fail, sizeof fail) != (ssize_t) sizeof fail) - || (close (fd) != 0)) { - SYSLOG ((LOG_WARN, - "Can't reset faillog entry for UID %lu in %s.", - (unsigned long) uid, FAILLOG_FILE)); - (void) close (fd); + || (write_full(fd, &fail, sizeof fail) == -1)) { + goto err_write; + } + + if (close (fd) != 0 && errno != EINTR) { + goto err_close; } } else { (void) close (fd); } return 1; + +err_write: + { + int saved_errno = errno; + (void) close (fd); + errno = saved_errno; + } +err_close: + SYSLOG ((LOG_WARN, + "Can't reset faillog entry for UID %lu in %s: %m", + (unsigned long) uid, FAILLOG_FILE)); + return 1; } /* @@ -223,7 +254,7 @@ void failprint (const struct faillog *fail) /* * Print all information we have. */ - (void) strftime (lasttimeb, sizeof lasttimeb, "%c", tp); + STRFTIME(lasttimeb, "%c", tp); /*@-formatconst@*/ (void) printf (ngettext ("%d failure since last login.\n" @@ -234,62 +265,3 @@ void failprint (const struct faillog *fail) fail->fail_cnt, lasttime, fail->fail_line); /*@=formatconst@*/ } - -/* - * failtmp - update the cumulative failure log - * - * failtmp updates the (struct utmp) formatted failure log which - * maintains a record of all login failures. - */ - -void failtmp (const char *username, -#ifdef USE_UTMPX - const struct utmpx *failent -#else /* !USE_UTMPX */ - const struct utmp *failent -#endif /* !USE_UTMPX */ - ) -{ - const char *ftmp; - int fd; - - /* - * Get the name of the failure file. If no file has been defined - * in login.defs, don't do this. - */ - - ftmp = getdef_str ("FTMP_FILE"); - if (NULL == ftmp) { - return; - } - - /* - * Open the file for append. It must already exist for this - * feature to be used. - */ - - if (access (ftmp, F_OK) != 0) { - return; - } - - fd = open (ftmp, O_WRONLY | O_APPEND); - if (-1 == fd) { - SYSLOG ((LOG_WARN, - "Can't append failure of user %s to %s.", - username, ftmp)); - return; - } - - /* - * Append the new failure record and close the log file. - */ - - if ( (write (fd, (const void *) failent, sizeof *failent) != (ssize_t) sizeof *failent) - || (close (fd) != 0)) { - SYSLOG ((LOG_WARN, - "Can't append failure of user %s to %s.", - username, ftmp)); - (void) close (fd); - } -} - diff --git a/libmisc/failure.h b/lib/failure.h index 2ac30d7..1352b68 100644 --- a/libmisc/failure.h +++ b/lib/failure.h @@ -13,11 +13,6 @@ #include "defines.h" #include "faillog.h" -#ifdef USE_UTMPX -#include <utmpx.h> -#else /* !USE_UTMPX */ -#include <utmp.h> -#endif /* !USE_UTMPX */ /* * failure - make failure entry @@ -45,17 +40,5 @@ extern int failcheck (uid_t uid, struct faillog *fl, bool failed); */ extern void failprint (const struct faillog *); -/* - * failtmp - update the cumulative failure log - * - * failtmp updates the (struct utmp) formatted failure log which - * maintains a record of all login failures. - */ -#ifdef USE_UTMPX -extern void failtmp (const char *username, const struct utmpx *); -#else /* !USE_UTMPX */ -extern void failtmp (const char *username, const struct utmp *); -#endif /* !USE_UTMPX */ - #endif diff --git a/libmisc/find_new_gid.c b/lib/find_new_gid.c index 65ab5d0..cfd5609 100644 --- a/libmisc/find_new_gid.c +++ b/lib/find_new_gid.c @@ -12,6 +12,7 @@ #include <stdio.h> #include <errno.h> +#include "alloc.h" #include "prototypes.h" #include "groupio.h" #include "getdef.h" @@ -40,15 +41,14 @@ static int get_ranges (bool sys_group, gid_t *min_id, gid_t *max_id, *preferred_min = (gid_t) 1; /* Get the minimum ID range from login.defs or default to 101 */ - *min_id = (gid_t) getdef_ulong ("SYS_GID_MIN", 101UL); + *min_id = getdef_ulong ("SYS_GID_MIN", 101UL); /* * If SYS_GID_MAX is unspecified, we should assume it to be one * less than the GID_MIN (which is reserved for non-system accounts) */ - gid_def_max = (gid_t) getdef_ulong ("GID_MIN", 1000UL) - 1; - *max_id = (gid_t) getdef_ulong ("SYS_GID_MAX", - (unsigned long) gid_def_max); + gid_def_max = getdef_ulong ("GID_MIN", 1000UL) - 1; + *max_id = getdef_ulong ("SYS_GID_MAX", gid_def_max); /* Check that the ranges make sense */ if (*max_id < *min_id) { @@ -71,8 +71,8 @@ static int get_ranges (bool sys_group, gid_t *min_id, gid_t *max_id, /* Non-system groups */ /* Get the values from login.defs or use reasonable defaults */ - *min_id = (gid_t) getdef_ulong ("GID_MIN", 1000UL); - *max_id = (gid_t) getdef_ulong ("GID_MAX", 60000UL); + *min_id = getdef_ulong ("GID_MIN", 1000UL); + *max_id = getdef_ulong ("GID_MAX", 60000UL); /* * The preferred minimum should match the standard ID minimum @@ -99,6 +99,7 @@ static int get_ranges (bool sys_group, gid_t *min_id, gid_t *max_id, * * On success, return 0 * If the ID is in use, return EEXIST + * If the ID might clash with -1, return EINVAL * If the ID is outside the range, return ERANGE * In other cases, return errno from getgrgid() */ @@ -112,6 +113,11 @@ static int check_gid (const gid_t gid, return ERANGE; } + /* Check for compatibility with 16b and 32b gid_t error codes */ + if (gid == UINT16_MAX || gid == UINT32_MAX) { + return EINVAL; + } + /* * Check whether we already detected this GID * using the gr_next() loop @@ -183,10 +189,10 @@ int find_new_gid (bool sys_group, * gr_locate_gid() found the GID in an as-yet uncommitted * entry. We'll proceed below and auto-set a GID. */ - } else if (result == EEXIST || result == ERANGE) { + } else if (result == EEXIST || result == ERANGE || result == EINVAL) { /* * Continue on below. At this time, we won't - * treat these two cases differently. + * treat these three cases differently. */ } else { /* @@ -226,14 +232,13 @@ int find_new_gid (bool sys_group, */ /* Create an array to hold all of the discovered GIDs */ - used_gids = malloc (sizeof (bool) * (gid_max +1)); + used_gids = CALLOC (gid_max + 1, bool); if (NULL == used_gids) { fprintf (log_get_logfd(), _("%s: failed to allocate memory: %s\n"), log_get_progname(), strerror (errno)); return -1; } - memset (used_gids, false, sizeof (bool) * (gid_max + 1)); /* First look for the lowest and highest value in the local database */ (void) gr_rewind (); @@ -297,8 +302,11 @@ int find_new_gid (bool sys_group, *gid = id; free (used_gids); return 0; - } else if (result == EEXIST) { - /* This GID is in use, we'll continue to the next */ + } else if (result == EEXIST || result == EINVAL) { + /* + * This GID is in use or unusable, we'll + * continue to the next. + */ } else { /* * An unexpected error occurred. @@ -340,8 +348,11 @@ int find_new_gid (bool sys_group, *gid = id; free (used_gids); return 0; - } else if (result == EEXIST) { - /* This GID is in use, we'll continue to the next */ + } else if (result == EEXIST || result == EINVAL) { + /* + * This GID is in use or unusable, we'll + * continue to the next. + */ } else { /* * An unexpected error occurred. @@ -400,8 +411,11 @@ int find_new_gid (bool sys_group, *gid = id; free (used_gids); return 0; - } else if (result == EEXIST) { - /* This GID is in use, we'll continue to the next */ + } else if (result == EEXIST || result == EINVAL) { + /* + * This GID is in use or unusable, we'll + * continue to the next. + */ } else { /* * An unexpected error occurred. @@ -443,8 +457,11 @@ int find_new_gid (bool sys_group, *gid = id; free (used_gids); return 0; - } else if (result == EEXIST) { - /* This GID is in use, we'll continue to the next */ + } else if (result == EEXIST || result == EINVAL) { + /* + * This GID is in use or unusable, we'll + * continue to the next. + */ } else { /* * An unexpected error occurred. diff --git a/libmisc/find_new_sub_gids.c b/lib/find_new_sub_gids.c index bbd4570..74c9d8f 100644 --- a/libmisc/find_new_sub_gids.c +++ b/lib/find_new_sub_gids.c @@ -59,6 +59,6 @@ int find_new_sub_gids (gid_t *range_start, unsigned long *range_count) return 0; } #else /* !ENABLE_SUBIDS */ -extern int errno; /* warning: ANSI C forbids an empty source file */ +extern int ISO_C_forbids_an_empty_translation_unit; #endif /* !ENABLE_SUBIDS */ diff --git a/libmisc/find_new_sub_uids.c b/lib/find_new_sub_uids.c index a86b311..cc4b0cf 100644 --- a/libmisc/find_new_sub_uids.c +++ b/lib/find_new_sub_uids.c @@ -59,6 +59,6 @@ int find_new_sub_uids (uid_t *range_start, unsigned long *range_count) return 0; } #else /* !ENABLE_SUBIDS */ -extern int errno; /* warning: ANSI C forbids an empty source file */ +extern int ISO_C_forbids_an_empty_translation_unit; #endif /* !ENABLE_SUBIDS */ diff --git a/libmisc/find_new_uid.c b/lib/find_new_uid.c index 5f7e74b..45ce712 100644 --- a/libmisc/find_new_uid.c +++ b/lib/find_new_uid.c @@ -12,6 +12,7 @@ #include <stdio.h> #include <errno.h> +#include "alloc.h" #include "prototypes.h" #include "pwio.h" #include "getdef.h" @@ -40,15 +41,14 @@ static int get_ranges (bool sys_user, uid_t *min_id, uid_t *max_id, *preferred_min = (uid_t) 1; /* Get the minimum ID range from login.defs or default to 101 */ - *min_id = (uid_t) getdef_ulong ("SYS_UID_MIN", 101UL); + *min_id = getdef_ulong ("SYS_UID_MIN", 101UL); /* * If SYS_UID_MAX is unspecified, we should assume it to be one * less than the UID_MIN (which is reserved for non-system accounts) */ - uid_def_max = (uid_t) getdef_ulong ("UID_MIN", 1000UL) - 1; - *max_id = (uid_t) getdef_ulong ("SYS_UID_MAX", - (unsigned long) uid_def_max); + uid_def_max = getdef_ulong ("UID_MIN", 1000UL) - 1; + *max_id = getdef_ulong ("SYS_UID_MAX", uid_def_max); /* Check that the ranges make sense */ if (*max_id < *min_id) { @@ -71,8 +71,8 @@ static int get_ranges (bool sys_user, uid_t *min_id, uid_t *max_id, /* Non-system users */ /* Get the values from login.defs or use reasonable defaults */ - *min_id = (uid_t) getdef_ulong ("UID_MIN", 1000UL); - *max_id = (uid_t) getdef_ulong ("UID_MAX", 60000UL); + *min_id = getdef_ulong ("UID_MIN", 1000UL); + *max_id = getdef_ulong ("UID_MAX", 60000UL); /* * The preferred minimum should match the standard ID minimum @@ -99,6 +99,7 @@ static int get_ranges (bool sys_user, uid_t *min_id, uid_t *max_id, * * On success, return 0 * If the ID is in use, return EEXIST + * If the ID might clash with -1, return EINVAL * If the ID is outside the range, return ERANGE * In other cases, return errno from getpwuid() */ @@ -112,6 +113,11 @@ static int check_uid(const uid_t uid, return ERANGE; } + /* Check for compatibility with 16b and 32b uid_t error codes */ + if (uid == UINT16_MAX || uid == UINT32_MAX) { + return EINVAL; + } + /* * Check whether we already detected this UID * using the pw_next() loop @@ -183,10 +189,10 @@ int find_new_uid(bool sys_user, * pw_locate_uid() found the UID in an as-yet uncommitted * entry. We'll proceed below and auto-set an UID. */ - } else if (result == EEXIST || result == ERANGE) { + } else if (result == EEXIST || result == ERANGE || result == EINVAL) { /* * Continue on below. At this time, we won't - * treat these two cases differently. + * treat these three cases differently. */ } else { /* @@ -226,14 +232,13 @@ int find_new_uid(bool sys_user, */ /* Create an array to hold all of the discovered UIDs */ - used_uids = malloc (sizeof (bool) * (uid_max +1)); + used_uids = CALLOC(uid_max + 1, bool); if (NULL == used_uids) { fprintf (log_get_logfd(), _("%s: failed to allocate memory: %s\n"), log_get_progname(), strerror (errno)); return -1; } - memset (used_uids, false, sizeof (bool) * (uid_max + 1)); /* First look for the lowest and highest value in the local database */ (void) pw_rewind (); @@ -297,8 +302,11 @@ int find_new_uid(bool sys_user, *uid = id; free (used_uids); return 0; - } else if (result == EEXIST) { - /* This UID is in use, we'll continue to the next */ + } else if (result == EEXIST || result == EINVAL) { + /* + * This GID is in use or unusable, we'll + * continue to the next. + */ } else { /* * An unexpected error occurred. @@ -340,8 +348,11 @@ int find_new_uid(bool sys_user, *uid = id; free (used_uids); return 0; - } else if (result == EEXIST) { - /* This UID is in use, we'll continue to the next */ + } else if (result == EEXIST || result == EINVAL) { + /* + * This GID is in use or unusable, we'll + * continue to the next. + */ } else { /* * An unexpected error occurred. @@ -400,8 +411,11 @@ int find_new_uid(bool sys_user, *uid = id; free (used_uids); return 0; - } else if (result == EEXIST) { - /* This UID is in use, we'll continue to the next */ + } else if (result == EEXIST || result == EINVAL) { + /* + * This GID is in use or unusable, we'll + * continue to the next. + */ } else { /* * An unexpected error occurred. @@ -443,8 +457,11 @@ int find_new_uid(bool sys_user, *uid = id; free (used_uids); return 0; - } else if (result == EEXIST) { - /* This UID is in use, we'll continue to the next */ + } else if (result == EEXIST || result == EINVAL) { + /* + * This GID is in use or unusable, we'll + * continue to the next. + */ } else { /* * An unexpected error occurred. diff --git a/libmisc/getdate.c b/lib/getdate.c index fc17c18..556ce62 100644 --- a/libmisc/getdate.c +++ b/lib/getdate.c @@ -82,9 +82,6 @@ #ifdef HAVE_CONFIG_H # include <config.h> -# ifdef FORCE_ALLOCA_H -# include <alloca.h> -# endif #endif /* Since the code of getdate.y is not included in the Emacs executable @@ -101,6 +98,7 @@ #include <ctype.h> #include <time.h> +#include "attr.h" #include "getdate.h" #include <string.h> @@ -215,7 +213,7 @@ static int yyRelSeconds; static int yyRelYear; -#line 219 "getdate.c" +#line 217 "getdate.c" # ifndef YY_CAST # ifdef __cplusplus @@ -301,12 +299,12 @@ extern int yydebug; #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED union YYSTYPE { -#line 149 "getdate.y" +#line 147 "getdate.y" int Number; enum _MERIDIAN Meridian; -#line 310 "getdate.c" +#line 308 "getdate.c" }; typedef union YYSTYPE YYSTYPE; @@ -746,12 +744,12 @@ static const yytype_int8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_int16 yyrline[] = { - 0, 165, 165, 166, 169, 172, 175, 178, 181, 184, - 187, 193, 199, 208, 214, 226, 229, 233, 238, 242, - 246, 252, 256, 274, 280, 286, 290, 295, 299, 306, - 314, 317, 320, 323, 326, 329, 332, 335, 338, 341, - 344, 347, 350, 353, 356, 359, 362, 365, 368, 373, - 407, 410 + 0, 163, 163, 164, 167, 170, 173, 176, 179, 182, + 185, 191, 197, 206, 212, 224, 227, 231, 236, 240, + 244, 250, 254, 272, 278, 284, 288, 293, 297, 304, + 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, + 342, 345, 348, 351, 354, 357, 360, 363, 366, 371, + 405, 408 }; #endif @@ -1352,69 +1350,69 @@ yyreduce: switch (yyn) { case 4: /* item: time */ -#line 169 "getdate.y" +#line 167 "getdate.y" { yyHaveTime++; } -#line 1360 "getdate.c" +#line 1358 "getdate.c" break; case 5: /* item: zone */ -#line 172 "getdate.y" +#line 170 "getdate.y" { yyHaveZone++; } -#line 1368 "getdate.c" +#line 1366 "getdate.c" break; case 6: /* item: date */ -#line 175 "getdate.y" +#line 173 "getdate.y" { yyHaveDate++; } -#line 1376 "getdate.c" +#line 1374 "getdate.c" break; case 7: /* item: day */ -#line 178 "getdate.y" +#line 176 "getdate.y" { yyHaveDay++; } -#line 1384 "getdate.c" +#line 1382 "getdate.c" break; case 8: /* item: rel */ -#line 181 "getdate.y" +#line 179 "getdate.y" { yyHaveRel++; } -#line 1392 "getdate.c" +#line 1390 "getdate.c" break; case 10: /* time: tUNUMBER tMERIDIAN */ -#line 187 "getdate.y" +#line 185 "getdate.y" { yyHour = (yyvsp[-1].Number); yyMinutes = 0; yySeconds = 0; yyMeridian = (yyvsp[0].Meridian); } -#line 1403 "getdate.c" +#line 1401 "getdate.c" break; case 11: /* time: tUNUMBER ':' tUNUMBER o_merid */ -#line 193 "getdate.y" +#line 191 "getdate.y" { yyHour = (yyvsp[-3].Number); yyMinutes = (yyvsp[-1].Number); yySeconds = 0; yyMeridian = (yyvsp[0].Meridian); } -#line 1414 "getdate.c" +#line 1412 "getdate.c" break; case 12: /* time: tUNUMBER ':' tUNUMBER tSNUMBER */ -#line 199 "getdate.y" +#line 197 "getdate.y" { yyHour = (yyvsp[-3].Number); yyMinutes = (yyvsp[-1].Number); @@ -1424,22 +1422,22 @@ yyreduce: ? -(yyvsp[0].Number) % 100 + (-(yyvsp[0].Number) / 100) * 60 : - ((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60)); } -#line 1428 "getdate.c" +#line 1426 "getdate.c" break; case 13: /* time: tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid */ -#line 208 "getdate.y" +#line 206 "getdate.y" { yyHour = (yyvsp[-5].Number); yyMinutes = (yyvsp[-3].Number); yySeconds = (yyvsp[-1].Number); yyMeridian = (yyvsp[0].Meridian); } -#line 1439 "getdate.c" +#line 1437 "getdate.c" break; case 14: /* time: tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER */ -#line 214 "getdate.y" +#line 212 "getdate.y" { yyHour = (yyvsp[-5].Number); yyMinutes = (yyvsp[-3].Number); @@ -1450,71 +1448,71 @@ yyreduce: ? -(yyvsp[0].Number) % 100 + (-(yyvsp[0].Number) / 100) * 60 : - ((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60)); } -#line 1454 "getdate.c" +#line 1452 "getdate.c" break; case 15: /* zone: tZONE */ -#line 226 "getdate.y" +#line 224 "getdate.y" { yyTimezone = (yyvsp[0].Number); } -#line 1462 "getdate.c" +#line 1460 "getdate.c" break; case 16: /* zone: tDAYZONE */ -#line 229 "getdate.y" +#line 227 "getdate.y" { yyTimezone = (yyvsp[0].Number) - 60; } -#line 1470 "getdate.c" +#line 1468 "getdate.c" break; case 17: /* zone: tZONE tDST */ -#line 233 "getdate.y" +#line 231 "getdate.y" { yyTimezone = (yyvsp[-1].Number) - 60; } -#line 1478 "getdate.c" +#line 1476 "getdate.c" break; case 18: /* day: tDAY */ -#line 238 "getdate.y" +#line 236 "getdate.y" { yyDayOrdinal = 1; yyDayNumber = (yyvsp[0].Number); } -#line 1487 "getdate.c" +#line 1485 "getdate.c" break; case 19: /* day: tDAY ',' */ -#line 242 "getdate.y" +#line 240 "getdate.y" { yyDayOrdinal = 1; yyDayNumber = (yyvsp[-1].Number); } -#line 1496 "getdate.c" +#line 1494 "getdate.c" break; case 20: /* day: tUNUMBER tDAY */ -#line 246 "getdate.y" +#line 244 "getdate.y" { yyDayOrdinal = (yyvsp[-1].Number); yyDayNumber = (yyvsp[0].Number); } -#line 1505 "getdate.c" +#line 1503 "getdate.c" break; case 21: /* date: tUNUMBER '/' tUNUMBER */ -#line 252 "getdate.y" +#line 250 "getdate.y" { yyMonth = (yyvsp[-2].Number); yyDay = (yyvsp[0].Number); } -#line 1514 "getdate.c" +#line 1512 "getdate.c" break; case 22: /* date: tUNUMBER '/' tUNUMBER '/' tUNUMBER */ -#line 256 "getdate.y" +#line 254 "getdate.y" { /* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY. The goal in recognizing YYYY/MM/DD is solely to support legacy @@ -1533,71 +1531,71 @@ yyreduce: yyYear = (yyvsp[0].Number); } } -#line 1537 "getdate.c" +#line 1535 "getdate.c" break; case 23: /* date: tUNUMBER tSNUMBER tSNUMBER */ -#line 274 "getdate.y" +#line 272 "getdate.y" { /* ISO 8601 format. yyyy-mm-dd. */ yyYear = (yyvsp[-2].Number); yyMonth = -(yyvsp[-1].Number); yyDay = -(yyvsp[0].Number); } -#line 1548 "getdate.c" +#line 1546 "getdate.c" break; case 24: /* date: tUNUMBER tMONTH tSNUMBER */ -#line 280 "getdate.y" +#line 278 "getdate.y" { /* e.g. 17-JUN-1992. */ yyDay = (yyvsp[-2].Number); yyMonth = (yyvsp[-1].Number); yyYear = -(yyvsp[0].Number); } -#line 1559 "getdate.c" +#line 1557 "getdate.c" break; case 25: /* date: tMONTH tUNUMBER */ -#line 286 "getdate.y" +#line 284 "getdate.y" { yyMonth = (yyvsp[-1].Number); yyDay = (yyvsp[0].Number); } -#line 1568 "getdate.c" +#line 1566 "getdate.c" break; case 26: /* date: tMONTH tUNUMBER ',' tUNUMBER */ -#line 290 "getdate.y" +#line 288 "getdate.y" { yyMonth = (yyvsp[-3].Number); yyDay = (yyvsp[-2].Number); yyYear = (yyvsp[0].Number); } -#line 1578 "getdate.c" +#line 1576 "getdate.c" break; case 27: /* date: tUNUMBER tMONTH */ -#line 295 "getdate.y" +#line 293 "getdate.y" { yyMonth = (yyvsp[0].Number); yyDay = (yyvsp[-1].Number); } -#line 1587 "getdate.c" +#line 1585 "getdate.c" break; case 28: /* date: tUNUMBER tMONTH tUNUMBER */ -#line 299 "getdate.y" +#line 297 "getdate.y" { yyMonth = (yyvsp[-1].Number); yyDay = (yyvsp[-2].Number); yyYear = (yyvsp[0].Number); } -#line 1597 "getdate.c" +#line 1595 "getdate.c" break; case 29: /* rel: relunit tAGO */ -#line 306 "getdate.y" +#line 304 "getdate.y" { yyRelSeconds = -yyRelSeconds; yyRelMinutes = -yyRelMinutes; @@ -1606,155 +1604,155 @@ yyreduce: yyRelMonth = -yyRelMonth; yyRelYear = -yyRelYear; } -#line 1610 "getdate.c" +#line 1608 "getdate.c" break; case 31: /* relunit: tUNUMBER tYEAR_UNIT */ -#line 317 "getdate.y" +#line 315 "getdate.y" { yyRelYear += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1618 "getdate.c" +#line 1616 "getdate.c" break; case 32: /* relunit: tSNUMBER tYEAR_UNIT */ -#line 320 "getdate.y" +#line 318 "getdate.y" { yyRelYear += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1626 "getdate.c" +#line 1624 "getdate.c" break; case 33: /* relunit: tYEAR_UNIT */ -#line 323 "getdate.y" +#line 321 "getdate.y" { - yyRelYear++; + yyRelYear += (yyvsp[0].Number); } -#line 1634 "getdate.c" +#line 1632 "getdate.c" break; case 34: /* relunit: tUNUMBER tMONTH_UNIT */ -#line 326 "getdate.y" +#line 324 "getdate.y" { yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1642 "getdate.c" +#line 1640 "getdate.c" break; case 35: /* relunit: tSNUMBER tMONTH_UNIT */ -#line 329 "getdate.y" +#line 327 "getdate.y" { yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1650 "getdate.c" +#line 1648 "getdate.c" break; case 36: /* relunit: tMONTH_UNIT */ -#line 332 "getdate.y" +#line 330 "getdate.y" { - yyRelMonth++; + yyRelMonth += (yyvsp[0].Number); } -#line 1658 "getdate.c" +#line 1656 "getdate.c" break; case 37: /* relunit: tUNUMBER tDAY_UNIT */ -#line 335 "getdate.y" +#line 333 "getdate.y" { yyRelDay += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1666 "getdate.c" +#line 1664 "getdate.c" break; case 38: /* relunit: tSNUMBER tDAY_UNIT */ -#line 338 "getdate.y" +#line 336 "getdate.y" { yyRelDay += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1674 "getdate.c" +#line 1672 "getdate.c" break; case 39: /* relunit: tDAY_UNIT */ -#line 341 "getdate.y" +#line 339 "getdate.y" { - yyRelDay++; + yyRelDay += (yyvsp[0].Number); } -#line 1682 "getdate.c" +#line 1680 "getdate.c" break; case 40: /* relunit: tUNUMBER tHOUR_UNIT */ -#line 344 "getdate.y" +#line 342 "getdate.y" { yyRelHour += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1690 "getdate.c" +#line 1688 "getdate.c" break; case 41: /* relunit: tSNUMBER tHOUR_UNIT */ -#line 347 "getdate.y" +#line 345 "getdate.y" { yyRelHour += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1698 "getdate.c" +#line 1696 "getdate.c" break; case 42: /* relunit: tHOUR_UNIT */ -#line 350 "getdate.y" +#line 348 "getdate.y" { - yyRelHour++; + yyRelHour += (yyvsp[0].Number); } -#line 1706 "getdate.c" +#line 1704 "getdate.c" break; case 43: /* relunit: tUNUMBER tMINUTE_UNIT */ -#line 353 "getdate.y" +#line 351 "getdate.y" { yyRelMinutes += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1714 "getdate.c" +#line 1712 "getdate.c" break; case 44: /* relunit: tSNUMBER tMINUTE_UNIT */ -#line 356 "getdate.y" +#line 354 "getdate.y" { yyRelMinutes += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1722 "getdate.c" +#line 1720 "getdate.c" break; case 45: /* relunit: tMINUTE_UNIT */ -#line 359 "getdate.y" +#line 357 "getdate.y" { - yyRelMinutes++; + yyRelMinutes += (yyvsp[0].Number); } -#line 1730 "getdate.c" +#line 1728 "getdate.c" break; case 46: /* relunit: tUNUMBER tSEC_UNIT */ -#line 362 "getdate.y" +#line 360 "getdate.y" { yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1738 "getdate.c" +#line 1736 "getdate.c" break; case 47: /* relunit: tSNUMBER tSEC_UNIT */ -#line 365 "getdate.y" +#line 363 "getdate.y" { yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number); } -#line 1746 "getdate.c" +#line 1744 "getdate.c" break; case 48: /* relunit: tSEC_UNIT */ -#line 368 "getdate.y" +#line 366 "getdate.y" { - yyRelSeconds++; + yyRelSeconds += (yyvsp[0].Number); } -#line 1754 "getdate.c" +#line 1752 "getdate.c" break; case 49: /* number: tUNUMBER */ -#line 374 "getdate.y" +#line 372 "getdate.y" { if ((yyHaveTime != 0) && (yyHaveDate != 0) && (yyHaveRel == 0)) yyYear = (yyvsp[0].Number); @@ -1785,27 +1783,27 @@ yyreduce: } } } -#line 1789 "getdate.c" +#line 1787 "getdate.c" break; case 50: /* o_merid: %empty */ -#line 407 "getdate.y" +#line 405 "getdate.y" { (yyval.Meridian) = MER24; } -#line 1797 "getdate.c" +#line 1795 "getdate.c" break; case 51: /* o_merid: tMERIDIAN */ -#line 411 "getdate.y" +#line 409 "getdate.y" { (yyval.Meridian) = (yyvsp[0].Meridian); } -#line 1805 "getdate.c" +#line 1803 "getdate.c" break; -#line 1809 "getdate.c" +#line 1807 "getdate.c" default: break; } @@ -1998,7 +1996,7 @@ yyreturnlab: return yyresult; } -#line 416 "getdate.y" +#line 414 "getdate.y" /* Month and day table. */ @@ -2158,7 +2156,7 @@ static TABLE const MilitaryTable[] = { -static int yyerror (unused const char *s) +static int yyerror (MAYBE_UNUSED const char *s) { return 0; } @@ -2511,11 +2509,8 @@ time_t get_date (const char *p, const time_t *now) #if defined (TEST) -/* ARGSUSED */ int -main (ac, av) - int ac; - char *av[]; +main(void) { char buff[MAX_BUFF_LEN + 1]; time_t d; diff --git a/libmisc/getdate.h b/lib/getdate.h index eae56f6..eae56f6 100644 --- a/libmisc/getdate.h +++ b/lib/getdate.h diff --git a/libmisc/getdate.y b/lib/getdate.y index 0c07f74..8cea2cc 100644 --- a/libmisc/getdate.y +++ b/lib/getdate.y @@ -12,9 +12,6 @@ #ifdef HAVE_CONFIG_H # include <config.h> -# ifdef FORCE_ALLOCA_H -# include <alloca.h> -# endif #endif /* Since the code of getdate.y is not included in the Emacs executable @@ -31,6 +28,7 @@ #include <ctype.h> #include <time.h> +#include "attr.h" #include "getdate.h" #include <string.h> @@ -321,7 +319,7 @@ relunit : tUNUMBER tYEAR_UNIT { yyRelYear += $1 * $2; } | tYEAR_UNIT { - yyRelYear++; + yyRelYear += $1; } | tUNUMBER tMONTH_UNIT { yyRelMonth += $1 * $2; @@ -330,7 +328,7 @@ relunit : tUNUMBER tYEAR_UNIT { yyRelMonth += $1 * $2; } | tMONTH_UNIT { - yyRelMonth++; + yyRelMonth += $1; } | tUNUMBER tDAY_UNIT { yyRelDay += $1 * $2; @@ -339,7 +337,7 @@ relunit : tUNUMBER tYEAR_UNIT { yyRelDay += $1 * $2; } | tDAY_UNIT { - yyRelDay++; + yyRelDay += $1; } | tUNUMBER tHOUR_UNIT { yyRelHour += $1 * $2; @@ -348,7 +346,7 @@ relunit : tUNUMBER tYEAR_UNIT { yyRelHour += $1 * $2; } | tHOUR_UNIT { - yyRelHour++; + yyRelHour += $1; } | tUNUMBER tMINUTE_UNIT { yyRelMinutes += $1 * $2; @@ -357,7 +355,7 @@ relunit : tUNUMBER tYEAR_UNIT { yyRelMinutes += $1 * $2; } | tMINUTE_UNIT { - yyRelMinutes++; + yyRelMinutes += $1; } | tUNUMBER tSEC_UNIT { yyRelSeconds += $1 * $2; @@ -366,7 +364,7 @@ relunit : tUNUMBER tYEAR_UNIT { yyRelSeconds += $1 * $2; } | tSEC_UNIT { - yyRelSeconds++; + yyRelSeconds += $1; } ; @@ -572,7 +570,7 @@ static TABLE const MilitaryTable[] = { -static int yyerror (unused const char *s) +static int yyerror (MAYBE_UNUSED const char *s) { return 0; } @@ -925,11 +923,8 @@ time_t get_date (const char *p, const time_t *now) #if defined (TEST) -/* ARGSUSED */ int -main (ac, av) - int ac; - char *av[]; +main(void) { char buff[MAX_BUFF_LEN + 1]; time_t d; diff --git a/libmisc/getgr_nam_gid.c b/lib/getgr_nam_gid.c index 5294f50..fd0c217 100644 --- a/libmisc/getgr_nam_gid.c +++ b/lib/getgr_nam_gid.c @@ -23,20 +23,20 @@ */ extern /*@only@*//*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname) { - long long int gid; - char *endptr; + char *end; + long long gid; if (NULL == grname) { return NULL; } errno = 0; - gid = strtoll (grname, &endptr, 10); + gid = strtoll(grname, &end, 10); if ( ('\0' != *grname) - && ('\0' == *endptr) - && (ERANGE != errno) + && ('\0' == *end) + && (0 == errno) && (/*@+longintegral@*/gid == (gid_t)gid)/*@=longintegral@*/) { - return xgetgrgid ((gid_t) gid); + return xgetgrgid (gid); } return xgetgrnam (grname); } diff --git a/libmisc/hushed.c b/lib/hushed.c index 84b2f55..86c224f 100644 --- a/libmisc/hushed.c +++ b/lib/hushed.c @@ -18,6 +18,9 @@ #include "defines.h" #include "prototypes.h" #include "getdef.h" +#include "string/sprintf.h" + + /* * hushed - determine if a user receives login messages * @@ -26,11 +29,11 @@ */ bool hushed (const char *username) { - struct passwd *pw; - const char *hushfile; - char buf[BUFSIZ]; - bool found; - FILE *fp; + bool found; + char buf[BUFSIZ]; + FILE *fp; + const char *hushfile; + struct passwd *pw; /* * Get the name of the file to use. If this option is not @@ -53,7 +56,7 @@ bool hushed (const char *username) */ if (hushfile[0] != '/') { - (void) snprintf (buf, sizeof (buf), "%s/%s", pw->pw_dir, hushfile); + SNPRINTF(buf, "%s/%s", pw->pw_dir, hushfile); return (access (buf, F_OK) == 0); } @@ -66,7 +69,7 @@ bool hushed (const char *username) if (NULL == fp) { return false; } - for (found = false; !found && (fgets (buf, (int) sizeof buf, fp) == buf);) { + for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) { buf[strcspn (buf, "\n")] = '\0'; found = (strcmp (buf, pw->pw_shell) == 0) || (strcmp (buf, pw->pw_name) == 0); diff --git a/libmisc/idmapping.c b/lib/idmapping.c index 30eb89f..56c72ea 100644 --- a/libmisc/idmapping.c +++ b/lib/idmapping.c @@ -11,13 +11,20 @@ #include <limits.h> #include <stdlib.h> #include <stdio.h> +#include <strings.h> + +#include "alloc.h" +#include "atoi/str2i.h" #include "prototypes.h" +#include "string/stpeprintf.h" #include "idmapping.h" #if HAVE_SYS_CAPABILITY_H #include <sys/prctl.h> #include <sys/capability.h> #endif #include "shadowlog.h" +#include "sizeof.h" + struct map_range *get_map_ranges(int ranges, int argc, char **argv) { @@ -29,21 +36,12 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv) return NULL; } - if (ranges != ((argc + 2) / 3)) { + if (ranges * 3 != argc) { fprintf(log_get_logfd(), "%s: ranges: %u is wrong for argc: %d\n", log_get_progname(), ranges, argc); return NULL; } - if ((ranges * 3) > argc) { - fprintf(log_get_logfd(), "ranges: %u argc: %d\n", - ranges, argc); - fprintf(log_get_logfd(), - _( "%s: Not enough arguments to form %u mappings\n"), - log_get_progname(), ranges); - return NULL; - } - - mappings = calloc(ranges, sizeof(*mappings)); + mappings = CALLOC(ranges, struct map_range); if (!mappings) { fprintf(log_get_logfd(), _( "%s: Memory allocation failure\n"), log_get_progname()); @@ -53,15 +51,15 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv) /* Gather up the ranges from the command line */ mapping = mappings; for (idx = 0, argidx = 0; idx < ranges; idx++, argidx += 3, mapping++) { - if (!getulong(argv[argidx + 0], &mapping->upper)) { + if (str2ul(&mapping->upper, argv[argidx + 0]) == -1) { free(mappings); return NULL; } - if (!getulong(argv[argidx + 1], &mapping->lower)) { + if (str2ul(&mapping->lower, argv[argidx + 1]) == -1) { free(mappings); return NULL; } - if (!getulong(argv[argidx + 2], &mapping->count)) { + if (str2ul(&mapping->count, argv[argidx + 2]) == -1) { free(mappings); return NULL; } @@ -99,7 +97,7 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv) * 8bytes --> 21 ascii estimated -> 18446744073709551616 (20 real) * 16bytes --> 39 ascii estimated -> 340282366920938463463374607431768211456 (39 real) */ -#define ULONG_DIGITS ((((sizeof(unsigned long) * CHAR_BIT) + 9)/10)*3) +#define ULONG_DIGITS (((WIDTHOF(unsigned long) + 9)/10)*3) #if HAVE_SYS_CAPABILITY_H static inline bool maps_lower_root(int cap, int ranges, const struct map_range *mappings) @@ -141,7 +139,7 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings int idx; const struct map_range *mapping; size_t bufsize; - char *buf, *pos; + char *buf, *pos, *end; int fd; #if HAVE_SYS_CAPABILITY_H @@ -172,7 +170,7 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings } /* Lockdown new{g,u}idmap by dropping all unneeded capabilities. */ - memset(data, 0, sizeof(data)); + bzero(data, sizeof(data)); data[0].effective = CAP_TO_MASK(cap); /* * When uid 0 from the ancestor userns is supposed to be mapped into @@ -187,23 +185,22 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings } #endif - bufsize = ranges * ((ULONG_DIGITS + 1) * 3); - pos = buf = xmalloc(bufsize); + bufsize = (ULONG_DIGITS + 1) * 3 * ranges + 1; + pos = buf = XMALLOC(bufsize, char); + end = buf + bufsize; /* Build the mapping command */ mapping = mappings; for (idx = 0; idx < ranges; idx++, mapping++) { /* Append this range to the string that will be written */ - int written = snprintf(pos, bufsize - (pos - buf), - "%lu %lu %lu\n", - mapping->upper, - mapping->lower, - mapping->count); - if ((written <= 0) || (written >= (bufsize - (pos - buf)))) { - fprintf(log_get_logfd(), _("%s: snprintf failed!\n"), log_get_progname()); - exit(EXIT_FAILURE); - } - pos += written; + pos = stpeprintf(pos, end, "%lu %lu %lu\n", + mapping->upper, + mapping->lower, + mapping->count); + } + if (pos == end || pos == NULL) { + fprintf(log_get_logfd(), _("%s: stpeprintf failed!\n"), log_get_progname()); + exit(EXIT_FAILURE); } /* Write the mapping to the mapping file */ @@ -213,11 +210,15 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings log_get_progname(), map_file, strerror(errno)); exit(EXIT_FAILURE); } - if (write(fd, buf, pos - buf) != (pos - buf)) { + if (write_full(fd, buf, pos - buf) == -1) { fprintf(log_get_logfd(), _("%s: write to %s failed: %s\n"), log_get_progname(), map_file, strerror(errno)); exit(EXIT_FAILURE); } - close(fd); + if (close(fd) != 0 && errno != EINTR) { + fprintf(log_get_logfd(), _("%s: closing %s failed: %s\n"), + log_get_progname(), map_file, strerror(errno)); + exit(EXIT_FAILURE); + } free(buf); } diff --git a/libmisc/idmapping.h b/lib/idmapping.h index 46d4631..46d4631 100644 --- a/libmisc/idmapping.h +++ b/lib/idmapping.h diff --git a/libmisc/isexpired.c b/lib/isexpired.c index ff20396..c275691 100644 --- a/libmisc/isexpired.c +++ b/lib/isexpired.c @@ -15,11 +15,13 @@ #include <config.h> #include <sys/types.h> -#include "prototypes.h" -#include "defines.h" #include <pwd.h> #include <time.h> +#include "adds.h" +#include "defines.h" +#include "prototypes.h" + #ident "$Id$" @@ -38,9 +40,9 @@ */ int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp) { - long now; + long now; - now = (long) time ((time_t *) 0) / SCALE; + now = time(NULL) / DAY; if (NULL == sp) { return 0; @@ -72,7 +74,8 @@ int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp) if ( (sp->sp_lstchg > 0) && (sp->sp_max >= 0) && (sp->sp_inact >= 0) - && (now >= (sp->sp_lstchg + sp->sp_max + sp->sp_inact))) { + && (now >= addsl(sp->sp_lstchg, sp->sp_max, sp->sp_inact))) + { return 2; } @@ -84,7 +87,7 @@ int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp) if ( (-1 == sp->sp_lstchg) || (-1 == sp->sp_max) - || (sp->sp_max >= ((10000L * DAY) / SCALE))) { + || (sp->sp_max >= 10000)) { return 0; } @@ -94,9 +97,9 @@ int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp) * the password has expired. */ - if (now >= (sp->sp_lstchg + sp->sp_max)) { + if (now >= addsl(sp->sp_lstchg, sp->sp_max)) return 1; - } + return 0; } diff --git a/libmisc/limits.c b/lib/limits.c index fea85fe..813c082 100644 --- a/libmisc/limits.c +++ b/lib/limits.c @@ -28,11 +28,12 @@ #include <pwd.h> #include "getdef.h" #include "shadowlog.h" -#ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> -#define LIMITS -#endif -#ifdef LIMITS + +#include "atoi/str2i.h" +#include "memzero.h" + + #ifndef LIMITS_FILE #define LIMITS_FILE "/etc/limits" #endif @@ -48,8 +49,10 @@ static int setrlimit_value (unsigned int resource, const char *value, unsigned int multiplier) { - struct rlimit rlim; - rlim_t limit; + char *end; + long l; + rlim_t limit; + struct rlimit rlim; /* The "-" is special, not belonging to a strange negative limit. * It is infinity, in a controlled way. @@ -58,23 +61,18 @@ static int setrlimit_value (unsigned int resource, limit = RLIM_INFINITY; } else { - /* We cannot use getlong here because it fails when there + /* We cannot use str2sl() here because it fails when there * is more to the value than just this number! * Also, we are limited to base 10 here (hex numbers will not * work with the limit string parser as is anyway) */ - char *endptr; - long longlimit = strtol (value, &endptr, 10); - if ((0 == longlimit) && (value == endptr)) { - /* No argument at all. No-op. - * FIXME: We could instead throw an error, though. - */ - return 0; - } - longlimit *= multiplier; - limit = (rlim_t)longlimit; - if (longlimit != limit) - { + errno = 0; + l = strtol(value, &end, 10); + + if (value == end || errno != 0) + return 0; // FIXME: We could instead throw an error, though. + + if (__builtin_mul_overflow(l, multiplier, &limit)) { /* FIXME: Again, silent error handling... * Wouldn't screaming make more sense? */ @@ -95,11 +93,11 @@ static int set_prio (const char *value) { long prio; - if ( (getlong (value, &prio) == 0) + if ( (str2sl(&prio, value) == -1) || (prio != (int) prio)) { return 0; } - if (setpriority (PRIO_PROCESS, 0, (int) prio) != 0) { + if (setpriority (PRIO_PROCESS, 0, prio) != 0) { return LOGIN_ERROR_RLIMIT; } return 0; @@ -108,14 +106,14 @@ static int set_prio (const char *value) static int set_umask (const char *value) { - unsigned long int mask; + unsigned long mask; - if ( (getulong (value, &mask) == 0) + if ( (str2ul(&mask, value) == -1) || (mask != (mode_t) mask)) { return 0; } - (void) umask ((mode_t) mask); + (void) umask (mask); return 0; } @@ -123,14 +121,9 @@ static int set_umask (const char *value) /* Counts the number of user logins and check against the limit */ static int check_logins (const char *name, const char *maxlogins) { -#ifdef USE_UTMPX - struct utmpx *ut; -#else /* !USE_UTMPX */ - struct utmp *ut; -#endif /* !USE_UTMPX */ unsigned long limit, count; - if (getulong (maxlogins, &limit) == 0) { + if (str2ul(&limit, maxlogins) == -1) { return 0; } @@ -139,38 +132,8 @@ static int check_logins (const char *name, const char *maxlogins) return LOGIN_ERROR_LOGIN; } - count = 0; -#ifdef USE_UTMPX - setutxent (); - while ((ut = getutxent ())) -#else /* !USE_UTMPX */ - setutent (); - while ((ut = getutent ())) -#endif /* !USE_UTMPX */ - { - if (USER_PROCESS != ut->ut_type) { - continue; - } - if ('\0' == ut->ut_user[0]) { - continue; - } - if (strncmp (name, ut->ut_user, sizeof (ut->ut_user)) != 0) { - continue; - } - count++; - if (count > limit) { - break; - } - } -#ifdef USE_UTMPX - endutxent (); -#else /* !USE_UTMPX */ - endutent (); -#endif /* !USE_UTMPX */ - /* - * This is called after setutmp(), so the number of logins counted - * includes the user who is currently trying to log in. - */ + count = active_sessions_count(name, limit); + if (count > limit) { SYSLOG ((LOG_WARN, "Too many logins (max %lu) for %s\n", @@ -243,34 +206,26 @@ static int do_user_limits (const char *buf, const char *name) while ('\0' != *pp) { switch (*pp++) { -#ifdef RLIMIT_AS case 'a': case 'A': /* RLIMIT_AS - max address space (KB) */ retval |= setrlimit_value (RLIMIT_AS, pp, 1024); break; -#endif -#ifdef RLIMIT_CORE case 'c': case 'C': /* RLIMIT_CORE - max core file size (KB) */ retval |= setrlimit_value (RLIMIT_CORE, pp, 1024); break; -#endif -#ifdef RLIMIT_DATA case 'd': case 'D': /* RLIMIT_DATA - max data size (KB) */ retval |= setrlimit_value (RLIMIT_DATA, pp, 1024); break; -#endif -#ifdef RLIMIT_FSIZE case 'f': case 'F': /* RLIMIT_FSIZE - Maximum filesize (KB) */ retval |= setrlimit_value (RLIMIT_FSIZE, pp, 1024); break; -#endif #ifdef RLIMIT_NICE case 'i': case 'I': @@ -294,13 +249,11 @@ static int do_user_limits (const char *buf, const char *name) retval |= setrlimit_value (RLIMIT_MEMLOCK, pp, 1024); break; #endif -#ifdef RLIMIT_NOFILE case 'n': case 'N': /* RLIMIT_NOFILE - max number of open files */ retval |= setrlimit_value (RLIMIT_NOFILE, pp, 1); break; -#endif #ifdef RLIMIT_RTPRIO case 'o': case 'O': @@ -319,20 +272,16 @@ static int do_user_limits (const char *buf, const char *name) retval |= setrlimit_value (RLIMIT_RSS, pp, 1024); break; #endif -#ifdef RLIMIT_STACK case 's': case 'S': /* RLIMIT_STACK - max stack size (KB) */ retval |= setrlimit_value (RLIMIT_STACK, pp, 1024); break; -#endif -#ifdef RLIMIT_CPU case 't': case 'T': /* RLIMIT_CPU - max CPU time (MIN) */ retval |= setrlimit_value (RLIMIT_CPU, pp, 60); break; -#endif #ifdef RLIMIT_NPROC case 'u': case 'U': @@ -409,11 +358,11 @@ static int setup_user_limits (const char *uname) char tempbuf[1024]; /* init things */ - memzero (buf, sizeof (buf)); - memzero (name, sizeof (name)); - memzero (limits, sizeof (limits)); - memzero (deflimits, sizeof (deflimits)); - memzero (tempbuf, sizeof (tempbuf)); + MEMZERO(buf); + MEMZERO(name); + MEMZERO(limits); + MEMZERO(deflimits); + MEMZERO(tempbuf); /* start the checks */ fil = fopen (LIMITS_FILE, "r"); @@ -430,7 +379,7 @@ static int setup_user_limits (const char *uname) if (('#' == buf[0]) || ('\n' == buf[0])) { continue; } - memzero (tempbuf, sizeof (tempbuf)); + MEMZERO(tempbuf); /* a valid line should have a username, then spaces, * then limits * we allow the format: @@ -479,7 +428,6 @@ static int setup_user_limits (const char *uname) } return do_user_limits (limits, uname); } -#endif /* LIMITS */ static void setup_usergroups (const struct passwd *info) @@ -523,7 +471,6 @@ void setup_limits (const struct passwd *info) */ if (getdef_bool ("QUOTAS_ENAB")) { -#ifdef LIMITS if (info->pw_uid != 0) { if ((setup_user_limits (info->pw_name) & LOGIN_ERROR_LOGIN) != 0) { (void) fputs (_("Too many logins.\n"), log_get_logfd()); @@ -531,18 +478,18 @@ void setup_limits (const struct passwd *info) exit (EXIT_FAILURE); } } -#endif for (cp = info->pw_gecos; cp != NULL; cp = strchr (cp, ',')) { if (',' == *cp) { cp++; } if (strncmp (cp, "pri=", 4) == 0) { - long int inc; - if ( (getlong (cp + 4, &inc) == 1) + long inc; + + if ( (str2sl(&inc, cp + 4) == 0) && (inc >= -20) && (inc <= 20)) { errno = 0; - if ( (nice ((int) inc) != -1) + if ( (nice (inc) != -1) || (0 != errno)) { continue; } @@ -556,10 +503,10 @@ void setup_limits (const struct passwd *info) continue; } if (strncmp (cp, "ulimit=", 7) == 0) { - long int blocks; - if ( (getlong (cp + 7, &blocks) == 0) + long blocks; + if ( (str2sl(&blocks, cp + 7) == -1) || (blocks != (int) blocks) - || (set_filesize_limit ((int) blocks) != 0)) { + || (set_filesize_limit (blocks) != 0)) { SYSLOG ((LOG_WARN, "Can't set the ulimit for user %s", info->pw_name)); @@ -567,14 +514,15 @@ void setup_limits (const struct passwd *info) continue; } if (strncmp (cp, "umask=", 6) == 0) { - unsigned long int mask; - if ( (getulong (cp + 6, &mask) == 0) + unsigned long mask; + + if ( (str2ul(&mask, cp + 6) == -1) || (mask != (mode_t) mask)) { SYSLOG ((LOG_WARN, "Can't set umask value for user %s", info->pw_name)); } else { - (void) umask ((mode_t) mask); + (void) umask (mask); } continue; @@ -584,6 +532,6 @@ void setup_limits (const struct passwd *info) } #else /* !USE_PAM */ -extern int errno; /* warning: ANSI C forbids an empty source file */ +extern int ISO_C_forbids_an_empty_translation_unit; #endif /* !USE_PAM */ diff --git a/libmisc/list.c b/lib/list.c index 9d7ec77..9fc6608 100644 --- a/libmisc/list.c +++ b/lib/list.c @@ -11,6 +11,8 @@ #ident "$Id$" #include <assert.h> + +#include "alloc.h" #include "prototypes.h" #include "defines.h" /* @@ -20,7 +22,8 @@ * name, and if not present it is added to a freshly allocated * list of users. */ -/*@only@*/ /*@out@*/char **add_list (/*@returned@*/ /*@only@*/char **list, const char *member) +/*@only@*/char ** +add_list(/*@returned@*/ /*@only@*/char **list, const char *member) { int i; char **tmp; @@ -33,7 +36,7 @@ * pointer if it is present. */ - for (i = 0; list[i] != (char *) 0; i++) { + for (i = 0; list[i] != NULL; i++) { if (strcmp (list[i], member) == 0) { return list; } @@ -44,7 +47,7 @@ * old entries, and the new entries as well. */ - tmp = (char **) xmalloc ((i + 2) * sizeof member); + tmp = XMALLOC(i + 2, char *); /* * Copy the original list to the new list, then append the @@ -52,12 +55,12 @@ * is returned to the invoker. */ - for (i = 0; list[i] != (char *) 0; i++) { + for (i = 0; list[i] != NULL; i++) { tmp[i] = list[i]; } tmp[i] = xstrdup (member); - tmp[i+1] = (char *) 0; + tmp[i+1] = NULL; return tmp; } @@ -70,7 +73,8 @@ * list of users. */ -/*@only@*/ /*@out@*/char **del_list (/*@returned@*/ /*@only@*/char **list, const char *member) +/*@only@*/char ** +del_list(/*@returned@*/ /*@only@*/char **list, const char *member) { int i, j; char **tmp; @@ -83,7 +87,7 @@ * pointer if it is not present. */ - for (i = j = 0; list[i] != (char *) 0; i++) { + for (i = j = 0; list[i] != NULL; i++) { if (strcmp (list[i], member) != 0) { j++; } @@ -98,7 +102,7 @@ * old entries. */ - tmp = (char **) xmalloc ((j + 1) * sizeof member); + tmp = XMALLOC(j + 1, char *); /* * Copy the original list except the deleted members to the @@ -106,14 +110,14 @@ * is returned to the invoker. */ - for (i = j = 0; list[i] != (char *) 0; i++) { + for (i = j = 0; list[i] != NULL; i++) { if (strcmp (list[i], member) != 0) { tmp[j] = list[i]; j++; } } - tmp[j] = (char *) 0; + tmp[j] = NULL; return tmp; } @@ -124,7 +128,8 @@ * function with list of members, the list elements are not enforced to be * constant strings here. */ -/*@only@*/ /*@out@*/char **dup_list (char *const *list) +/*@only@*/char ** +dup_list(char *const *list) { int i; char **tmp; @@ -133,7 +138,7 @@ for (i = 0; NULL != list[i]; i++); - tmp = (char **) xmalloc ((i + 1) * sizeof (char *)); + tmp = XMALLOC(i + 1, char *); i = 0; while (NULL != *list) { @@ -142,7 +147,7 @@ list++; } - tmp[i] = (char *) 0; + tmp[i] = NULL; return tmp; } @@ -210,14 +215,14 @@ bool is_on_list (char *const *list, const char *member) * Allocate the array we're going to store the pointers into. */ - array = (char **) xmalloc (sizeof (char *) * i); + array = XMALLOC(i, char *); /* * Empty list is special - 0 members, not 1 empty member. --marekm */ if ('\0' == *members) { - *array = (char *) 0; + *array = NULL; free (members); return array; } @@ -227,18 +232,9 @@ bool is_on_list (char *const *list, const char *member) * array of pointers. */ - for (cp = members, i = 0;; i++) { - array[i] = cp; - cp2 = strchr (cp, ','); - if (NULL != cp2) { - *cp2 = '\0'; - cp2++; - cp = cp2; - } else { - array[i + 1] = (char *) 0; - break; - } - } + for (cp = members, i = 0; cp != NULL; i++) + array[i] = strsep(&cp, ","); + array[i] = NULL; /* * Return the new array of pointers diff --git a/libmisc/log.c b/lib/log.c index a220be0..9f54d45 100644 --- a/libmisc/log.c +++ b/lib/log.c @@ -17,14 +17,18 @@ #include <time.h> #include "defines.h" #include <lastlog.h> +#include "memzero.h" #include "prototypes.h" +#include "string/strncpy.h" +#include "string/strtcpy.h" + /* * dolastlog - create lastlog entry * * A "last login" entry is created for the user being logged in. The * UID is extracted from the global (struct passwd) entry and the - * TTY information is gotten from the (struct utmp). + * TTY information is gotten from the (struct utmpx). */ void dolastlog ( struct lastlog *ll, @@ -67,7 +71,7 @@ void dolastlog ( * the way we read the old one in. */ - if (read (fd, (void *) &newlog, sizeof newlog) != (ssize_t) sizeof newlog) { + if (read (fd, &newlog, sizeof newlog) != (ssize_t) sizeof newlog) { memzero (&newlog, sizeof newlog); } if (NULL != ll) { @@ -77,17 +81,29 @@ void dolastlog ( ll_time = newlog.ll_time; (void) time (&ll_time); newlog.ll_time = ll_time; - strncpy (newlog.ll_line, line, sizeof (newlog.ll_line) - 1); + STRTCPY(newlog.ll_line, line); #if HAVE_LL_HOST - strncpy (newlog.ll_host, host, sizeof (newlog.ll_host) - 1); + STRNCPY(newlog.ll_host, host); #endif if ( (lseek (fd, offset, SEEK_SET) != offset) - || (write (fd, (const void *) &newlog, sizeof newlog) != (ssize_t) sizeof newlog) - || (close (fd) != 0)) { - SYSLOG ((LOG_WARN, - "Can't write lastlog entry for UID %lu in %s.", - (unsigned long) pw->pw_uid, LASTLOG_FILE)); + || (write_full(fd, &newlog, sizeof newlog) == -1)) { + goto err_write; + } + + if (close (fd) != 0 && errno != EINTR) { + goto err_close; + } + + return; + +err_write: + { + int saved_errno = errno; (void) close (fd); + errno = saved_errno; } +err_close: + SYSLOG ((LOG_WARN, + "Can't write lastlog entry for UID %lu in %s: %m", + (unsigned long) pw->pw_uid, LASTLOG_FILE)); } - diff --git a/libmisc/mail.c b/lib/mail.c index 647f879..d14bdb1 100644 --- a/libmisc/mail.c +++ b/lib/mail.c @@ -15,7 +15,9 @@ #include <stdio.h> #include <string.h> +#include "alloc.h" #include "getdef.h" +#include "string/sprintf.h" #ident "$Id$" @@ -34,22 +36,18 @@ void mailcheck (void) */ mailbox = getenv ("MAILDIR"); if (NULL != mailbox) { - char *newmail; - size_t len = strlen (mailbox) + 5; - int wlen; + char *newmail; - newmail = xmalloc (len); - wlen = snprintf (newmail, len, "%s/new", mailbox); - assert (wlen == (int) len - 1); + xasprintf(&newmail, "%s/new", mailbox); if (stat (newmail, &statbuf) != -1 && statbuf.st_size != 0) { if (statbuf.st_mtime > statbuf.st_atime) { - free (newmail); + free(newmail); (void) puts (_("You have new mail.")); return; } } - free (newmail); + free(newmail); } mailbox = getenv ("MAIL"); diff --git a/libmisc/motd.c b/lib/motd.c index 7f7e523..d1d5bf6 100644 --- a/libmisc/motd.c +++ b/lib/motd.c @@ -12,9 +12,11 @@ #ident "$Id$" #include <stdio.h> -#include "prototypes.h" + +#include "alloc.h" #include "defines.h" #include "getdef.h" +#include "prototypes.h" /* * motd -- output the /etc/motd file * diff --git a/libmisc/myname.c b/lib/myname.c index 1b02617..1b02617 100644 --- a/libmisc/myname.c +++ b/lib/myname.c diff --git a/libmisc/obscure.c b/lib/obscure.c index 3daaa95..549c2a8 100644 --- a/libmisc/obscure.c +++ b/lib/obscure.c @@ -9,25 +9,27 @@ #include <config.h> -#ifndef USE_PAM - #ident "$Id$" -/* - * This version of obscure.c contains modifications to support "cracklib" - * by Alec Muffet (alec.muffett@uk.sun.com). You must obtain the Cracklib - * library source code for this function to operate. - */ #include <ctype.h> #include <stdio.h> + +#include "alloc.h" +#include "attr.h" +#include "memzero.h" #include "prototypes.h" #include "defines.h" #include "getdef.h" + +#if WITH_LIBBSD == 0 +#include "freezero.h" +#endif /* WITH_LIBBSD */ + /* * can't be a palindrome - like `R A D A R' or `M A D A M' */ -static bool palindrome (unused const char *old, const char *new) +static bool palindrome (MAYBE_UNUSED const char *old, const char *new) { size_t i, j; @@ -73,57 +75,6 @@ static bool similar (/*@notnull@*/const char *old, /*@notnull@*/const char *new) return true; } -/* - * a nice mix of characters. - */ - -static bool simple (unused const char *old, const char *new) -{ - bool digits = false; - bool uppers = false; - bool lowers = false; - bool others = false; - int size; - int i; - - for (i = 0; '\0' != new[i]; i++) { - if (isdigit (new[i])) { - digits = true; - } else if (isupper (new[i])) { - uppers = true; - } else if (islower (new[i])) { - lowers = true; - } else { - others = true; - } - } - - /* - * The scam is this - a password of only one character type - * must be 8 letters long. Two types, 7, and so on. - */ - - size = 9; - if (digits) { - size--; - } - if (uppers) { - size--; - } - if (lowers) { - size--; - } - if (others) { - size--; - } - - if (size <= i) { - return false; - } - - return true; -} - static char *str_lower (/*@returned@*/char *string) { char *cp; @@ -137,28 +88,18 @@ static char *str_lower (/*@returned@*/char *string) static /*@observer@*//*@null@*/const char *password_check ( /*@notnull@*/const char *old, /*@notnull@*/const char *new, - /*@notnull@*/const struct passwd *pwdp) + /*@notnull@*/MAYBE_UNUSED const struct passwd *pwdp) { const char *msg = NULL; char *oldmono, *newmono, *wrapped; -#ifdef HAVE_LIBCRACK - char *dictpath; - -#ifdef HAVE_LIBCRACK_PW - char *FascistCheckPw (); -#else - char *FascistCheck (); -#endif -#endif - if (strcmp (new, old) == 0) { return _("no change"); } newmono = str_lower (xstrdup (new)); oldmono = str_lower (xstrdup (old)); - wrapped = xmalloc (strlen (oldmono) * 2 + 1); + wrapped = XMALLOC(strlen(oldmono) * 2 + 1, char); strcpy (wrapped, oldmono); strcat (wrapped, oldmono); @@ -168,25 +109,8 @@ static /*@observer@*//*@null@*/const char *password_check ( msg = _("case changes only"); } else if (similar (oldmono, newmono)) { msg = _("too similar"); - } else if (simple (old, new)) { - msg = _("too simple"); } else if (strstr (wrapped, newmono) != NULL) { msg = _("rotated"); - } else { -#ifdef HAVE_LIBCRACK - /* - * Invoke Alec Muffett's cracklib routines. - */ - - dictpath = getdef_str ("CRACKLIB_DICTPATH"); - if (NULL != dictpath) { -#ifdef HAVE_LIBCRACK_PW - msg = FascistCheckPw (new, dictpath, pwdp); -#else - msg = FascistCheck (new, dictpath); -#endif - } -#endif } strzero (newmono); strzero (oldmono); @@ -257,7 +181,7 @@ static /*@observer@*//*@null@*/const char *obscure_msg ( } } - maxlen = (size_t) getdef_num ("PASS_MAX_LEN", 8); + maxlen = getdef_num ("PASS_MAX_LEN", 8); if ( (oldlen <= maxlen) && (newlen <= maxlen)) { return NULL; @@ -274,10 +198,8 @@ static /*@observer@*//*@null@*/const char *obscure_msg ( msg = password_check (old1, new1, pwdp); - memzero (new1, newlen); - memzero (old1, oldlen); - free (new1); - free (old1); + freezero (new1, newlen); + freezero (old1, oldlen); return msg; } @@ -300,7 +222,3 @@ bool obscure (const char *old, const char *new, const struct passwd *pwdp) } return true; } - -#else /* !USE_PAM */ -extern int errno; /* warning: ANSI C forbids an empty source file */ -#endif /* !USE_PAM */ diff --git a/libmisc/pam_pass.c b/lib/pam_pass.c index 166a42e..ff49173 100644 --- a/libmisc/pam_pass.c +++ b/lib/pam_pass.c @@ -55,5 +55,5 @@ void do_pam_passwd (const char *user, bool silent, bool change_expired) (void) pam_end (pamh, PAM_SUCCESS); } #else /* !USE_PAM */ -extern int errno; /* warning: ANSI C forbids an empty source file */ +extern int ISO_C_forbids_an_empty_translation_unit; #endif /* !USE_PAM */ diff --git a/libmisc/pam_pass_non_interactive.c b/lib/pam_pass_non_interactive.c index 34cdc1f..3d10908 100644 --- a/libmisc/pam_pass_non_interactive.c +++ b/lib/pam_pass_non_interactive.c @@ -13,7 +13,13 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> +#include <strings.h> + #include <security/pam_appl.h> + +#include "alloc.h" +#include "attr.h" +#include "memzero.h" #include "prototypes.h" #include "shadowlog.h" @@ -21,7 +27,7 @@ static int ni_conv (int num_msg, const struct pam_message **msg, struct pam_response **resp, - unused void *appdata_ptr); + MAYBE_UNUSED void *appdata_ptr); static const struct pam_conv non_interactive_pam_conv = { ni_conv, NULL @@ -32,7 +38,7 @@ static const struct pam_conv non_interactive_pam_conv = { static int ni_conv (int num_msg, const struct pam_message **msg, struct pam_response **resp, - unused void *appdata_ptr) + MAYBE_UNUSED void *appdata_ptr) { struct pam_response *responses; int count; @@ -43,8 +49,7 @@ static int ni_conv (int num_msg, return PAM_CONV_ERR; } - responses = (struct pam_response *) calloc ((size_t) num_msg, - sizeof (*responses)); + responses = CALLOC (num_msg, struct pam_response); if (NULL == responses) { return PAM_CONV_ERR; } @@ -93,9 +98,8 @@ static int ni_conv (int num_msg, failed_conversation: for (count=0; count < num_msg; count++) { if (NULL != responses[count].resp) { - memset (responses[count].resp, 0, - strlen (responses[count].resp)); - free (responses[count].resp); + strzero(responses[count].resp); + free(responses[count].resp); responses[count].resp = NULL; } } @@ -141,5 +145,5 @@ int do_pam_passwd_non_interactive (const char *pam_service, return ((PAM_SUCCESS == ret) ? 0 : 1); } #else /* !USE_PAM */ -extern int errno; /* warning: ANSI C forbids an empty source file */ +extern int ISO_C_forbids_an_empty_translation_unit; #endif /* !USE_PAM */ diff --git a/libmisc/prefix_flag.c b/lib/prefix_flag.c index 4eb5154..bba7102 100644 --- a/libmisc/prefix_flag.c +++ b/lib/prefix_flag.c @@ -11,7 +11,9 @@ #include <stdio.h> #include <assert.h> + #include "defines.h" +#include "alloc.h" #include "prototypes.h" /*@-exitarg@*/ #include "exitcodes.h" @@ -26,6 +28,8 @@ #endif /* ENABLE_SUBIDS */ #include "getdef.h" #include "shadowlog.h" +#include "string/sprintf.h" + static char *passwd_db_file = NULL; static char *spw_db_file = NULL; @@ -83,6 +87,15 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char ** if (prefix != NULL) { + /* Drop privileges */ + if ( (setregid (getgid (), getgid ()) != 0) + || (setreuid (getuid (), getuid ()) != 0)) { + fprintf (log_get_logfd(), + _("%s: failed to drop privileges (%s)\n"), + log_get_progname(), strerror (errno)); + exit (EXIT_FAILURE); + } + if ( prefix[0] == '\0' || !strcmp(prefix, "/")) return ""; /* if prefix is "/" then we ignore the flag option */ /* should we prevent symbolic link from being used as a prefix? */ @@ -93,50 +106,33 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char ** log_get_progname()); exit (E_BAD_ARG); } - size_t len; - len = strlen(prefix) + strlen(PASSWD_FILE) + 2; - passwd_db_file = xmalloc(len); - snprintf(passwd_db_file, len, "%s/%s", prefix, PASSWD_FILE); + + xasprintf(&passwd_db_file, "%s/%s", prefix, PASSWD_FILE); pw_setdbname(passwd_db_file); - len = strlen(prefix) + strlen(GROUP_FILE) + 2; - group_db_file = xmalloc(len); - snprintf(group_db_file, len, "%s/%s", prefix, GROUP_FILE); + xasprintf(&group_db_file, "%s/%s", prefix, GROUP_FILE); gr_setdbname(group_db_file); #ifdef SHADOWGRP - len = strlen(prefix) + strlen(SGROUP_FILE) + 2; - sgroup_db_file = xmalloc(len); - snprintf(sgroup_db_file, len, "%s/%s", prefix, SGROUP_FILE); + xasprintf(&sgroup_db_file, "%s/%s", prefix, SGROUP_FILE); sgr_setdbname(sgroup_db_file); #endif -#ifdef USE_NIS - __setspNIS(0); /* disable NIS for now, at least until it is properly supporting a "prefix" */ -#endif - len = strlen(prefix) + strlen(SHADOW_FILE) + 2; - spw_db_file = xmalloc(len); - snprintf(spw_db_file, len, "%s/%s", prefix, SHADOW_FILE); + xasprintf(&spw_db_file, "%s/%s", prefix, SHADOW_FILE); spw_setdbname(spw_db_file); #ifdef ENABLE_SUBIDS - len = strlen(prefix) + strlen("/etc/subuid") + 2; - suid_db_file = xmalloc(len); - snprintf(suid_db_file, len, "%s/%s", prefix, "/etc/subuid"); + xasprintf(&suid_db_file, "%s/%s", prefix, SUBUID_FILE); sub_uid_setdbname(suid_db_file); - len = strlen(prefix) + strlen("/etc/subgid") + 2; - sgid_db_file = xmalloc(len); - snprintf(sgid_db_file, len, "%s/%s", prefix, "/etc/subgid"); + xasprintf(&sgid_db_file, "%s/%s", prefix, SUBGID_FILE); sub_gid_setdbname(sgid_db_file); #endif #ifdef USE_ECONF setdef_config_file(prefix); #else - len = strlen(prefix) + strlen("/etc/login.defs") + 2; - def_conf_file = xmalloc(len); - snprintf(def_conf_file, len, "%s/%s", prefix, "/etc/login.defs"); + xasprintf(&def_conf_file, "%s/%s", prefix, "/etc/login.defs"); setdef_config_file(def_conf_file); #endif } @@ -227,6 +223,29 @@ extern struct passwd *prefix_getpwnam(const char* name) return getpwnam(name); } } +#if HAVE_FGETPWENT_R +extern int prefix_getpwnam_r(const char* name, struct passwd* pwd, + char* buf, size_t buflen, struct passwd** result) +{ + if (passwd_db_file) { + FILE* fg; + int ret = 0; + + fg = fopen(passwd_db_file, "rt"); + if (!fg) + return errno; + while ((ret = fgetpwent_r(fg, pwd, buf, buflen, result)) == 0) { + if (!strcmp(name, pwd->pw_name)) + break; + } + fclose(fg); + return ret; + } + else { + return getpwnam_r(name, pwd, buf, buflen, result); + } +} +#endif extern struct spwd *prefix_getspnam(const char* name) { if (spw_db_file) { @@ -315,26 +334,27 @@ extern void prefix_endgrent(void) extern struct group *prefix_getgr_nam_gid(const char *grname) { - long long int gid; - char *endptr; - struct group *g; + char *end; + long long gid; + struct group *g; if (NULL == grname) { return NULL; } - if (group_db_file) { - errno = 0; - gid = strtoll (grname, &endptr, 10); - if ( ('\0' != *grname) - && ('\0' == *endptr) - && (ERANGE != errno) - && (gid == (gid_t)gid)) { - return prefix_getgrgid ((gid_t) gid); - } - g = prefix_getgrnam (grname); - return g ? __gr_dup(g) : NULL; - } - else + if (!group_db_file) return getgr_nam_gid(grname); + + errno = 0; + gid = strtoll(grname, &end, 10); + if ( ('\0' != *grname) + && ('\0' == *end) + && (0 == errno) + && (gid == (gid_t)gid)) + { + return prefix_getgrgid(gid); + } + + g = prefix_getgrnam(grname); + return g ? __gr_dup(g) : NULL; } diff --git a/libmisc/pwd2spwd.c b/lib/pwd2spwd.c index 139a024..eea9519 100644 --- a/libmisc/pwd2spwd.c +++ b/lib/pwd2spwd.c @@ -11,8 +11,6 @@ #ident "$Id$" -#ifndef USE_PAM - #include <sys/types.h> #include "prototypes.h" #include "defines.h" @@ -41,8 +39,8 @@ struct spwd *pwd_to_spwd (const struct passwd *pw) * Defaults used if there is no pw_age information. */ sp.sp_min = 0; - sp.sp_max = (10000L * DAY) / SCALE; - sp.sp_lstchg = (long) gettime () / SCALE; + sp.sp_max = 10000; + sp.sp_lstchg = gettime () / DAY; if (0 == sp.sp_lstchg) { /* Better disable aging than requiring a password * change */ @@ -61,7 +59,4 @@ struct spwd *pwd_to_spwd (const struct passwd *pw) return &sp; } -#else /* USE_PAM */ -extern int errno; /* warning: ANSI C forbids an empty source file */ -#endif /* !USE_PAM */ diff --git a/libmisc/pwd_init.c b/lib/pwd_init.c index 63c71e2..b3f94e1 100644 --- a/libmisc/pwd_init.c +++ b/lib/pwd_init.c @@ -15,9 +15,7 @@ #include <signal.h> #include <sys/types.h> #include <sys/stat.h> -#ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> -#endif #include "prototypes.h" @@ -28,39 +26,22 @@ */ void pwd_init (void) { -#ifdef HAVE_SYS_RESOURCE_H struct rlimit rlim; -#ifdef RLIMIT_CORE rlim.rlim_cur = rlim.rlim_max = 0; setrlimit (RLIMIT_CORE, &rlim); -#endif + rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY; -#ifdef RLIMIT_AS setrlimit (RLIMIT_AS, &rlim); -#endif -#ifdef RLIMIT_CPU + setrlimit (RLIMIT_CPU, &rlim); -#endif -#ifdef RLIMIT_DATA setrlimit (RLIMIT_DATA, &rlim); -#endif -#ifdef RLIMIT_FSIZE setrlimit (RLIMIT_FSIZE, &rlim); -#endif -#ifdef RLIMIT_NOFILE setrlimit (RLIMIT_NOFILE, &rlim); -#endif #ifdef RLIMIT_RSS setrlimit (RLIMIT_RSS, &rlim); #endif -#ifdef RLIMIT_STACK setrlimit (RLIMIT_STACK, &rlim); -#endif -#else /* !HAVE_SYS_RESOURCE_H */ - set_filesize_limit (30000); - /* don't know how to set the other limits... */ -#endif /* !HAVE_SYS_RESOURCE_H */ signal (SIGALRM, SIG_IGN); signal (SIGHUP, SIG_IGN); @@ -68,12 +49,8 @@ void pwd_init (void) signal (SIGPIPE, SIG_IGN); signal (SIGQUIT, SIG_IGN); signal (SIGTERM, SIG_IGN); -#ifdef SIGTSTP signal (SIGTSTP, SIG_IGN); -#endif -#ifdef SIGTTOU signal (SIGTTOU, SIG_IGN); -#endif umask (077); } diff --git a/libmisc/pwdcheck.c b/lib/pwdcheck.c index 15fc3a3..93c9f5c 100644 --- a/libmisc/pwdcheck.c +++ b/lib/pwdcheck.c @@ -13,12 +13,14 @@ #include <stdio.h> #include <shadow.h> + +#include "attr.h" #include "prototypes.h" #include "defines.h" #include "pwauth.h" #include "shadowlog.h" -void passwd_check (const char *user, const char *passwd, unused const char *progname) +void passwd_check (const char *user, const char *passwd, MAYBE_UNUSED const char *progname) { struct spwd *sp; @@ -26,7 +28,7 @@ void passwd_check (const char *user, const char *passwd, unused const char *prog if (NULL != sp) { passwd = sp->sp_pwdp; } - if (pw_auth (passwd, user, PW_LOGIN, (char *) 0) != 0) { + if (pw_auth (passwd, user, PW_LOGIN, NULL) != 0) { SYSLOG ((LOG_WARN, "incorrect password for `%s'", user)); (void) sleep (1); fprintf (log_get_logfd(), _("Incorrect password for %s.\n"), user); @@ -34,5 +36,5 @@ void passwd_check (const char *user, const char *passwd, unused const char *prog } } #else /* USE_PAM */ -extern int errno; /* warning: ANSI C forbids an empty source file */ +extern int ISO_C_forbids_an_empty_translation_unit; #endif /* USE_PAM */ diff --git a/libmisc/remove_tree.c b/lib/remove_tree.c index 3d76b95..3d76b95 100644 --- a/libmisc/remove_tree.c +++ b/lib/remove_tree.c diff --git a/libmisc/rlogin.c b/lib/rlogin.c index fa67dc3..cbc05dd 100644 --- a/libmisc/rlogin.c +++ b/lib/rlogin.c @@ -18,76 +18,36 @@ #include <stdio.h> #include <pwd.h> #include <netdb.h> + +#include "atoi/str2i.h" + + static struct { int spd_name; int spd_baud; } speed_table[] = { -#ifdef B50 - { - B50, 50}, -#endif -#ifdef B75 - { - B75, 75}, -#endif -#ifdef B110 - { - B110, 110}, -#endif -#ifdef B134 - { - B134, 134}, -#endif -#ifdef B150 - { - B150, 150}, -#endif -#ifdef B200 - { - B200, 200}, -#endif -#ifdef B300 - { - B300, 300}, -#endif -#ifdef B600 - { - B600, 600}, -#endif -#ifdef B1200 - { - B1200, 1200}, -#endif -#ifdef B1800 - { - B1800, 1800}, -#endif -#ifdef B2400 - { - B2400, 2400}, -#endif -#ifdef B4800 - { - B4800, 4800}, -#endif -#ifdef B9600 - { - B9600, 9600}, -#endif -#ifdef B19200 - { - B19200, 19200}, -#endif -#ifdef B38400 - { - B38400, 38400}, -#endif - { - -1, -1} + { B50, 50}, + { B75, 75}, + { B110, 110}, + { B134, 134}, + { B150, 150}, + { B200, 200}, + { B300, 300}, + { B600, 600}, + { B1200, 1200}, + { B1800, 1800}, + { B2400, 2400}, + { B4800, 4800}, + { B9600, 9600}, + { B19200, 19200}, + { B38400, 38400}, + { -1, -1} }; -static void get_remote_string (char *buf, size_t size) + +static void +get_remote_string(char *buf, size_t size) { for (;;) { if (read (0, buf, 1) != 1) { @@ -101,11 +61,13 @@ static void get_remote_string (char *buf, size_t size) ++buf; } } - /*NOTREACHED*/} + /*NOTREACHED*/ +} + int -do_rlogin (const char *remote_host, char *name, size_t namelen, char *term, - size_t termlen) +do_rlogin(const char *remote_host, char *name, size_t namesize, char *term, + size_t termsize) { struct passwd *pwd; char remote_name[32]; @@ -115,18 +77,17 @@ do_rlogin (const char *remote_host, char *name, size_t namelen, char *term, int i; TERMIO termio; - get_remote_string (remote_name, sizeof remote_name); - get_remote_string (name, namelen); - get_remote_string (term, termlen); + get_remote_string(remote_name, sizeof(remote_name)); + get_remote_string(name, namesize); + get_remote_string(term, termsize); cp = strchr (term, '/'); if (NULL != cp) { *cp = '\0'; cp++; - if (getulong (cp, &remote_speed) == 0) { + if (str2ul(&remote_speed, cp) == -1) remote_speed = 9600; - } } for (i = 0; ( (speed_table[i].spd_baud != remote_speed) @@ -172,4 +133,3 @@ do_rlogin (const char *remote_host, char *name, size_t namelen, char *term, #endif } #endif /* RLOGIN */ - diff --git a/libmisc/root_flag.c b/lib/root_flag.c index 62915b0..5572831 100644 --- a/libmisc/root_flag.c +++ b/lib/root_flag.c @@ -91,16 +91,16 @@ static void change_root (const char* newroot) exit (E_BAD_ARG); } - if (chdir (newroot) != 0) { + if (chroot (newroot) != 0) { fprintf(log_get_logfd(), - _("%s: cannot chdir to chroot directory %s: %s\n"), + _("%s: unable to chroot to directory %s: %s\n"), log_get_progname(), newroot, strerror (errno)); exit (E_BAD_ARG); } - if (chroot (newroot) != 0) { + if (chdir ("/") != 0) { fprintf(log_get_logfd(), - _("%s: unable to chroot to directory %s: %s\n"), + _("%s: cannot chdir in chroot directory %s: %s\n"), log_get_progname(), newroot, strerror (errno)); exit (E_BAD_ARG); } diff --git a/libmisc/salt.c b/lib/salt.c index e5f633a..529d59c 100644 --- a/libmisc/salt.c +++ b/lib/salt.c @@ -10,8 +10,6 @@ * * Written by Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>, * it is in the public domain. - * - * l64a was Written by J.T. Conklin <jtc@netbsd.org>. Public domain. */ #include <config.h> @@ -22,9 +20,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#if HAVE_SYS_RANDOM_H -#include <sys/random.h> -#endif +#include <strings.h> + #include "prototypes.h" #include "defines.h" #include "getdef.h" @@ -91,13 +88,9 @@ #define GENSALT_SETTING_SIZE 100 /* local function prototypes */ -static long read_random_bytes (void); #if !USE_XCRYPT_GENSALT static /*@observer@*/const char *gensalt (size_t salt_size); #endif /* !USE_XCRYPT_GENSALT */ -#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) -static long shadow_random (long min, long max); -#endif /* USE_SHA_CRYPT || USE_BCRYPT */ #ifdef USE_SHA_CRYPT static /*@observer@*/unsigned long SHA_get_salt_rounds (/*@null@*/const int *prefered_rounds); static /*@observer@*/void SHA_salt_rounds_to_buf (char *buf, unsigned long rounds); @@ -111,113 +104,6 @@ static /*@observer@*/unsigned long YESCRYPT_get_salt_cost (/*@null@*/const int * static /*@observer@*/void YESCRYPT_salt_cost_to_buf (char *buf, unsigned long cost); #endif /* USE_YESCRYPT */ -#if !USE_XCRYPT_GENSALT && !defined(HAVE_L64A) -static /*@observer@*/char *l64a (long value) -{ - static char buf[8]; - char *s = buf; - int digit; - int i; - - if (value < 0) { - errno = EINVAL; - return(NULL); - } - - for (i = 0; value != 0 && i < 6; i++) { - digit = value & 0x3f; - - if (digit < 2) { - *s = digit + '.'; - } else if (digit < 12) { - *s = digit + '0' - 2; - } else if (digit < 38) { - *s = digit + 'A' - 12; - } else { - *s = digit + 'a' - 38; - } - - value >>= 6; - s++; - } - - *s = '\0'; - - return buf; -} -#endif /* !USE_XCRYPT_GENSALT && !defined(HAVE_L64A) */ - -/* Read sizeof (long) random bytes from /dev/urandom. */ -static long read_random_bytes (void) -{ - long randval = 0; - -#ifdef HAVE_ARC4RANDOM_BUF - /* arc4random_buf, if it exists, can never fail. */ - arc4random_buf (&randval, sizeof (randval)); - goto end; -#endif - -#ifdef HAVE_GETENTROPY - /* getentropy may exist but lack kernel support. */ - if (getentropy (&randval, sizeof (randval)) == 0) { - goto end; - } -#endif - -#ifdef HAVE_GETRANDOM - /* Likewise getrandom. */ - if ((size_t) getrandom (&randval, sizeof (randval), 0) == sizeof (randval)) { - goto end; - } -#endif - - /* Use /dev/urandom as a last resort. */ - FILE *f = fopen ("/dev/urandom", "r"); - if (NULL == f) { - goto fail; - } - - if (fread (&randval, sizeof (randval), 1, f) != 1) { - fclose(f); - goto fail; - } - - fclose(f); - goto end; - -fail: - fprintf (log_get_logfd(), - _("Unable to obtain random bytes.\n")); - exit (1); - -end: - return randval; -} - -#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) -/* - * Return a random number between min and max (both included). - * - * It favors slightly the higher numbers. - */ -static long shadow_random (long min, long max) -{ - double drand; - long ret; - - drand = (double) (read_random_bytes () & RAND_MAX) / (double) RAND_MAX; - drand *= (double) (max - min + 1); - /* On systems were this is not random() range is lower, we favor - * higher numbers of salt. */ - ret = (long) (max + 1 - drand); - /* And we catch limits, and use the highest number */ - if ((ret < min) || (ret > max)) { - ret = max; - } - return ret; -} -#endif /* USE_SHA_CRYPT || USE_BCRYPT */ #ifdef USE_SHA_CRYPT /* Return the the rounds number for the SHA crypt methods. */ @@ -245,7 +131,7 @@ static /*@observer@*/unsigned long SHA_get_salt_rounds (/*@null@*/const int *pre max_rounds = min_rounds; } - rounds = (unsigned long) shadow_random (min_rounds, max_rounds); + rounds = csrand_interval (min_rounds, max_rounds); } } else if (0 == *prefered_rounds) { rounds = SHA_ROUNDS_DEFAULT; @@ -318,7 +204,7 @@ static /*@observer@*/unsigned long BCRYPT_get_salt_rounds (/*@null@*/const int * max_rounds = min_rounds; } - rounds = (unsigned long) shadow_random (min_rounds, max_rounds); + rounds = csrand_interval (min_rounds, max_rounds); } } else if (0 == *prefered_rounds) { rounds = B_ROUNDS_DEFAULT; @@ -435,13 +321,13 @@ static /*@observer@*/const char *gensalt (size_t salt_size) { static char salt[MAX_SALT_SIZE + 6]; - memset (salt, '\0', MAX_SALT_SIZE + 6); + bzero(salt, MAX_SALT_SIZE + 6); assert (salt_size >= MIN_SALT_SIZE && salt_size <= MAX_SALT_SIZE); - strcat (salt, l64a (read_random_bytes ())); + strcat (salt, l64a (csrand ())); do { - strcat (salt, l64a (read_random_bytes ())); + strcat (salt, l64a (csrand ())); } while (strlen (salt) < salt_size); salt[salt_size] = '\0'; @@ -474,7 +360,7 @@ static /*@observer@*/const char *gensalt (size_t salt_size) const char *method; unsigned long rounds = 0; - memset (result, '\0', GENSALT_SETTING_SIZE); + bzero(result, GENSALT_SETTING_SIZE); if (NULL != meth) method = meth; @@ -493,26 +379,26 @@ static /*@observer@*/const char *gensalt (size_t salt_size) } else if (0 == strcmp (method, "BCRYPT")) { BCRYPTMAGNUM(result); salt_len = BCRYPT_SALT_SIZE; - rounds = BCRYPT_get_salt_rounds ((int *) arg); + rounds = BCRYPT_get_salt_rounds (arg); BCRYPT_salt_rounds_to_buf (result, rounds); #endif /* USE_BCRYPT */ #ifdef USE_YESCRYPT } else if (0 == strcmp (method, "YESCRYPT")) { MAGNUM(result, 'y'); salt_len = YESCRYPT_SALT_SIZE; - rounds = YESCRYPT_get_salt_cost ((int *) arg); + rounds = YESCRYPT_get_salt_cost (arg); YESCRYPT_salt_cost_to_buf (result, rounds); #endif /* USE_YESCRYPT */ #ifdef USE_SHA_CRYPT } else if (0 == strcmp (method, "SHA256")) { MAGNUM(result, '5'); salt_len = SHA_CRYPT_SALT_SIZE; - rounds = SHA_get_salt_rounds ((int *) arg); + rounds = SHA_get_salt_rounds (arg); SHA_salt_rounds_to_buf (result, rounds); } else if (0 == strcmp (method, "SHA512")) { MAGNUM(result, '6'); salt_len = SHA_CRYPT_SALT_SIZE; - rounds = SHA_get_salt_rounds ((int *) arg); + rounds = SHA_get_salt_rounds (arg); SHA_salt_rounds_to_buf (result, rounds); #endif /* USE_SHA_CRYPT */ } else if (0 != strcmp (method, "DES")) { @@ -522,7 +408,7 @@ static /*@observer@*/const char *gensalt (size_t salt_size) method); salt_len = MAX_SALT_SIZE; rounds = 0; - memset (result, '\0', GENSALT_SETTING_SIZE); + bzero(result, GENSALT_SETTING_SIZE); } #if USE_XCRYPT_GENSALT @@ -534,7 +420,7 @@ static /*@observer@*/const char *gensalt (size_t salt_size) /* Avoid -Wunused-but-set-variable. */ salt_len = GENSALT_SETTING_SIZE - 1; rounds = 0; - memset (result, '.', salt_len); + memset(result, '.', salt_len); result[salt_len] = '\0'; } diff --git a/libmisc/setugid.c b/lib/setugid.c index 6dbe38e..6dbe38e 100644 --- a/libmisc/setugid.c +++ b/lib/setugid.c diff --git a/libmisc/setupenv.c b/lib/setupenv.c index 5d7aefa..c9b7f26 100644 --- a/libmisc/setupenv.c +++ b/lib/setupenv.c @@ -20,26 +20,25 @@ #include <sys/stat.h> #include <stdio.h> #include <ctype.h> + +#include "alloc.h" #include "prototypes.h" #include "defines.h" #include <pwd.h> #include "getdef.h" #include "shadowlog.h" +#include "string/sprintf.h" + #ifndef USE_PAM static void -addenv_path (const char *varname, const char *dirname, const char *filename) +addenv_path(const char *varname, const char *dirname, const char *filename) { - char *buf; - size_t len = strlen (dirname) + strlen (filename) + 2; - int wlen; - - buf = xmalloc (len); - wlen = snprintf (buf, len, "%s/%s", dirname, filename); - assert (wlen == (int) len - 1); + char *buf; - addenv (varname, buf); - free (buf); + xasprintf(&buf, "%s/%s", dirname, filename); + addenv(varname, buf); + free(buf); } static void read_env_file (const char *filename) @@ -61,7 +60,7 @@ static void read_env_file (const char *filename) cp = buf; /* ignore whitespace and comments */ - while (('\0' != *cp) && isspace (*cp)) { + while (isspace (*cp)) { cp++; } if (('\0' == *cp) || ('#' == *cp)) { @@ -194,8 +193,6 @@ void setup_env (struct passwd *info) */ if (chdir (info->pw_dir) == -1) { - static char temp_pw_dir[] = "/"; - if (!getdef_bool ("DEFAULT_HOME") || chdir ("/") == -1) { fprintf (log_get_logfd(), _("Unable to cd to '%s'\n"), info->pw_dir); @@ -207,7 +204,7 @@ void setup_env (struct passwd *info) } (void) puts (_("No directory, logging in with HOME=/")); free (info->pw_dir); - info->pw_dir = xstrdup (temp_pw_dir); + info->pw_dir = xstrdup ("/"); } /* @@ -221,10 +218,8 @@ void setup_env (struct passwd *info) */ if ((NULL == info->pw_shell) || ('\0' == *info->pw_shell)) { - static char temp_pw_shell[] = SHELL; - free (info->pw_shell); - info->pw_shell = xstrdup (temp_pw_shell); + info->pw_shell = xstrdup (SHELL); } addenv ("SHELL", info->pw_shell); diff --git a/libmisc/shell.c b/lib/shell.c index 7c67500..25ef3e3 100644 --- a/libmisc/shell.c +++ b/lib/shell.c @@ -15,6 +15,9 @@ #include <errno.h> #include "prototypes.h" #include "defines.h" +#include "string/sprintf.h" + + extern char **newenvp; extern size_t newenvc; @@ -30,10 +33,10 @@ extern size_t newenvc; int shell (const char *file, /*@null@*/const char *arg, char *const envp[]) { - char arg0[1024]; - int err; + int err; + char arg0[1024]; - if (file == (char *) 0) { + if (file == NULL) { errno = EINVAL; return errno; } @@ -44,9 +47,8 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[]) * that. So, we determine the 0'th entry only if they * don't want to tell us what it is themselves. */ - if (arg == (char *) 0) { - (void) snprintf (arg0, sizeof arg0, "-%s", Basename (file)); - arg0[sizeof arg0 - 1] = '\0'; + if (arg == NULL) { + SNPRINTF(arg0, "-%s", Basename(file)); arg = arg0; } @@ -55,7 +57,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[]) * able to figure out what we are up to without too much * grief. */ - (void) execle (file, arg, (char *) 0, envp); + (void) execle (file, arg, (char *) NULL, envp); err = errno; if (access (file, R_OK|X_OK) == 0) { @@ -63,7 +65,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[]) * Assume this is a shell script (with no shebang). * Interpret it with /bin/sh */ - (void) execle (SHELL, "sh", "-", file, (char *)0, envp); + (void) execle (SHELL, "sh", "-", file, (char *) NULL, envp); err = errno; } @@ -72,7 +74,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[]) * how to execute this stupid shell, so I might as well give * up in disgust ... */ - (void) snprintf (arg0, sizeof arg0, _("Cannot execute %s"), file); + SNPRINTF(arg0, _("Cannot execute %s"), file); errno = err; perror (arg0); return err; diff --git a/libmisc/sub.c b/lib/sub.c index d30c4c7..d8e2447 100644 --- a/libmisc/sub.c +++ b/lib/sub.c @@ -15,8 +15,10 @@ #include <sys/types.h> #include "prototypes.h" #include "defines.h" +#define MAX_SUBROOT2 "maximum subsystem depth reached\n" #define BAD_SUBROOT2 "invalid root `%s' for user `%s'\n" #define NO_SUBROOT2 "no subsystem root `%s' for user `%s'\n" +#define MAX_DEPTH 1024 /* * subsystem - change to subsystem root * @@ -27,6 +29,18 @@ */ void subsystem (const struct passwd *pw) { + static int depth = 0; + + /* + * Prevent endless loop on misconfigured systems. + */ + if (++depth > MAX_DEPTH) { + printf (_("Maximum subsystem depth reached\n")); + SYSLOG ((LOG_WARN, MAX_SUBROOT2)); + closelog (); + exit (EXIT_FAILURE); + } + /* * The new root directory must begin with a "/" character. */ @@ -43,8 +57,8 @@ void subsystem (const struct passwd *pw) * must be able to change into it. */ - if ( (chdir (pw->pw_dir) != 0) - || (chroot (pw->pw_dir) != 0)) { + if ( (chroot (pw->pw_dir) != 0) + || (chdir ("/") != 0)) { (void) printf (_("Can't change root directory to '%s'\n"), pw->pw_dir); SYSLOG ((LOG_WARN, NO_SUBROOT2, pw->pw_dir, pw->pw_name)); diff --git a/libmisc/sulog.c b/lib/sulog.c index 3e95613..2ef22b2 100644 --- a/libmisc/sulog.c +++ b/lib/sulog.c @@ -64,7 +64,7 @@ void sulog (const char *tty, bool success, const char *oldname, const char *name /* Do not return if the group permission were raised. */ exit (EXIT_FAILURE); } - if (fp == (FILE *) 0) { + if (fp == NULL) { return; /* can't open or create logfile */ } diff --git a/libmisc/ttytype.c b/lib/ttytype.c index f72d957..a9fb0e8 100644 --- a/libmisc/ttytype.c +++ b/lib/ttytype.c @@ -34,16 +34,14 @@ void ttytype (const char *line) if (NULL == typefile) { return; } - if (access (typefile, F_OK) != 0) { - return; - } fp = fopen (typefile, "r"); if (NULL == fp) { - perror (typefile); + if (errno != ENOENT) + perror (typefile); return; } - while (fgets (buf, (int) sizeof buf, fp) == buf) { + while (fgets (buf, sizeof buf, fp) == buf) { if (buf[0] == '#') { continue; } @@ -34,7 +34,7 @@ fp = fopen (fname, "r"); if ( (NULL == fp) - || (fgets (tzbuf, (int) sizeof (tzbuf), fp) == NULL)) { + || (fgets (tzbuf, sizeof (tzbuf), fp) == NULL)) { def_tz = getdef_str ("ENV_TZ"); if ((NULL == def_tz) || ('/' == def_tz[0])) { def_tz = "TZ=CST6CDT"; @@ -42,7 +42,8 @@ strcpy (tzbuf, def_tz); } else { - tzbuf[strlen (tzbuf) - 1] = '\0'; + /* Remove optional trailing '\n'. */ + tzbuf[strcspn (tzbuf, "\n")] = '\0'; } if (NULL != fp) { @@ -52,6 +53,6 @@ return tzbuf; } #else /* !USE_PAM */ -extern int errno; /* warning: ANSI C forbids an empty source file */ +extern int ISO_C_forbids_an_empty_translation_unit; #endif /* !USE_PAM */ diff --git a/libmisc/ulimit.c b/lib/ulimit.c index e331d46..45a184a 100644 --- a/libmisc/ulimit.c +++ b/lib/ulimit.c @@ -11,36 +11,18 @@ #ident "$Id$" -#if HAVE_ULIMIT_H -#include <ulimit.h> -#ifndef UL_SETFSIZE -#ifdef UL_SFILLIM -#define UL_SETFSIZE UL_SFILLIM -#else -#define UL_SETFSIZE 2 -#endif -#endif -#elif HAVE_SYS_RESOURCE_H -#include <sys/time.h> /* for struct timeval on sunos4 */ -/* XXX - is the above ok or should it be <time.h> on ultrix? */ +#include <sys/time.h> #include <sys/resource.h> -#endif #include "prototypes.h" int set_filesize_limit (int blocks) { int ret = -1; -#if HAVE_ULIMIT_H - if (ulimit (UL_SETFSIZE, blocks) != -1) { - ret = 0; - } -#elif defined(RLIMIT_FSIZE) struct rlimit rlimit_fsize; rlimit_fsize.rlim_cur = 512L * blocks; rlimit_fsize.rlim_max = rlimit_fsize.rlim_cur; ret = setrlimit (RLIMIT_FSIZE, &rlimit_fsize); -#endif return ret; } diff --git a/libmisc/user_busy.c b/lib/user_busy.c index c03feb2..a622376 100644 --- a/libmisc/user_busy.c +++ b/lib/user_busy.c @@ -23,6 +23,8 @@ #include "subordinateio.h" #endif /* ENABLE_SUBIDS */ #include "shadowlog.h" +#include "string/sprintf.h" + #ifdef __linux__ static int check_status (const char *name, const char *sname, uid_t uid); @@ -32,7 +34,7 @@ static int user_busy_utmp (const char *name); #endif /* !__linux__ */ /* - * user_busy - check if an user if currently running processes + * user_busy - check if a user is currently running processes */ int user_busy (const char *name, uid_t uid) { @@ -43,26 +45,21 @@ int user_busy (const char *name, uid_t uid) /* On Linux, directly parse /proc */ return user_busy_processes (name, uid); #else /* !__linux__ */ - /* If we cannot rely on /proc, check is there is a record in utmp + /* If we cannot rely on /proc, check if there is a record in utmp * indicating that the user is still logged in */ return user_busy_utmp (name); #endif /* !__linux__ */ } + #ifndef __linux__ -static int user_busy_utmp (const char *name) +static int +user_busy_utmp(const char *name) { -#ifdef USE_UTMPX - struct utmpx *utent; + struct utmpx *utent; - setutxent (); - while ((utent = getutxent ()) != NULL) -#else /* !USE_UTMPX */ - struct utmp *utent; - - setutent (); - while ((utent = getutent ()) != NULL) -#endif /* !USE_UTMPX */ + setutxent(); + while ((utent = getutxent()) != NULL) { if (utent->ut_type != USER_PROCESS) { continue; @@ -84,17 +81,18 @@ static int user_busy_utmp (const char *name) } #endif /* !__linux__ */ + #ifdef __linux__ #ifdef ENABLE_SUBIDS #define in_parentuid_range(uid) ((uid) >= parentuid && (uid) < parentuid + range) static int different_namespace (const char *sname) { /* 41: /proc/xxxxxxxxxx/task/xxxxxxxxxx/ns/user + \0 */ - char path[41]; - char buf[512], buf2[512]; - ssize_t llen1, llen2; + char path[41]; + char buf[512], buf2[512]; + ssize_t llen1, llen2; - snprintf (path, 41, "/proc/%s/ns/user", sname); + SNPRINTF(path, "/proc/%s/ns/user", sname); if ((llen1 = readlink (path, buf, sizeof(buf))) == -1) return 0; @@ -113,11 +111,11 @@ static int different_namespace (const char *sname) static int check_status (const char *name, const char *sname, uid_t uid) { /* 40: /proc/xxxxxxxxxx/task/xxxxxxxxxx/status + \0 */ - char status[40]; - char line[1024]; - FILE *sfile; + char status[40]; + char line[1024]; + FILE *sfile; - snprintf (status, 40, "/proc/%s/status", sname); + SNPRINTF(status, "/proc/%s/status", sname); sfile = fopen (status, "r"); if (NULL == sfile) { @@ -158,16 +156,16 @@ static int check_status (const char *name, const char *sname, uid_t uid) static int user_busy_processes (const char *name, uid_t uid) { - DIR *proc; - struct dirent *ent; - char *tmp_d_name; - pid_t pid; - DIR *task_dir; + DIR *proc; + DIR *task_dir; + char *tmp_d_name; /* 22: /proc/xxxxxxxxxx/task + \0 */ - char task_path[22]; - char root_path[22]; - struct stat sbroot; - struct stat sbroot_process; + char task_path[22]; + char root_path[22]; + pid_t pid; + struct stat sbroot; + struct stat sbroot_process; + struct dirent *ent; #ifdef ENABLE_SUBIDS sub_uid_open (O_RDONLY); @@ -207,13 +205,12 @@ static int user_busy_processes (const char *name, uid_t uid) } /* Check if this is a valid PID */ - if (get_pid (tmp_d_name, &pid) == 0) { + if (get_pid(tmp_d_name, &pid) == -1) { continue; } /* Check if the process is in our chroot */ - snprintf (root_path, 22, "/proc/%lu/root", (unsigned long) pid); - root_path[21] = '\0'; + SNPRINTF(root_path, "/proc/%lu/root", (unsigned long) pid); if (stat (root_path, &sbroot_process) != 0) { continue; } @@ -233,13 +230,12 @@ static int user_busy_processes (const char *name, uid_t uid) return 1; } - snprintf (task_path, 22, "/proc/%lu/task", (unsigned long) pid); - task_path[21] = '\0'; + SNPRINTF(task_path, "/proc/%lu/task", (unsigned long) pid); task_dir = opendir (task_path); if (task_dir != NULL) { while ((ent = readdir (task_dir)) != NULL) { pid_t tid; - if (get_pid (ent->d_name, &tid) == 0) { + if (get_pid(ent->d_name, &tid) == -1) { continue; } if (tid == pid) { diff --git a/libmisc/valid.c b/lib/valid.c index 326635f..326635f 100644 --- a/libmisc/valid.c +++ b/lib/valid.c diff --git a/libmisc/xgetXXbyYY.c b/lib/xgetXXbyYY.c index 6a3f969..7d5e914 100644 --- a/libmisc/xgetXXbyYY.c +++ b/lib/xgetXXbyYY.c @@ -23,13 +23,15 @@ * Two important function classes that fall into this category are * getpwnam(3) and syslog(3). * - * This file provide wrapper to the getpwnam or getpwnam_r functions. + * This file provides wrapper to the name or name_r functions. */ #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> + +#include "alloc.h" #include "prototypes.h" #include "shadowlog.h" @@ -50,46 +52,38 @@ /* we have to start with something */ size_t length = 0x100; - result = malloc(sizeof(LOOKUP_TYPE)); + result = MALLOC(1, LOOKUP_TYPE); if (NULL == result) { - fprintf (log_get_logfd(), _("%s: out of memory\n"), - "x" STRINGIZE(FUNCTION_NAME)); - exit (13); + goto oom; } while (true) { int status; LOOKUP_TYPE *resbuf = NULL; - buffer = (char *)realloc (buffer, length); - if (NULL == buffer) { - fprintf (log_get_logfd(), _("%s: out of memory\n"), - "x" STRINGIZE(FUNCTION_NAME)); - exit (13); - } + buffer = XREALLOC(buffer, length, char); status = REENTRANT_NAME(ARG_NAME, result, buffer, length, &resbuf); if ((0 == status) && (resbuf == result)) { /* Build a result structure that can be freed by * the shadow *_free functions. */ LOOKUP_TYPE *ret_result = DUP_FUNCTION(result); + if (NULL == ret_result) { + goto oom; + } free(buffer); free(result); return ret_result; } if (ERANGE != status) { - free (buffer); - free (result); - return NULL; + break; } - if (length <= ((size_t)-1 / 4)) { - length *= 4; - } else if (length == (size_t) -1) { + if (length == SIZE_MAX) { break; - } else { - length = (size_t) -1; } + + length = (length <= SIZE_MAX / 4) ? length * 4 : SIZE_MAX; } free(buffer); @@ -109,13 +103,16 @@ if (result) { result = DUP_FUNCTION(result); if (NULL == result) { - fprintf (log_get_logfd(), _("%s: out of memory\n"), - "x" STRINGIZE(FUNCTION_NAME)); - exit (13); + goto oom; } } return result; #endif + +oom: + fprintf (log_get_logfd(), _("%s: out of memory\n"), + "x" STRINGIZE(FUNCTION_NAME)); + exit (13); } diff --git a/libmisc/xgetgrgid.c b/lib/xgetgrgid.c index fe99929..6419196 100644 --- a/libmisc/xgetgrgid.c +++ b/lib/xgetgrgid.c @@ -23,7 +23,7 @@ * Two important function classes that fall into this category are * getpwnam(3) and syslog(3). * - * This file provide wrapper to the getpwnam or getpwnam_r functions. + * This file provides wrapper to the getgrgid or getgrgid_r functions. */ #include <config.h> @@ -35,7 +35,7 @@ #define ARG_TYPE gid_t #define ARG_NAME gid #define DUP_FUNCTION __gr_dup -#define HAVE_FUNCTION_R (defined HAVE_GETGRGID_R) +#define HAVE_FUNCTION_R 1 #include "xgetXXbyYY.c" diff --git a/libmisc/xgetgrnam.c b/lib/xgetgrnam.c index 66d6f93..35ad9ee 100644 --- a/libmisc/xgetgrnam.c +++ b/lib/xgetgrnam.c @@ -23,7 +23,7 @@ * Two important function classes that fall into this category are * getpwnam(3) and syslog(3). * - * This file provide wrapper to the getpwnam or getpwnam_r functions. + * This file provides wrapper to the getgrnam or getgrnam_r functions. */ #include <config.h> @@ -35,7 +35,7 @@ #define ARG_TYPE const char * #define ARG_NAME name #define DUP_FUNCTION __gr_dup -#define HAVE_FUNCTION_R (defined HAVE_GETGRNAM_R) +#define HAVE_FUNCTION_R 1 #include "xgetXXbyYY.c" diff --git a/libmisc/xgetpwnam.c b/lib/xgetpwnam.c index 74eb972..4387e79 100644 --- a/libmisc/xgetpwnam.c +++ b/lib/xgetpwnam.c @@ -23,7 +23,7 @@ * Two important function classes that fall into this category are * getpwnam(3) and syslog(3). * - * This file provide wrapper to the getpwnam or getpwnam_r functions. + * This file provides wrapper to the getpwnam or getpwnam_r functions. */ #include <config.h> @@ -35,7 +35,7 @@ #define ARG_TYPE const char * #define ARG_NAME name #define DUP_FUNCTION __pw_dup -#define HAVE_FUNCTION_R (defined HAVE_GETPWNAM_R) +#define HAVE_FUNCTION_R 1 #include "xgetXXbyYY.c" diff --git a/libmisc/xgetpwuid.c b/lib/xgetpwuid.c index 23b2d0c..d663a42 100644 --- a/libmisc/xgetpwuid.c +++ b/lib/xgetpwuid.c @@ -23,7 +23,7 @@ * Two important function classes that fall into this category are * getpwnam(3) and syslog(3). * - * This file provide wrapper to the getpwnam or getpwnam_r functions. + * This file provides wrapper to the getpwuid or getpwuid_r functions. */ #include <config.h> @@ -35,7 +35,7 @@ #define ARG_TYPE uid_t #define ARG_NAME uid #define DUP_FUNCTION __pw_dup -#define HAVE_FUNCTION_R (defined HAVE_GETPWUID_R) +#define HAVE_FUNCTION_R 1 #include "xgetXXbyYY.c" diff --git a/libmisc/xgetspnam.c b/lib/xgetspnam.c index 148185f..ebda94b 100644 --- a/libmisc/xgetspnam.c +++ b/lib/xgetspnam.c @@ -23,7 +23,7 @@ * Two important function classes that fall into this category are * getpwnam(3) and syslog(3). * - * This file provide wrapper to the getpwnam or getpwnam_r functions. + * This file provides wrapper to the getspnam or getspnam_r functions. */ #include <config.h> diff --git a/libmisc/.indent.pro b/libmisc/.indent.pro deleted file mode 100644 index fe572bb..0000000 --- a/libmisc/.indent.pro +++ /dev/null @@ -1,5 +0,0 @@ --kr --i8 --bad --pcs --l80 diff --git a/libmisc/Makefile.am b/libmisc/Makefile.am deleted file mode 100644 index 3d319cd..0000000 --- a/libmisc/Makefile.am +++ /dev/null @@ -1,80 +0,0 @@ - -EXTRA_DIST = .indent.pro xgetXXbyYY.c - -AM_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir) $(ECONF_CPPFLAGS) - -noinst_LTLIBRARIES = libmisc.la - -libmisc_la_SOURCES = \ - addgrps.c \ - age.c \ - audit_help.c \ - basename.c \ - chkname.c \ - chkname.h \ - chowndir.c \ - chowntty.c \ - cleanup.c \ - cleanup_group.c \ - cleanup_user.c \ - console.c \ - copydir.c \ - date_to_str.c \ - entry.c \ - env.c \ - failure.c \ - failure.h \ - find_new_gid.c \ - find_new_uid.c \ - find_new_sub_gids.c \ - find_new_sub_uids.c \ - getdate.h \ - getdate.y \ - getgr_nam_gid.c \ - getrange.c \ - gettime.c \ - hushed.c \ - idmapping.h \ - idmapping.c \ - isexpired.c \ - limits.c \ - list.c log.c \ - loginprompt.c \ - mail.c \ - motd.c \ - myname.c \ - obscure.c \ - pam_pass.c \ - pam_pass_non_interactive.c \ - prefix_flag.c \ - pwd2spwd.c \ - pwdcheck.c \ - pwd_init.c \ - remove_tree.c \ - rlogin.c \ - root_flag.c \ - salt.c \ - setugid.c \ - setupenv.c \ - shell.c \ - strtoday.c \ - sub.c \ - sulog.c \ - ttytype.c \ - tz.c \ - ulimit.c \ - user_busy.c \ - utmp.c \ - valid.c \ - xgetpwnam.c \ - xgetpwuid.c \ - xgetgrnam.c \ - xgetgrgid.c \ - xgetspnam.c \ - xmalloc.c \ - yesno.c - -if WITH_BTRFS -libmisc_la_SOURCES += btrfs.c -endif - diff --git a/libmisc/Makefile.in b/libmisc/Makefile.in deleted file mode 100644 index 2defd8e..0000000 --- a/libmisc/Makefile.in +++ /dev/null @@ -1,927 +0,0 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994-2021 Free Software Foundation, Inc. - -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -VPATH = @srcdir@ -am__is_gnu_make = { \ - if test -z '$(MAKELEVEL)'; then \ - false; \ - elif test -n '$(MAKE_HOST)'; then \ - true; \ - elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ - true; \ - else \ - false; \ - fi; \ -} -am__make_running_with_option = \ - case $${target_option-} in \ - ?) ;; \ - *) echo "am__make_running_with_option: internal error: invalid" \ - "target option '$${target_option-}' specified" >&2; \ - exit 1;; \ - esac; \ - has_opt=no; \ - sane_makeflags=$$MAKEFLAGS; \ - if $(am__is_gnu_make); then \ - sane_makeflags=$$MFLAGS; \ - else \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - bs=\\; \ - sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ - | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ - esac; \ - fi; \ - skip_next=no; \ - strip_trailopt () \ - { \ - flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ - }; \ - for flg in $$sane_makeflags; do \ - test $$skip_next = yes && { skip_next=no; continue; }; \ - case $$flg in \ - *=*|--*) continue;; \ - -*I) strip_trailopt 'I'; skip_next=yes;; \ - -*I?*) strip_trailopt 'I';; \ - -*O) strip_trailopt 'O'; skip_next=yes;; \ - -*O?*) strip_trailopt 'O';; \ - -*l) strip_trailopt 'l'; skip_next=yes;; \ - -*l?*) strip_trailopt 'l';; \ - -[dEDm]) skip_next=yes;; \ - -[JT]) skip_next=yes;; \ - esac; \ - case $$flg in \ - *$$target_option*) has_opt=yes; break;; \ - esac; \ - done; \ - test $$has_opt = yes -am__make_dryrun = (target_option=n; $(am__make_running_with_option)) -am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) -pkgdatadir = $(datadir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkglibexecdir = $(libexecdir)/@PACKAGE@ -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -@WITH_BTRFS_TRUE@am__append_1 = btrfs.c -subdir = libmisc -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \ - $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/intlmacosx.m4 \ - $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ - $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \ - $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/acinclude.m4 \ - $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -CONFIG_CLEAN_VPATH_FILES = -LTLIBRARIES = $(noinst_LTLIBRARIES) -libmisc_la_LIBADD = -am__libmisc_la_SOURCES_DIST = addgrps.c age.c audit_help.c basename.c \ - chkname.c chkname.h chowndir.c chowntty.c cleanup.c \ - cleanup_group.c cleanup_user.c console.c copydir.c \ - date_to_str.c entry.c env.c failure.c failure.h find_new_gid.c \ - find_new_uid.c find_new_sub_gids.c find_new_sub_uids.c \ - getdate.h getdate.y getgr_nam_gid.c getrange.c gettime.c \ - hushed.c idmapping.h idmapping.c isexpired.c limits.c list.c \ - log.c loginprompt.c mail.c motd.c myname.c obscure.c \ - pam_pass.c pam_pass_non_interactive.c prefix_flag.c pwd2spwd.c \ - pwdcheck.c pwd_init.c remove_tree.c rlogin.c root_flag.c \ - salt.c setugid.c setupenv.c shell.c strtoday.c sub.c sulog.c \ - ttytype.c tz.c ulimit.c user_busy.c utmp.c valid.c xgetpwnam.c \ - xgetpwuid.c xgetgrnam.c xgetgrgid.c xgetspnam.c xmalloc.c \ - yesno.c btrfs.c -@WITH_BTRFS_TRUE@am__objects_1 = btrfs.lo -am_libmisc_la_OBJECTS = addgrps.lo age.lo audit_help.lo basename.lo \ - chkname.lo chowndir.lo chowntty.lo cleanup.lo cleanup_group.lo \ - cleanup_user.lo console.lo copydir.lo date_to_str.lo entry.lo \ - env.lo failure.lo find_new_gid.lo find_new_uid.lo \ - find_new_sub_gids.lo find_new_sub_uids.lo getdate.lo \ - getgr_nam_gid.lo getrange.lo gettime.lo hushed.lo idmapping.lo \ - isexpired.lo limits.lo list.lo log.lo loginprompt.lo mail.lo \ - motd.lo myname.lo obscure.lo pam_pass.lo \ - pam_pass_non_interactive.lo prefix_flag.lo pwd2spwd.lo \ - pwdcheck.lo pwd_init.lo remove_tree.lo rlogin.lo root_flag.lo \ - salt.lo setugid.lo setupenv.lo shell.lo strtoday.lo sub.lo \ - sulog.lo ttytype.lo tz.lo ulimit.lo user_busy.lo utmp.lo \ - valid.lo xgetpwnam.lo xgetpwuid.lo xgetgrnam.lo xgetgrgid.lo \ - xgetspnam.lo xmalloc.lo yesno.lo $(am__objects_1) -libmisc_la_OBJECTS = $(am_libmisc_la_OBJECTS) -AM_V_lt = $(am__v_lt_@AM_V@) -am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) -am__v_lt_0 = --silent -am__v_lt_1 = -AM_V_P = $(am__v_P_@AM_V@) -am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) -am__v_P_0 = false -am__v_P_1 = : -AM_V_GEN = $(am__v_GEN_@AM_V@) -am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) -am__v_GEN_0 = @echo " GEN " $@; -am__v_GEN_1 = -AM_V_at = $(am__v_at_@AM_V@) -am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) -am__v_at_0 = @ -am__v_at_1 = -DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__maybe_remake_depfiles = depfiles -am__depfiles_remade = ./$(DEPDIR)/addgrps.Plo ./$(DEPDIR)/age.Plo \ - ./$(DEPDIR)/audit_help.Plo ./$(DEPDIR)/basename.Plo \ - ./$(DEPDIR)/btrfs.Plo ./$(DEPDIR)/chkname.Plo \ - ./$(DEPDIR)/chowndir.Plo ./$(DEPDIR)/chowntty.Plo \ - ./$(DEPDIR)/cleanup.Plo ./$(DEPDIR)/cleanup_group.Plo \ - ./$(DEPDIR)/cleanup_user.Plo ./$(DEPDIR)/console.Plo \ - ./$(DEPDIR)/copydir.Plo ./$(DEPDIR)/date_to_str.Plo \ - ./$(DEPDIR)/entry.Plo ./$(DEPDIR)/env.Plo \ - ./$(DEPDIR)/failure.Plo ./$(DEPDIR)/find_new_gid.Plo \ - ./$(DEPDIR)/find_new_sub_gids.Plo \ - ./$(DEPDIR)/find_new_sub_uids.Plo ./$(DEPDIR)/find_new_uid.Plo \ - ./$(DEPDIR)/getdate.Plo ./$(DEPDIR)/getgr_nam_gid.Plo \ - ./$(DEPDIR)/getrange.Plo ./$(DEPDIR)/gettime.Plo \ - ./$(DEPDIR)/hushed.Plo ./$(DEPDIR)/idmapping.Plo \ - ./$(DEPDIR)/isexpired.Plo ./$(DEPDIR)/limits.Plo \ - ./$(DEPDIR)/list.Plo ./$(DEPDIR)/log.Plo \ - ./$(DEPDIR)/loginprompt.Plo ./$(DEPDIR)/mail.Plo \ - ./$(DEPDIR)/motd.Plo ./$(DEPDIR)/myname.Plo \ - ./$(DEPDIR)/obscure.Plo ./$(DEPDIR)/pam_pass.Plo \ - ./$(DEPDIR)/pam_pass_non_interactive.Plo \ - ./$(DEPDIR)/prefix_flag.Plo ./$(DEPDIR)/pwd2spwd.Plo \ - ./$(DEPDIR)/pwd_init.Plo ./$(DEPDIR)/pwdcheck.Plo \ - ./$(DEPDIR)/remove_tree.Plo ./$(DEPDIR)/rlogin.Plo \ - ./$(DEPDIR)/root_flag.Plo ./$(DEPDIR)/salt.Plo \ - ./$(DEPDIR)/setugid.Plo ./$(DEPDIR)/setupenv.Plo \ - ./$(DEPDIR)/shell.Plo ./$(DEPDIR)/strtoday.Plo \ - ./$(DEPDIR)/sub.Plo ./$(DEPDIR)/sulog.Plo \ - ./$(DEPDIR)/ttytype.Plo ./$(DEPDIR)/tz.Plo \ - ./$(DEPDIR)/ulimit.Plo ./$(DEPDIR)/user_busy.Plo \ - ./$(DEPDIR)/utmp.Plo ./$(DEPDIR)/valid.Plo \ - ./$(DEPDIR)/xgetgrgid.Plo ./$(DEPDIR)/xgetgrnam.Plo \ - ./$(DEPDIR)/xgetpwnam.Plo ./$(DEPDIR)/xgetpwuid.Plo \ - ./$(DEPDIR)/xgetspnam.Plo ./$(DEPDIR)/xmalloc.Plo \ - ./$(DEPDIR)/yesno.Plo -am__mv = mv -f -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ - $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CFLAGS) $(CFLAGS) -AM_V_CC = $(am__v_CC_@AM_V@) -am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) -am__v_CC_0 = @echo " CC " $@; -am__v_CC_1 = -CCLD = $(CC) -LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(AM_LDFLAGS) $(LDFLAGS) -o $@ -AM_V_CCLD = $(am__v_CCLD_@AM_V@) -am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) -am__v_CCLD_0 = @echo " CCLD " $@; -am__v_CCLD_1 = -@MAINTAINER_MODE_FALSE@am__skipyacc = test -f $@ || -am__yacc_c2h = sed -e s/cc$$/hh/ -e s/cpp$$/hpp/ -e s/cxx$$/hxx/ \ - -e s/c++$$/h++/ -e s/c$$/h/ -YACCCOMPILE = $(YACC) $(AM_YFLAGS) $(YFLAGS) -LTYACCCOMPILE = $(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=compile $(YACC) $(AM_YFLAGS) $(YFLAGS) -AM_V_YACC = $(am__v_YACC_@AM_V@) -am__v_YACC_ = $(am__v_YACC_@AM_DEFAULT_V@) -am__v_YACC_0 = @echo " YACC " $@; -am__v_YACC_1 = -YLWRAP = $(top_srcdir)/ylwrap -SOURCES = $(libmisc_la_SOURCES) -DIST_SOURCES = $(am__libmisc_la_SOURCES_DIST) -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac -am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) -# Read a list of newline-separated strings from the standard input, -# and print each of them once, without duplicates. Input order is -# *not* preserved. -am__uniquify_input = $(AWK) '\ - BEGIN { nonempty = 0; } \ - { items[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in items) print i; }; } \ -' -# Make sure the list of sources is unique. This is necessary because, -# e.g., the same source file might be shared among _SOURCES variables -# for different programs/libraries. -am__define_uniq_tagged_files = \ - list='$(am__tagged_files)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | $(am__uniquify_input)` -am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \ - $(top_srcdir)/ylwrap getdate.c -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -AMTAR = @AMTAR@ -AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ -AR = @AR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CSCOPE = @CSCOPE@ -CTAGS = @CTAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -DLLTOOL = @DLLTOOL@ -DSYMUTIL = @DSYMUTIL@ -DUMPBIN = @DUMPBIN@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -ECONF_CPPFLAGS = @ECONF_CPPFLAGS@ -EGREP = @EGREP@ -ETAGS = @ETAGS@ -EXEEXT = @EXEEXT@ -FGREP = @FGREP@ -GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ -GMSGFMT = @GMSGFMT@ -GMSGFMT_015 = @GMSGFMT_015@ -GREP = @GREP@ -GROUP_NAME_MAX_LENGTH = @GROUP_NAME_MAX_LENGTH@ -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -INTLLIBS = @INTLLIBS@ -INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ -LD = @LD@ -LDFLAGS = @LDFLAGS@ -LIBACL = @LIBACL@ -LIBATTR = @LIBATTR@ -LIBAUDIT = @LIBAUDIT@ -LIBCRACK = @LIBCRACK@ -LIBCRYPT = @LIBCRYPT@ -LIBECONF = @LIBECONF@ -LIBICONV = @LIBICONV@ -LIBINTL = @LIBINTL@ -LIBMD = @LIBMD@ -LIBOBJS = @LIBOBJS@ -LIBPAM = @LIBPAM@ -LIBS = @LIBS@ -LIBSELINUX = @LIBSELINUX@ -LIBSEMANAGE = @LIBSEMANAGE@ -LIBSKEY = @LIBSKEY@ -LIBSUBID_ABI = @LIBSUBID_ABI@ -LIBSUBID_ABI_MAJOR = @LIBSUBID_ABI_MAJOR@ -LIBSUBID_ABI_MICRO = @LIBSUBID_ABI_MICRO@ -LIBSUBID_ABI_MINOR = @LIBSUBID_ABI_MINOR@ -LIBTCB = @LIBTCB@ -LIBTOOL = @LIBTOOL@ -LIPO = @LIPO@ -LIYESCRYPT = @LIYESCRYPT@ -LN_S = @LN_S@ -LTLIBICONV = @LTLIBICONV@ -LTLIBINTL = @LTLIBINTL@ -LTLIBOBJS = @LTLIBOBJS@ -LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ -MAINT = @MAINT@ -MAKEINFO = @MAKEINFO@ -MANIFEST_TOOL = @MANIFEST_TOOL@ -MKDIR_P = @MKDIR_P@ -MSGFMT = @MSGFMT@ -MSGFMT_015 = @MSGFMT_015@ -MSGMERGE = @MSGMERGE@ -NM = @NM@ -NMEDIT = @NMEDIT@ -OBJDUMP = @OBJDUMP@ -OBJEXT = @OBJEXT@ -OTOOL = @OTOOL@ -OTOOL64 = @OTOOL64@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_URL = @PACKAGE_URL@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -POSUB = @POSUB@ -RANLIB = @RANLIB@ -SED = @SED@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -USE_NLS = @USE_NLS@ -VENDORDIR = @VENDORDIR@ -VERSION = @VERSION@ -XGETTEXT = @XGETTEXT@ -XGETTEXT_015 = @XGETTEXT_015@ -XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ -XMLCATALOG = @XMLCATALOG@ -XML_CATALOG_FILE = @XML_CATALOG_FILE@ -XSLTPROC = @XSLTPROC@ -YACC = @YACC@ -YFLAGS = @YFLAGS@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_AR = @ac_ct_AR@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -builddir = @builddir@ -capcmd = @capcmd@ -datadir = @datadir@ -datarootdir = @datarootdir@ -docdir = @docdir@ -dvidir = @dvidir@ -exec_prefix = @exec_prefix@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -htmldir = @htmldir@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -runstatedir = @runstatedir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -top_build_prefix = @top_build_prefix@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -EXTRA_DIST = .indent.pro xgetXXbyYY.c -AM_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir) $(ECONF_CPPFLAGS) -noinst_LTLIBRARIES = libmisc.la -libmisc_la_SOURCES = addgrps.c age.c audit_help.c basename.c chkname.c \ - chkname.h chowndir.c chowntty.c cleanup.c cleanup_group.c \ - cleanup_user.c console.c copydir.c date_to_str.c entry.c env.c \ - failure.c failure.h find_new_gid.c find_new_uid.c \ - find_new_sub_gids.c find_new_sub_uids.c getdate.h getdate.y \ - getgr_nam_gid.c getrange.c gettime.c hushed.c idmapping.h \ - idmapping.c isexpired.c limits.c list.c log.c loginprompt.c \ - mail.c motd.c myname.c obscure.c pam_pass.c \ - pam_pass_non_interactive.c prefix_flag.c pwd2spwd.c pwdcheck.c \ - pwd_init.c remove_tree.c rlogin.c root_flag.c salt.c setugid.c \ - setupenv.c shell.c strtoday.c sub.c sulog.c ttytype.c tz.c \ - ulimit.c user_busy.c utmp.c valid.c xgetpwnam.c xgetpwuid.c \ - xgetgrnam.c xgetgrgid.c xgetspnam.c xmalloc.c yesno.c \ - $(am__append_1) -all: all-am - -.SUFFIXES: -.SUFFIXES: .c .lo .o .obj .y -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ - && { if test -f $@; then exit 0; else break; fi; }; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libmisc/Makefile'; \ - $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --foreign libmisc/Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(am__aclocal_m4_deps): - -clean-noinstLTLIBRARIES: - -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) - @list='$(noinst_LTLIBRARIES)'; \ - locs=`for p in $$list; do echo $$p; done | \ - sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ - sort -u`; \ - test -z "$$locs" || { \ - echo rm -f $${locs}; \ - rm -f $${locs}; \ - } - -libmisc.la: $(libmisc_la_OBJECTS) $(libmisc_la_DEPENDENCIES) $(EXTRA_libmisc_la_DEPENDENCIES) - $(AM_V_CCLD)$(LINK) $(libmisc_la_OBJECTS) $(libmisc_la_LIBADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/addgrps.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/age.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audit_help.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basename.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/btrfs.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chkname.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chowndir.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chowntty.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cleanup.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cleanup_group.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cleanup_user.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/console.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/copydir.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/date_to_str.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/entry.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/env.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/failure.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/find_new_gid.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/find_new_sub_gids.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/find_new_sub_uids.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/find_new_uid.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getdate.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getgr_nam_gid.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getrange.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gettime.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hushed.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/idmapping.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isexpired.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/limits.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loginprompt.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mail.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/motd.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/myname.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/obscure.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_pass.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pam_pass_non_interactive.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prefix_flag.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pwd2spwd.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pwd_init.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pwdcheck.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/remove_tree.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rlogin.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/root_flag.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/salt.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setugid.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setupenv.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shell.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strtoday.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sub.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sulog.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttytype.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tz.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ulimit.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/user_busy.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utmp.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/valid.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xgetgrgid.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xgetgrnam.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xgetpwnam.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xgetpwuid.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xgetspnam.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmalloc.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/yesno.Plo@am__quote@ # am--include-marker - -$(am__depfiles_remade): - @$(MKDIR_P) $(@D) - @echo '# dummy' >$@-t && $(am__mv) $@-t $@ - -am--depfiles: $(am__depfiles_remade) - -.c.o: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< - -.c.obj: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -.c.lo: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< - -.y.c: - $(AM_V_YACC)$(am__skipyacc) $(SHELL) $(YLWRAP) $< y.tab.c $@ y.tab.h `echo $@ | $(am__yacc_c2h)` y.output $*.output -- $(YACCCOMPILE) - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -ID: $(am__tagged_files) - $(am__define_uniq_tagged_files); mkid -fID $$unique -tags: tags-am -TAGS: tags - -tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) - set x; \ - here=`pwd`; \ - $(am__define_uniq_tagged_files); \ - shift; \ - if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - if test $$# -gt 0; then \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - "$$@" $$unique; \ - else \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$unique; \ - fi; \ - fi -ctags: ctags-am - -CTAGS: ctags -ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) - $(am__define_uniq_tagged_files); \ - test -z "$(CTAGS_ARGS)$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && $(am__cd) $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) "$$here" -cscopelist: cscopelist-am - -cscopelist-am: $(am__tagged_files) - list='$(am__tagged_files)'; \ - case "$(srcdir)" in \ - [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ - *) sdir=$(subdir)/$(srcdir) ;; \ - esac; \ - for i in $$list; do \ - if test -f "$$i"; then \ - echo "$(subdir)/$$i"; \ - else \ - echo "$$sdir/$$i"; \ - fi; \ - done >> $(top_builddir)/cscope.files - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -distdir: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) distdir-am - -distdir-am: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - list='$(DISTFILES)'; \ - dist_files=`for file in $$list; do echo $$file; done | \ - sed -e "s|^$$srcdirstrip/||;t" \ - -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ - case $$dist_files in \ - */*) $(MKDIR_P) `echo "$$dist_files" | \ - sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ - sort -u` ;; \ - esac; \ - for file in $$dist_files; do \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - if test -d $$d/$$file; then \ - dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test -d "$(distdir)/$$file"; then \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ - else \ - test -f "$(distdir)/$$file" \ - || cp -p $$d/$$file "$(distdir)/$$file" \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(LTLIBRARIES) -installdirs: -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - if test -z '$(STRIP)'; then \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - install; \ - else \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ - fi -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." - -rm -f getdate.c -clean: clean-am - -clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ - mostlyclean-am - -distclean: distclean-am - -rm -f ./$(DEPDIR)/addgrps.Plo - -rm -f ./$(DEPDIR)/age.Plo - -rm -f ./$(DEPDIR)/audit_help.Plo - -rm -f ./$(DEPDIR)/basename.Plo - -rm -f ./$(DEPDIR)/btrfs.Plo - -rm -f ./$(DEPDIR)/chkname.Plo - -rm -f ./$(DEPDIR)/chowndir.Plo - -rm -f ./$(DEPDIR)/chowntty.Plo - -rm -f ./$(DEPDIR)/cleanup.Plo - -rm -f ./$(DEPDIR)/cleanup_group.Plo - -rm -f ./$(DEPDIR)/cleanup_user.Plo - -rm -f ./$(DEPDIR)/console.Plo - -rm -f ./$(DEPDIR)/copydir.Plo - -rm -f ./$(DEPDIR)/date_to_str.Plo - -rm -f ./$(DEPDIR)/entry.Plo - -rm -f ./$(DEPDIR)/env.Plo - -rm -f ./$(DEPDIR)/failure.Plo - -rm -f ./$(DEPDIR)/find_new_gid.Plo - -rm -f ./$(DEPDIR)/find_new_sub_gids.Plo - -rm -f ./$(DEPDIR)/find_new_sub_uids.Plo - -rm -f ./$(DEPDIR)/find_new_uid.Plo - -rm -f ./$(DEPDIR)/getdate.Plo - -rm -f ./$(DEPDIR)/getgr_nam_gid.Plo - -rm -f ./$(DEPDIR)/getrange.Plo - -rm -f ./$(DEPDIR)/gettime.Plo - -rm -f ./$(DEPDIR)/hushed.Plo - -rm -f ./$(DEPDIR)/idmapping.Plo - -rm -f ./$(DEPDIR)/isexpired.Plo - -rm -f ./$(DEPDIR)/limits.Plo - -rm -f ./$(DEPDIR)/list.Plo - -rm -f ./$(DEPDIR)/log.Plo - -rm -f ./$(DEPDIR)/loginprompt.Plo - -rm -f ./$(DEPDIR)/mail.Plo - -rm -f ./$(DEPDIR)/motd.Plo - -rm -f ./$(DEPDIR)/myname.Plo - -rm -f ./$(DEPDIR)/obscure.Plo - -rm -f ./$(DEPDIR)/pam_pass.Plo - -rm -f ./$(DEPDIR)/pam_pass_non_interactive.Plo - -rm -f ./$(DEPDIR)/prefix_flag.Plo - -rm -f ./$(DEPDIR)/pwd2spwd.Plo - -rm -f ./$(DEPDIR)/pwd_init.Plo - -rm -f ./$(DEPDIR)/pwdcheck.Plo - -rm -f ./$(DEPDIR)/remove_tree.Plo - -rm -f ./$(DEPDIR)/rlogin.Plo - -rm -f ./$(DEPDIR)/root_flag.Plo - -rm -f ./$(DEPDIR)/salt.Plo - -rm -f ./$(DEPDIR)/setugid.Plo - -rm -f ./$(DEPDIR)/setupenv.Plo - -rm -f ./$(DEPDIR)/shell.Plo - -rm -f ./$(DEPDIR)/strtoday.Plo - -rm -f ./$(DEPDIR)/sub.Plo - -rm -f ./$(DEPDIR)/sulog.Plo - -rm -f ./$(DEPDIR)/ttytype.Plo - -rm -f ./$(DEPDIR)/tz.Plo - -rm -f ./$(DEPDIR)/ulimit.Plo - -rm -f ./$(DEPDIR)/user_busy.Plo - -rm -f ./$(DEPDIR)/utmp.Plo - -rm -f ./$(DEPDIR)/valid.Plo - -rm -f ./$(DEPDIR)/xgetgrgid.Plo - -rm -f ./$(DEPDIR)/xgetgrnam.Plo - -rm -f ./$(DEPDIR)/xgetpwnam.Plo - -rm -f ./$(DEPDIR)/xgetpwuid.Plo - -rm -f ./$(DEPDIR)/xgetspnam.Plo - -rm -f ./$(DEPDIR)/xmalloc.Plo - -rm -f ./$(DEPDIR)/yesno.Plo - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -html-am: - -info: info-am - -info-am: - -install-data-am: - -install-dvi: install-dvi-am - -install-dvi-am: - -install-exec-am: - -install-html: install-html-am - -install-html-am: - -install-info: install-info-am - -install-info-am: - -install-man: - -install-pdf: install-pdf-am - -install-pdf-am: - -install-ps: install-ps-am - -install-ps-am: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -f ./$(DEPDIR)/addgrps.Plo - -rm -f ./$(DEPDIR)/age.Plo - -rm -f ./$(DEPDIR)/audit_help.Plo - -rm -f ./$(DEPDIR)/basename.Plo - -rm -f ./$(DEPDIR)/btrfs.Plo - -rm -f ./$(DEPDIR)/chkname.Plo - -rm -f ./$(DEPDIR)/chowndir.Plo - -rm -f ./$(DEPDIR)/chowntty.Plo - -rm -f ./$(DEPDIR)/cleanup.Plo - -rm -f ./$(DEPDIR)/cleanup_group.Plo - -rm -f ./$(DEPDIR)/cleanup_user.Plo - -rm -f ./$(DEPDIR)/console.Plo - -rm -f ./$(DEPDIR)/copydir.Plo - -rm -f ./$(DEPDIR)/date_to_str.Plo - -rm -f ./$(DEPDIR)/entry.Plo - -rm -f ./$(DEPDIR)/env.Plo - -rm -f ./$(DEPDIR)/failure.Plo - -rm -f ./$(DEPDIR)/find_new_gid.Plo - -rm -f ./$(DEPDIR)/find_new_sub_gids.Plo - -rm -f ./$(DEPDIR)/find_new_sub_uids.Plo - -rm -f ./$(DEPDIR)/find_new_uid.Plo - -rm -f ./$(DEPDIR)/getdate.Plo - -rm -f ./$(DEPDIR)/getgr_nam_gid.Plo - -rm -f ./$(DEPDIR)/getrange.Plo - -rm -f ./$(DEPDIR)/gettime.Plo - -rm -f ./$(DEPDIR)/hushed.Plo - -rm -f ./$(DEPDIR)/idmapping.Plo - -rm -f ./$(DEPDIR)/isexpired.Plo - -rm -f ./$(DEPDIR)/limits.Plo - -rm -f ./$(DEPDIR)/list.Plo - -rm -f ./$(DEPDIR)/log.Plo - -rm -f ./$(DEPDIR)/loginprompt.Plo - -rm -f ./$(DEPDIR)/mail.Plo - -rm -f ./$(DEPDIR)/motd.Plo - -rm -f ./$(DEPDIR)/myname.Plo - -rm -f ./$(DEPDIR)/obscure.Plo - -rm -f ./$(DEPDIR)/pam_pass.Plo - -rm -f ./$(DEPDIR)/pam_pass_non_interactive.Plo - -rm -f ./$(DEPDIR)/prefix_flag.Plo - -rm -f ./$(DEPDIR)/pwd2spwd.Plo - -rm -f ./$(DEPDIR)/pwd_init.Plo - -rm -f ./$(DEPDIR)/pwdcheck.Plo - -rm -f ./$(DEPDIR)/remove_tree.Plo - -rm -f ./$(DEPDIR)/rlogin.Plo - -rm -f ./$(DEPDIR)/root_flag.Plo - -rm -f ./$(DEPDIR)/salt.Plo - -rm -f ./$(DEPDIR)/setugid.Plo - -rm -f ./$(DEPDIR)/setupenv.Plo - -rm -f ./$(DEPDIR)/shell.Plo - -rm -f ./$(DEPDIR)/strtoday.Plo - -rm -f ./$(DEPDIR)/sub.Plo - -rm -f ./$(DEPDIR)/sulog.Plo - -rm -f ./$(DEPDIR)/ttytype.Plo - -rm -f ./$(DEPDIR)/tz.Plo - -rm -f ./$(DEPDIR)/ulimit.Plo - -rm -f ./$(DEPDIR)/user_busy.Plo - -rm -f ./$(DEPDIR)/utmp.Plo - -rm -f ./$(DEPDIR)/valid.Plo - -rm -f ./$(DEPDIR)/xgetgrgid.Plo - -rm -f ./$(DEPDIR)/xgetgrnam.Plo - -rm -f ./$(DEPDIR)/xgetpwnam.Plo - -rm -f ./$(DEPDIR)/xgetpwuid.Plo - -rm -f ./$(DEPDIR)/xgetspnam.Plo - -rm -f ./$(DEPDIR)/xmalloc.Plo - -rm -f ./$(DEPDIR)/yesno.Plo - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: - -.MAKE: install-am install-strip - -.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ - clean-generic clean-libtool clean-noinstLTLIBRARIES \ - cscopelist-am ctags ctags-am distclean distclean-compile \ - distclean-generic distclean-libtool distclean-tags distdir dvi \ - dvi-am html html-am info info-am install install-am \ - install-data install-data-am install-dvi install-dvi-am \ - install-exec install-exec-am install-html install-html-am \ - install-info install-info-am install-man install-pdf \ - install-pdf-am install-ps install-ps-am install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags tags-am uninstall uninstall-am - -.PRECIOUS: Makefile - - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/libmisc/date_to_str.c b/libmisc/date_to_str.c deleted file mode 100644 index 07e99f1..0000000 --- a/libmisc/date_to_str.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021, Alejandro Colomar <alx.manpages@gmail.com> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the copyright holders or contributors may not be used to - * endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <string.h> -#include <time.h> - -#ident "$Id$" - -#include "prototypes.h" - -void date_to_str (size_t size, char buf[size], long date) -{ - time_t t; - - t = date; - if (date < 0) - (void) strncpy (buf, "never", size); - else - (void) strftime (buf, size, "%Y-%m-%d", gmtime (&t)); - buf[size - 1] = '\0'; -} diff --git a/libmisc/entry.c b/libmisc/entry.c deleted file mode 100644 index 87f5754..0000000 --- a/libmisc/entry.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2007 - 2008, Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <config.h> - -#ident "$Id$" - -#include <sys/types.h> -#include <stdio.h> -#include "prototypes.h" -#include "defines.h" -#include <pwd.h> - -void pw_entry (const char *name, struct passwd *pwent) -{ - struct passwd *passwd; - - struct spwd *spwd; - - if (!(passwd = getpwnam (name))) { /* local, no need for xgetpwnam */ - pwent->pw_name = (char *) 0; - return; - } else { - pwent->pw_name = xstrdup (passwd->pw_name); - pwent->pw_uid = passwd->pw_uid; - pwent->pw_gid = passwd->pw_gid; - pwent->pw_gecos = xstrdup (passwd->pw_gecos); - pwent->pw_dir = xstrdup (passwd->pw_dir); - pwent->pw_shell = xstrdup (passwd->pw_shell); -#if !defined(AUTOSHADOW) - /* local, no need for xgetspnam */ - if ((spwd = getspnam (name))) { - pwent->pw_passwd = xstrdup (spwd->sp_pwdp); - return; - } -#endif - pwent->pw_passwd = xstrdup (passwd->pw_passwd); - } -} diff --git a/libmisc/getrange.c b/libmisc/getrange.c deleted file mode 100644 index 82f2edf..0000000 --- a/libmisc/getrange.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2008 , Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <config.h> - -#ident "$Id: $" - -#include <ctype.h> -#include <stdlib.h> - -#include "defines.h" -#include "prototypes.h" - -/* - * Parse a range and indicate if the range is valid. - * Valid ranges are in the form: - * <long> -> min=max=long has_min has_max - * -<long> -> max=long !has_min has_max - * <long>- -> min=long has_min !has_max - * <long1>-<long2> -> min=long1 max=long2 has_min has_max - * - * If the range is valid, getrange returns 1. - * If the range is not valid, getrange returns 0. - */ -int getrange (const char *range, - unsigned long *min, bool *has_min, - unsigned long *max, bool *has_max) -{ - char *endptr; - unsigned long n; - - if (NULL == range) { - return 0; - } - - if ('-' == range[0]) { - if (!isdigit(range[1])) { - /* invalid */ - return 0; - } - errno = 0; - n = strtoul (&range[1], &endptr, 10); - if (('\0' != *endptr) || (ERANGE == errno)) { - /* invalid */ - return 0; - } - /* -<long> */ - *has_min = false; - *has_max = true; - *max = n; - } else { - errno = 0; - n = strtoul (range, &endptr, 10); - if (ERANGE == errno) { - /* invalid */ - return 0; - } - switch (*endptr) { - case '\0': - /* <long> */ - *has_min = true; - *has_max = true; - *min = n; - *max = n; - break; - case '-': - endptr++; - if ('\0' == *endptr) { - /* <long>- */ - *has_min = true; - *has_max = false; - *min = n; - } else if (!isdigit (*endptr)) { - /* invalid */ - return 0; - } else { - *has_min = true; - *min = n; - errno = 0; - n = strtoul (endptr, &endptr, 10); - if ( ('\0' != *endptr) - || (ERANGE == errno)) { - /* invalid */ - return 0; - } - /* <long>-<long> */ - *has_max = true; - *max = n; - } - break; - default: - return 0; - } - } - - return 1; -} - diff --git a/libmisc/gettime.c b/libmisc/gettime.c deleted file mode 100644 index b288402..0000000 --- a/libmisc/gettime.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2017, Chris Lamb - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <config.h> - -#ident "$Id$" - -#include <errno.h> -#include <limits.h> -#include <stdio.h> -#include "defines.h" -#include "prototypes.h" -#include "shadowlog.h" - -/* - * gettime() returns the time as the number of seconds since the Epoch - * - * Like time(), gettime() returns the time as the number of seconds since the - * Epoch, 1970-01-01 00:00:00 +0000 (UTC), except that if the SOURCE_DATE_EPOCH - * environment variable is exported it will use that instead. - */ -/*@observer@*/time_t gettime () -{ - char *endptr; - char *source_date_epoch; - time_t fallback; - unsigned long long epoch; - FILE *shadow_logfd = log_get_logfd(); - - fallback = time (NULL); - source_date_epoch = shadow_getenv ("SOURCE_DATE_EPOCH"); - - if (!source_date_epoch) - return fallback; - - errno = 0; - epoch = strtoull (source_date_epoch, &endptr, 10); - if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0)) - || (errno != 0 && epoch == 0)) { - fprintf (shadow_logfd, - _("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n"), - strerror(errno)); - } else if (endptr == source_date_epoch) { - fprintf (shadow_logfd, - _("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n"), - endptr); - } else if (*endptr != '\0') { - fprintf (shadow_logfd, - _("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n"), - endptr); - } else if (epoch > ULONG_MAX) { - fprintf (shadow_logfd, - _("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to %lu but was found to be: %llu\n"), - ULONG_MAX, epoch); - } else if (epoch > fallback) { - fprintf (shadow_logfd, - _("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to the current time (%lu) but was found to be: %llu\n"), - fallback, epoch); - } else { - /* Valid */ - return (time_t)epoch; - } - - return fallback; -} diff --git a/libmisc/loginprompt.c b/libmisc/loginprompt.c deleted file mode 100644 index 0a67f46..0000000 --- a/libmisc/loginprompt.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * SPDX-FileCopyrightText: 1989 - 1993, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2008 - 2011, Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <config.h> - -#ident "$Id$" - -#include <assert.h> -#include <stdio.h> -#include <signal.h> -#include <ctype.h> -#include "prototypes.h" -#include "defines.h" -#include "getdef.h" - -static void login_exit (unused int sig) -{ - exit (EXIT_FAILURE); -} - -/* - * login_prompt - prompt the user for their login name - * - * login_prompt() displays the standard login prompt. If ISSUE_FILE - * is set in login.defs, this file is displayed before the prompt. - */ - -void login_prompt (const char *prompt, char *name, int namesize) -{ - char buf[1024]; - -#define MAX_ENV 32 - char *envp[MAX_ENV]; - char *cp; - int i; - FILE *fp; - - sighandler_t sigquit; -#ifdef SIGTSTP - sighandler_t sigtstp; -#endif - - /* - * There is a small chance that a QUIT character will be part of - * some random noise during a prompt. Deal with this by exiting - * instead of core dumping. If SIGTSTP is defined, do the same - * thing for that signal. - */ - - sigquit = signal (SIGQUIT, login_exit); -#ifdef SIGTSTP - sigtstp = signal (SIGTSTP, login_exit); -#endif - - /* - * See if the user has configured the issue file to - * be displayed and display it before the prompt. - */ - - if (NULL != prompt) { - 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); - } - - (void) fclose (fp); - } - } - (void) gethostname (buf, sizeof buf); - printf (prompt, buf); - (void) fflush (stdout); - } - - /* - * Read the user's response. The trailing newline will be - * removed. - */ - - memzero (buf, sizeof buf); - if (fgets (buf, (int) sizeof buf, stdin) != buf) { - exit (EXIT_FAILURE); - } - - cp = strchr (buf, '\n'); - if (NULL == cp) { - exit (EXIT_FAILURE); - } - *cp = '\0'; /* remove \n [ must be there ] */ - - /* - * Skip leading whitespace. This makes " username" work right. - * Then copy the rest (up to the end or the first "non-graphic" - * character into the username. - */ - - for (cp = buf; *cp == ' ' || *cp == '\t'; cp++); - - for (i = 0; i < namesize - 1 && isgraph (*cp); name[i++] = *cp++); - while (isgraph (*cp)) { - cp++; - } - - if ('\0' != *cp) { - cp++; - } - - name[i] = '\0'; - - /* - * This is a disaster, at best. The user may have entered extra - * environmental variables at the prompt. There are several ways - * to do this, and I just take the easy way out. - */ - - if ('\0' != *cp) { /* process new variables */ - char *nvar; - int count = 1; - int envc; - - for (envc = 0; envc < MAX_ENV; envc++) { - nvar = strtok ((0 != envc) ? (char *) 0 : cp, " \t,"); - if (NULL == nvar) { - break; - } - if (strchr (nvar, '=') != NULL) { - envp[envc] = nvar; - } else { - size_t len = strlen (nvar) + 32; - envp[envc] = xmalloc (len); - (void) snprintf (envp[envc], len, - "L%d=%s", count++, nvar); - } - } - set_env (envc, envp); - } - - /* - * Set the SIGQUIT handler back to its original value - */ - - (void) signal (SIGQUIT, sigquit); -#ifdef SIGTSTP - (void) signal (SIGTSTP, sigtstp); -#endif -} - diff --git a/libmisc/strtoday.c b/libmisc/strtoday.c deleted file mode 100644 index d321873..0000000 --- a/libmisc/strtoday.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 1999, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2008 , Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#if !defined(__GLIBC__) -#define _XOPEN_SOURCE 500 -#endif - -#include <config.h> - -#include <ctype.h> - -#ident "$Id$" - -#include "defines.h" -#include "prototypes.h" - -#ifndef USE_GETDATE -#define USE_GETDATE 1 -#endif - -#if USE_GETDATE -#include "getdate.h" -/* - * strtoday() now uses get_date() (borrowed from GNU shellutils) - * which can handle many date formats, for example: - * 1970-09-17 # ISO 8601. - * 70-9-17 # This century assumed by default. - * 70-09-17 # Leading zeros are ignored. - * 9/17/72 # Common U.S. writing. - * 24 September 1972 - * 24 Sept 72 # September has a special abbreviation. - * 24 Sep 72 # Three-letter abbreviations always allowed. - * Sep 24, 1972 - * 24-sep-72 - * 24sep72 - */ -long strtoday (const char *str) -{ - time_t t; - bool isnum = true; - const char *s = str; - - /* - * get_date() interprets an empty string as the current date, - * which is not what we expect, unless you're a BOFH :-). - * (useradd sets sp_expire = current date for new lusers) - */ - if ((NULL == str) || ('\0' == *str)) { - return -1; - } - - /* If a numerical value is provided, this is already a number of - * days since EPOCH. - */ - if ('-' == *s) { - s++; - } - while (' ' == *s) { - s++; - } - while (isnum && ('\0' != *s)) { - if (!isdigit (*s)) { - isnum = false; - } - s++; - } - if (isnum) { - long retdate; - if (getlong (str, &retdate) == 0) { - return -2; - } - return retdate; - } - - t = get_date (str, NULL); - if ((time_t) - 1 == t) { - return -2; - } - /* convert seconds to days since 1970-01-01 */ - return (long) (t + DAY / 2) / DAY; -} - -#else /* !USE_GETDATE */ -/* - * Old code, just in case get_date() doesn't work as expected... - */ -#include <stdio.h> -#ifdef HAVE_STRPTIME -/* - * for now we allow just one format, but we can define more later - * (we try them all until one succeeds). --marekm - */ -static const char *const date_formats[] = { - "%Y-%m-%d", - (char *) 0 -}; -#else -/* - * days and juldays are used to compute the number of days in the - * current month, and the cumulative number of days in the preceding - * months. they are declared so that january is 1, not 0. - */ -static const short days[13] = { 0, - 31, 28, 31, 30, 31, 30, /* JAN - JUN */ - 31, 31, 30, 31, 30, 31 -}; /* JUL - DEC */ - -static const short juldays[13] = { 0, - 0, 31, 59, 90, 120, 151, /* JAN - JUN */ - 181, 212, 243, 273, 304, 334 -}; /* JUL - DEC */ -#endif - -/* - * strtoday - compute the number of days since 1970. - * - * the total number of days prior to the current date is - * computed. january 1, 1970 is used as the origin with - * it having a day number of 0. - */ - -long strtoday (const char *str) -{ -#ifdef HAVE_STRPTIME - struct tm tp; - const char *const *fmt; - char *cp; - time_t result; - - memzero (&tp, sizeof tp); - for (fmt = date_formats; *fmt; fmt++) { - cp = strptime ((char *) str, *fmt, &tp); - if ((NULL == cp) || ('\0' != *cp)) { - continue; - } - - result = mktime (&tp); - if ((time_t) - 1 == result) { - continue; - } - - return (long) (result / DAY); /* success */ - } - return -1; -#else - char slop[2]; - int month; - int day; - int year; - long total; - - /* - * start by separating the month, day and year. the order - * is compiled in ... - */ - - if (sscanf (str, "%d/%d/%d%c", &year, &month, &day, slop) != 3) { - return -1; - } - - /* - * the month, day of the month, and year are checked for - * correctness and the year adjusted so it falls between - * 1970 and 2069. - */ - - if ((month < 1) || (month > 12)) { - return -1; - } - - if (day < 1) { - return -1; - } - - if ( ((2 != month) || ((year % 4) != 0)) - && (day > days[month])) { - return -1; - } else if ((month == 2) && ((year % 4) == 0) && (day > 29)) { - return -1; - } - - if (year < 0) { - return -1; - } else if (year <= 69) { - year += 2000; - } else if (year <= 99) { - year += 1900; - } - - /* - * On systems with 32-bit signed time_t, time wraps around in 2038 - * - for now we just limit the year to 2037 (instead of 2069). - * This limit can be removed once no one is using 32-bit systems - * anymore :-). --marekm - */ - if ((year < 1970) || (year > 2037)) { - return -1; - } - - /* - * the total number of days is the total number of days in all - * the whole years, plus the number of leap days, plus the - * number of days in the whole months preceding, plus the number - * of days so far in the month. - */ - - total = (long) ((year - 1970) * 365L) + (((year + 1) - 1970) / 4); - total += (long) juldays[month] + (month > 2 && (year % 4) == 0 ? 1 : 0); - total += (long) day - 1; - - return total; -#endif /* HAVE_STRPTIME */ -} -#endif /* !USE_GETDATE */ diff --git a/libmisc/utmp.c b/libmisc/utmp.c deleted file mode 100644 index 45b479f..0000000 --- a/libmisc/utmp.c +++ /dev/null @@ -1,474 +0,0 @@ -/* - * SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 1999, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2001 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2008 - 2009, Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <config.h> - -#include "defines.h" -#include "prototypes.h" - -#ifdef USE_UTMPX -#include <utmpx.h> -#else -#include <utmp.h> -#endif - -#include <assert.h> -#include <sys/param.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netdb.h> -#include <stdio.h> - -#ident "$Id$" - - -/* - * is_my_tty -- determine if "tty" is the same TTY stdin is using - */ -static bool is_my_tty (const char *tty) -{ - /* full_tty shall be at least sizeof utmp.ut_line + 5 */ - char full_tty[200]; - /* tmptty shall be bigger than full_tty */ - static char tmptty[sizeof (full_tty)+1]; - - if ('/' != *tty) { - (void) snprintf (full_tty, sizeof full_tty, "/dev/%s", tty); - tty = &full_tty[0]; - } - - if ('\0' == tmptty[0]) { - const char *tname = ttyname (STDIN_FILENO); - if (NULL != tname) { - (void) strncpy (tmptty, tname, sizeof tmptty); - tmptty[sizeof (tmptty) - 1] = '\0'; - } - } - - if ('\0' == tmptty[0]) { - (void) puts (_("Unable to determine your tty name.")); - exit (EXIT_FAILURE); - } else if (strncmp (tty, tmptty, sizeof (tmptty)) != 0) { - return false; - } else { - return true; - } -} - -/* - * get_current_utmp - return the most probable utmp entry for the current - * session - * - * The utmp file is scanned for an entry with the same process ID. - * The line entered by the *getty / telnetd, etc. should also match - * the current terminal. - * - * When an entry is returned by get_current_utmp, and if the utmp - * structure has a ut_id field, this field should be used to update - * the entry information. - * - * Return NULL if no entries exist in utmp for the current process. - */ -#ifndef USE_UTMPX -/*@null@*/ /*@only@*/struct utmp *get_current_utmp (void) -{ - struct utmp *ut; - struct utmp *ret = NULL; - - setutent (); - - /* First, try to find a valid utmp entry for this process. */ - while ((ut = getutent ()) != NULL) { - if ( (ut->ut_pid == getpid ()) -#ifdef HAVE_STRUCT_UTMP_UT_ID - && ('\0' != ut->ut_id[0]) -#endif -#ifdef HAVE_STRUCT_UTMP_UT_TYPE - && ( (LOGIN_PROCESS == ut->ut_type) - || (USER_PROCESS == ut->ut_type)) -#endif - /* A process may have failed to close an entry - * Check if this entry refers to the current tty */ - && is_my_tty (ut->ut_line)) { - break; - } - } - - if (NULL != ut) { - ret = (struct utmp *) xmalloc (sizeof (*ret)); - memcpy (ret, ut, sizeof (*ret)); - } - - endutent (); - - return ret; -} -#else -/*@null@*/ /*@only*/struct utmpx *get_current_utmp(void) -{ - struct utmpx *ut; - struct utmpx *ret = NULL; - - setutxent (); - - /* Find the utmpx entry for this PID. */ - while ((ut = getutxent ()) != NULL) { - if ( (ut->ut_pid == getpid ()) - && ('\0' != ut->ut_id[0]) - && ( (LOGIN_PROCESS == ut->ut_type) - || (USER_PROCESS == ut->ut_type)) - && is_my_tty (ut->ut_line)) { - break; - } - } - - if (NULL != ut) { - ret = (struct utmpx *) xmalloc (sizeof (*ret)); - memcpy (ret, ut, sizeof (*ret)); - } - - endutxent (); - - return ret; -} -#endif - - -#ifndef USE_PAM -/* - * Some systems already have updwtmp() and possibly updwtmpx(). Others - * don't, so we re-implement these functions if necessary. - */ -#ifndef HAVE_UPDWTMP -static void updwtmp (const char *filename, const struct utmp *ut) -{ - int fd; - - fd = open (filename, O_APPEND | O_WRONLY, 0); - if (fd >= 0) { - write (fd, (const char *) ut, sizeof (*ut)); - close (fd); - } -} -#endif /* ! HAVE_UPDWTMP */ - -#ifdef USE_UTMPX -#ifndef HAVE_UPDWTMPX -static void updwtmpx (const char *filename, const struct utmpx *utx) -{ - int fd; - - fd = open (filename, O_APPEND | O_WRONLY, 0); - if (fd >= 0) { - write (fd, (const char *) utx, sizeof (*utx)); - close (fd); - } -} -#endif /* ! HAVE_UPDWTMPX */ -#endif /* ! USE_UTMPX */ -#endif /* ! USE_PAM */ - - -#ifndef USE_UTMPX -/* - * prepare_utmp - prepare an utmp entry so that it can be logged in a - * utmp/wtmp file. - * - * It accepts an utmp entry in input (ut) to return an entry with - * the right ut_id. This is typically an entry returned by - * get_current_utmp - * If ut is NULL, ut_id will be forged based on the line argument. - * - * The ut_host field of the input structure may also be kept, and is - * used to define the ut_addr/ut_addr_v6 fields. (if these fields - * exist) - * - * Other fields are discarded and filed with new values (if they - * exist). - * - * The returned structure shall be freed by the caller. - */ -/*@only@*/struct utmp *prepare_utmp (const char *name, - const char *line, - const char *host, - /*@null@*/const struct utmp *ut) -{ - struct timeval tv; - char *hostname = NULL; - struct utmp *utent; - - assert (NULL != name); - assert (NULL != line); - - - - if ( (NULL != host) - && ('\0' != host[0])) { - hostname = (char *) xmalloc (strlen (host) + 1); - strcpy (hostname, host); -#ifdef HAVE_STRUCT_UTMP_UT_HOST - } else if ( (NULL != ut) - && ('\0' != ut->ut_host[0])) { - hostname = (char *) xmalloc (sizeof (ut->ut_host) + 1); - strncpy (hostname, ut->ut_host, sizeof (ut->ut_host)); - hostname[sizeof (ut->ut_host)] = '\0'; -#endif /* HAVE_STRUCT_UTMP_UT_HOST */ - } - - if (strncmp(line, "/dev/", 5) == 0) { - line += 5; - } - - - utent = (struct utmp *) xmalloc (sizeof (*utent)); - memzero (utent, sizeof (*utent)); - - - -#ifdef HAVE_STRUCT_UTMP_UT_TYPE - utent->ut_type = USER_PROCESS; -#endif /* HAVE_STRUCT_UTMP_UT_TYPE */ - utent->ut_pid = getpid (); - strncpy (utent->ut_line, line, sizeof (utent->ut_line) - 1); -#ifdef HAVE_STRUCT_UTMP_UT_ID - if (NULL != ut) { - strncpy (utent->ut_id, ut->ut_id, sizeof (utent->ut_id)); - } else { - /* XXX - assumes /dev/tty?? */ - strncpy (utent->ut_id, line + 3, sizeof (utent->ut_id) - 1); - } -#endif /* HAVE_STRUCT_UTMP_UT_ID */ -#ifdef HAVE_STRUCT_UTMP_UT_NAME - strncpy (utent->ut_name, name, sizeof (utent->ut_name)); -#endif /* HAVE_STRUCT_UTMP_UT_NAME */ -#ifdef HAVE_STRUCT_UTMP_UT_USER - strncpy (utent->ut_user, name, sizeof (utent->ut_user) - 1); -#endif /* HAVE_STRUCT_UTMP_UT_USER */ - if (NULL != hostname) { - struct addrinfo *info = NULL; -#ifdef HAVE_STRUCT_UTMP_UT_HOST - strncpy (utent->ut_host, hostname, sizeof (utent->ut_host) - 1); -#endif /* HAVE_STRUCT_UTMP_UT_HOST */ -#ifdef HAVE_STRUCT_UTMP_UT_SYSLEN - utent->ut_syslen = MIN (strlen (hostname), - sizeof (utent->ut_host)); -#endif /* HAVE_STRUCT_UTMP_UT_SYSLEN */ -#if defined(HAVE_STRUCT_UTMP_UT_ADDR) || defined(HAVE_STRUCT_UTMP_UT_ADDR_V6) - if (getaddrinfo (hostname, NULL, NULL, &info) == 0) { - /* getaddrinfo might not be reliable. - * Just try to log what may be useful. - */ - if (info->ai_family == AF_INET) { - struct sockaddr_in *sa = - (struct sockaddr_in *) info->ai_addr; -#ifdef HAVE_STRUCT_UTMP_UT_ADDR - memcpy (&(utent->ut_addr), - &(sa->sin_addr), - MIN (sizeof (utent->ut_addr), - sizeof (sa->sin_addr))); -#endif /* HAVE_STRUCT_UTMP_UT_ADDR */ -#ifdef HAVE_STRUCT_UTMP_UT_ADDR_V6 - memcpy (utent->ut_addr_v6, - &(sa->sin_addr), - MIN (sizeof (utent->ut_addr_v6), - sizeof (sa->sin_addr))); - } else if (info->ai_family == AF_INET6) { - struct sockaddr_in6 *sa = - (struct sockaddr_in6 *) info->ai_addr; - memcpy (utent->ut_addr_v6, - &(sa->sin6_addr), - MIN (sizeof (utent->ut_addr_v6), - sizeof (sa->sin6_addr))); -#endif /* HAVE_STRUCT_UTMP_UT_ADDR_V6 */ - } - freeaddrinfo (info); - } -#endif /* HAVE_STRUCT_UTMP_UT_ADDR || HAVE_STRUCT_UTMP_UT_ADDR_V6 */ - free (hostname); - } - /* ut_exit is only for DEAD_PROCESS */ - utent->ut_session = getsid (0); - if (gettimeofday (&tv, NULL) == 0) { -#ifdef HAVE_STRUCT_UTMP_UT_TIME - utent->ut_time = tv.tv_sec; -#endif /* HAVE_STRUCT_UTMP_UT_TIME */ -#ifdef HAVE_STRUCT_UTMP_UT_XTIME - utent->ut_xtime = tv.tv_usec; -#endif /* HAVE_STRUCT_UTMP_UT_XTIME */ -#ifdef HAVE_STRUCT_UTMP_UT_TV - utent->ut_tv.tv_sec = tv.tv_sec; - utent->ut_tv.tv_usec = tv.tv_usec; -#endif /* HAVE_STRUCT_UTMP_UT_TV */ - } - - return utent; -} - -/* - * setutmp - Update an entry in utmp and log an entry in wtmp - * - * Return 1 on failure and 0 on success. - */ -int setutmp (struct utmp *ut) -{ - int err = 0; - - assert (NULL != ut); - - setutent (); - if (pututline (ut) == NULL) { - err = 1; - } - endutent (); - -#ifndef USE_PAM - /* This is done by pam_lastlog */ - updwtmp (_WTMP_FILE, ut); -#endif /* ! USE_PAM */ - - return err; -} - -#else -/* - * prepare_utmpx - the UTMPX version for prepare_utmp - */ -/*@only@*/struct utmpx *prepare_utmpx (const char *name, - const char *line, - const char *host, - /*@null@*/const struct utmpx *ut) -{ - struct timeval tv; - char *hostname = NULL; - struct utmpx *utxent; - - assert (NULL != name); - assert (NULL != line); - - - - if ( (NULL != host) - && ('\0' != host[0])) { - hostname = (char *) xmalloc (strlen (host) + 1); - strcpy (hostname, host); -#ifdef HAVE_STRUCT_UTMP_UT_HOST - } else if ( (NULL != ut) - && (NULL != ut->ut_host) - && ('\0' != ut->ut_host[0])) { - hostname = (char *) xmalloc (sizeof (ut->ut_host) + 1); - strncpy (hostname, ut->ut_host, sizeof (ut->ut_host)); - hostname[sizeof (ut->ut_host)] = '\0'; -#endif /* HAVE_STRUCT_UTMP_UT_TYPE */ - } - - if (strncmp(line, "/dev/", 5) == 0) { - line += 5; - } - - utxent = (struct utmpx *) xmalloc (sizeof (*utxent)); - memzero (utxent, sizeof (*utxent)); - - - - utxent->ut_type = USER_PROCESS; - utxent->ut_pid = getpid (); - strncpy (utxent->ut_line, line, sizeof (utxent->ut_line)); - /* existence of ut->ut_id is enforced by configure */ - if (NULL != ut) { - strncpy (utxent->ut_id, ut->ut_id, sizeof (utxent->ut_id)); - } else { - /* XXX - assumes /dev/tty?? */ - strncpy (utxent->ut_id, line + 3, sizeof (utxent->ut_id)); - } -#ifdef HAVE_STRUCT_UTMPX_UT_NAME - strncpy (utxent->ut_name, name, sizeof (utxent->ut_name)); -#endif /* HAVE_STRUCT_UTMPX_UT_NAME */ - strncpy (utxent->ut_user, name, sizeof (utxent->ut_user)); - if (NULL != hostname) { - struct addrinfo *info = NULL; -#ifdef HAVE_STRUCT_UTMPX_UT_HOST - strncpy (utxent->ut_host, hostname, sizeof (utxent->ut_host)); -#endif /* HAVE_STRUCT_UTMPX_UT_HOST */ -#ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN - utxent->ut_syslen = MIN (strlen (hostname), - sizeof (utxent->ut_host)); -#endif /* HAVE_STRUCT_UTMPX_UT_SYSLEN */ -#if defined(HAVE_STRUCT_UTMPX_UT_ADDR) || defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6) - if (getaddrinfo (hostname, NULL, NULL, &info) == 0) { - /* getaddrinfo might not be reliable. - * Just try to log what may be useful. - */ - if (info->ai_family == AF_INET) { - struct sockaddr_in *sa = - (struct sockaddr_in *) info->ai_addr; -#ifdef HAVE_STRUCT_UTMPX_UT_ADDR - memcpy (&utxent->ut_addr, - &(sa->sin_addr), - MIN (sizeof (utxent->ut_addr), - sizeof (sa->sin_addr))); -#endif /* HAVE_STRUCT_UTMPX_UT_ADDR */ -#ifdef HAVE_STRUCT_UTMPX_UT_ADDR_V6 - memcpy (utxent->ut_addr_v6, - &(sa->sin_addr), - MIN (sizeof (utxent->ut_addr_v6), - sizeof (sa->sin_addr))); - } else if (info->ai_family == AF_INET6) { - struct sockaddr_in6 *sa = - (struct sockaddr_in6 *) info->ai_addr; - memcpy (utxent->ut_addr_v6, - &(sa->sin6_addr), - MIN (sizeof (utxent->ut_addr_v6), - sizeof (sa->sin6_addr))); -#endif /* HAVE_STRUCT_UTMPX_UT_ADDR_V6 */ - } - freeaddrinfo (info); - } -#endif /* HAVE_STRUCT_UTMPX_UT_ADDR || HAVE_STRUCT_UTMPX_UT_ADDR_V6 */ - free (hostname); - } - /* ut_exit is only for DEAD_PROCESS */ - utxent->ut_session = getsid (0); - if (gettimeofday (&tv, NULL) == 0) { -#ifdef HAVE_STRUCT_UTMPX_UT_TIME - utxent->ut_time = tv.tv_sec; -#endif /* HAVE_STRUCT_UTMPX_UT_TIME */ -#ifdef HAVE_STRUCT_UTMPX_UT_XTIME - utxent->ut_xtime = tv.tv_usec; -#endif /* HAVE_STRUCT_UTMPX_UT_XTIME */ - utxent->ut_tv.tv_sec = tv.tv_sec; - utxent->ut_tv.tv_usec = tv.tv_usec; - } - - return utxent; -} - -/* - * setutmpx - the UTMPX version for setutmp - */ -int setutmpx (struct utmpx *utx) -{ - int err = 0; - - assert (NULL != utx); - - setutxent (); - if (pututxline (utx) == NULL) { - err = 1; - } - endutxent (); - -#ifndef USE_PAM - /* This is done by pam_lastlog */ - updwtmpx (_WTMP_FILE "x", utx); -#endif /* ! USE_PAM */ - - return err; -} -#endif /* USE_UTMPX */ - diff --git a/libmisc/yesno.c b/libmisc/yesno.c deleted file mode 100644 index cfbe6ec..0000000 --- a/libmisc/yesno.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SPDX-FileCopyrightText: 1992 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 2007 - 2008, Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/* - * Common code for yes/no prompting - * - * Used by pwck.c and grpck.c - */ - -#include <config.h> - -#ident "$Id$" - -#include <stdio.h> -#include "prototypes.h" - -/* - * yes_or_no - get answer to question from the user - * - * It returns false if no. - * - * If the read_only flag is set, it will print No, and will return - * false. - */ -bool yes_or_no (bool read_only) -{ - char buf[80]; - - /* - * In read-only mode all questions are answered "no". - */ - if (read_only) { - (void) puts (_("No")); - return false; - } - - /* - * Typically, there's a prompt on stdout, sometimes unflushed. - */ - (void) fflush (stdout); - - /* - * Get a line and see what the first character is. - */ - /* TODO: use gettext */ - if (fgets (buf, (int) sizeof buf, stdin) == buf) { - return buf[0] == 'y' || buf[0] == 'Y'; - } - - return false; -} - |