diff --git a/lib/age.c b/lib/age.c index bdb789e30d..0cf5899ca2 100644 --- a/lib/age.c +++ b/lib/age.c @@ -49,18 +49,18 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp) * force them to change their password. */ - status = isexpired (pw, sp); + status = isexpired(pw, sp); switch (status) { case 0: return 0; case 1: - (void) fputs (_("Your password has expired."), stdout); + (void) fputs(_("Your password has expired."), stdout); break; case 2: - (void) fputs (_("Your password is inactive."), stdout); + (void) fputs(_("Your password is inactive."), stdout); break; case 3: - (void) fputs (_("Your login has expired."), stdout); + (void) fputs(_("Your login has expired."), stdout); break; } @@ -72,11 +72,11 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp) */ if ((status > 1) || (sp->sp_max < sp->sp_min)) { - (void) puts (_(" Contact the system administrator.")); - exit (EXIT_FAILURE); + (void) puts(_(" Contact the system administrator.")); + exit(EXIT_FAILURE); } - (void) puts (_(" Choose a new password.")); - (void) fflush (stdout); + (void) puts(_(" Choose a new password.")); + (void) fflush(stdout); /* * Close all the files so that unauthorized access won't @@ -84,12 +84,12 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp) * might become stale after "passwd" is executed. */ - endspent (); - endpwent (); + endspent(); + endpwent(); #ifdef SHADOWGRP - endsgent (); + endsgent(); #endif - endgrent (); + endgrent(); /* * Execute the /bin/passwd command. The exit status will be @@ -98,7 +98,7 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp) * change their password before being able to use the account. */ - pid = fork (); + pid = fork(); if (0 == pid) { int err; @@ -108,30 +108,30 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp) * it from the command line while logged in. */ #if !defined(USE_PAM) - if (setup_uid_gid (pw, false) != 0) + if (setup_uid_gid(pw, false) != 0) #else - if (setup_uid_gid (pw) != 0) + if (setup_uid_gid(pw) != 0) #endif { - _exit (126); + _exit(126); } - (void) execl (PASSWD_PROGRAM, PASSWD_PROGRAM, pw->pw_name, (char *) NULL); + (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); + perror("Can't execute " PASSWD_PROGRAM); + _exit((ENOENT == err) ? E_CMD_NOTFOUND : E_CMD_NOEXEC); } else if ((pid_t) -1 == pid) { - perror ("fork"); - exit (EXIT_FAILURE); + perror("fork"); + exit(EXIT_FAILURE); } - while (((child = wait (&status)) != pid) && (child != (pid_t)-1)); + while (((child = wait(&status)) != pid) && (child != (pid_t)-1)); if ((child == pid) && (0 == status)) { return 1; } - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); /*@notreached@*/} /* @@ -162,7 +162,7 @@ void agecheck (/*@null@*/const struct spwd *sp) } if (0 == sp->sp_lstchg) { - (void) puts (_("You must change your password.")); + (void) puts(_("You must change your password.")); return; } @@ -170,12 +170,12 @@ void agecheck (/*@null@*/const struct spwd *sp) if (remain <= sp->sp_warn) { if (remain > 1) { - (void) printf (_("Your password will expire in %ld days.\n"), + (void) printf(_("Your password will expire in %ld days.\n"), remain); } else if (1 == remain) { - (void) puts (_("Your password will expire tomorrow.")); + (void) puts(_("Your password will expire tomorrow.")); } else if (remain == 0) { - (void) puts (_("Your password will expire today.")); + (void) puts(_("Your password will expire today.")); } } } diff --git a/lib/alloc/calloc.h b/lib/alloc/calloc.h index db10a685bb..1ec0940a20 100644 --- a/lib/alloc/calloc.h +++ b/lib/alloc/calloc.h @@ -18,7 +18,7 @@ #define calloc_T(n, T) calloc_T_(n, typeas(T)) #define calloc_T_(n, T) \ ({ \ - (T *){calloc(n, sizeof(T))}; \ + (T *){calloc(n, sizeof (T))}; \ }) diff --git a/lib/alloc/malloc.h b/lib/alloc/malloc.h index 1e3a69291a..f1531730f8 100644 --- a/lib/alloc/malloc.h +++ b/lib/alloc/malloc.h @@ -19,7 +19,7 @@ #define malloc_T(n, T) malloc_T_(n, typeas(T)) #define malloc_T_(n, T) \ ({ \ - (T *){mallocarray(n, sizeof(T))}; \ + (T *){mallocarray(n, sizeof (T))}; \ }) diff --git a/lib/alloc/realloc.h b/lib/alloc/realloc.h index ac9f046ec6..5b8bd40f73 100644 --- a/lib/alloc/realloc.h +++ b/lib/alloc/realloc.h @@ -18,8 +18,8 @@ #define realloc_T(p, n, T) realloc_T_(p, n, typeas(T)) #define realloc_T_(p, n, T) \ ({ \ - _Generic(p, T *: (void)0); \ - (T *){reallocarray_(p, n, sizeof(T))}; \ + _Generic (p, T *: (void)0); \ + (T *){reallocarray_(p, n, sizeof (T))}; \ }) #define reallocarray_(p, n, size) reallocarray(p, (n) ?: 1, (size) ?: 1) diff --git a/lib/alloc/reallocf.h b/lib/alloc/reallocf.h index c3522829d6..f83f452067 100644 --- a/lib/alloc/reallocf.h +++ b/lib/alloc/reallocf.h @@ -19,8 +19,8 @@ #define reallocf_T(p, n, T) reallocf_T_(p, n, typeas(T)) #define reallocf_T_(p, n, T) \ ({ \ - _Generic(p, T *: (void)0); \ - (T *){reallocarrayf_(p, n, sizeof(T))}; \ + _Generic (p, T *: (void)0); \ + (T *){reallocarrayf_(p, n, sizeof (T))}; \ }) #define reallocarrayf_(p, n, size) reallocarrayf(p, (n) ?: 1, (size) ?: 1) diff --git a/lib/atoi/a2i.h b/lib/atoi/a2i.h index e7ece423ad..3c0e23e64e 100644 --- a/lib/atoi/a2i.h +++ b/lib/atoi/a2i.h @@ -26,7 +26,7 @@ \ int status; \ \ - *n_ = _Generic((T){0}, \ + *n_ = _Generic ((T){0}, \ short: strtoi_, \ int: strtoi_, \ long: strtoi_, \ diff --git a/lib/audit_help.c b/lib/audit_help.c index b0ac5631e5..20e3260401 100644 --- a/lib/audit_help.c +++ b/lib/audit_help.c @@ -29,9 +29,9 @@ int audit_fd; -void audit_help_open (void) +void audit_help_open(void) { - audit_fd = audit_open (); + audit_fd = audit_open(); if (audit_fd < 0) { /* You get these only when the kernel doesn't have * audit compiled in. */ @@ -40,9 +40,9 @@ void audit_help_open (void) || (errno == EAFNOSUPPORT)) { return; } - (void) fputs (_("Cannot open audit interface - aborting.\n"), + (void) fputs(_("Cannot open audit interface - aborting.\n"), log_get_logfd()); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } } @@ -61,14 +61,14 @@ 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, const char *op, +void audit_logger(int type, const char *op, const char *name, unsigned int id, shadow_audit_result result) { if (audit_fd < 0) { return; } else { - audit_log_acct_message (audit_fd, type, NULL, op, name, id, + audit_log_acct_message(audit_fd, type, NULL, op, name, id, NULL, NULL, NULL, result); } } @@ -102,7 +102,7 @@ audit_logger_with_group(int type, const char *op, const char *name, if (audit_fd < 0) return; - len = strnlen(grp, sizeof(enc_group)/2); + len = strnlen(grp, sizeof (enc_group)/2); if (audit_value_needs_encoding(grp, len)) { stprintf_a(buf, "%s %s=%s", op, grp_type, audit_encode_value(enc_group, grp, len)); @@ -114,12 +114,12 @@ audit_logger_with_group(int type, const char *op, const char *name, NULL, NULL, NULL, result); } -void audit_logger_message (const char *message, shadow_audit_result result) +void audit_logger_message(const char *message, shadow_audit_result result) { if (audit_fd < 0) { return; } else { - audit_log_user_message (audit_fd, + audit_log_user_message(audit_fd, AUDIT_USYS_CONFIG, message, NULL, /* hostname */ diff --git a/lib/chkname.c b/lib/chkname.c index 0b6d9409cc..cd94ba3413 100644 --- a/lib/chkname.c +++ b/lib/chkname.c @@ -119,11 +119,11 @@ is_valid_group_name(const char *name) * HP-UX 10 limits to 16 characters */ if ( (GROUP_NAME_MAX_LENGTH > 0) - && (strlen (name) > GROUP_NAME_MAX_LENGTH)) + && (strlen(name) > GROUP_NAME_MAX_LENGTH)) { errno = EOVERFLOW; return false; } - return is_valid_name (name); + return is_valid_name(name); } diff --git a/lib/chkname.h b/lib/chkname.h index 1f8e4e0822..53056e591d 100644 --- a/lib/chkname.h +++ b/lib/chkname.h @@ -26,7 +26,7 @@ #include -extern bool is_valid_user_name (const char *name); -extern bool is_valid_group_name (const char *name); +extern bool is_valid_user_name(const char *name); +extern bool is_valid_group_name(const char *name); #endif diff --git a/lib/chowndir.c b/lib/chowndir.c index f304e90312..973524db49 100644 --- a/lib/chowndir.c +++ b/lib/chowndir.c @@ -22,7 +22,7 @@ #include "string/strcmp/streq.h" -static int chown_tree_at (int at_fd, +static int chown_tree_at(int at_fd, const char *path, uid_t old_uid, uid_t new_uid, @@ -34,14 +34,14 @@ static int chown_tree_at (int at_fd, struct stat dir_sb; int dir_fd, rc = 0; - dir_fd = openat (at_fd, path, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); + dir_fd = openat(at_fd, path, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); if (dir_fd < 0) { return -1; } - dir = fdopendir (dir_fd); + dir = fdopendir(dir_fd); if (!dir) { - (void) close (dir_fd); + (void) close(dir_fd); return -1; } @@ -51,7 +51,7 @@ static int chown_tree_at (int at_fd, * recursively. If not, it is checked to see if an ownership * shall be changed. */ - while ((ent = readdir (dir))) { + while ((ent = readdir(dir))) { uid_t tmpuid = (uid_t) -1; gid_t tmpgid = (gid_t) -1; struct stat ent_sb; @@ -64,16 +64,16 @@ static int chown_tree_at (int at_fd, continue; } - rc = fstatat (dirfd(dir), ent->d_name, &ent_sb, AT_SYMLINK_NOFOLLOW); + rc = fstatat(dirfd(dir), ent->d_name, &ent_sb, AT_SYMLINK_NOFOLLOW); if (rc < 0) { break; } - if (S_ISDIR (ent_sb.st_mode)) { + if (S_ISDIR(ent_sb.st_mode)) { /* * Do the entire subdirectory. */ - rc = chown_tree_at (dirfd(dir), ent->d_name, old_uid, new_uid, old_gid, new_gid); + rc = chown_tree_at(dirfd(dir), ent->d_name, old_uid, new_uid, old_gid, new_gid); if (0 != rc) { break; } @@ -95,7 +95,7 @@ static int chown_tree_at (int at_fd, tmpgid = new_gid; } if (((uid_t) -1 != tmpuid) || ((gid_t) -1 != tmpgid)) { - rc = fchownat (dirfd(dir), ent->d_name, tmpuid, tmpgid, AT_SYMLINK_NOFOLLOW); + rc = fchownat(dirfd(dir), ent->d_name, tmpuid, tmpgid, AT_SYMLINK_NOFOLLOW); if (0 != rc) { break; } @@ -105,7 +105,7 @@ static int chown_tree_at (int at_fd, /* * Now do the root of the tree */ - if ((0 == rc) && (fstat (dirfd(dir), &dir_sb) == 0)) { + if ((0 == rc) && (fstat(dirfd(dir), &dir_sb) == 0)) { uid_t tmpuid = (uid_t) -1; gid_t tmpgid = (gid_t) -1; if (((uid_t) -1 == old_uid) || (dir_sb.st_uid == old_uid)) { @@ -115,13 +115,13 @@ static int chown_tree_at (int at_fd, tmpgid = new_gid; } if (((uid_t) -1 != tmpuid) || ((gid_t) -1 != tmpgid)) { - rc = fchown (dirfd(dir), tmpuid, tmpgid); + rc = fchown(dirfd(dir), tmpuid, tmpgid); } } else { rc = -1; } - (void) closedir (dir); + (void) closedir(dir); return rc; } @@ -139,11 +139,11 @@ static int chown_tree_at (int at_fd, * new_uid and new_gid can be set to -1 to indicate that no owner or * group-owner shall be changed. */ -int chown_tree (const char *root, +int chown_tree(const char *root, uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid) { - return chown_tree_at (AT_FDCWD, root, old_uid, new_uid, old_gid, new_gid); + return chown_tree_at(AT_FDCWD, root, old_uid, new_uid, old_gid, new_gid); } diff --git a/lib/chowntty.c b/lib/chowntty.c index 64f63d706d..022a774d9d 100644 --- a/lib/chowntty.c +++ b/lib/chowntty.c @@ -27,7 +27,7 @@ * with TTYPERM modes */ -void chown_tty (const struct passwd *info) +void chown_tty(const struct passwd *info) { struct group *grent; gid_t gid; @@ -37,10 +37,10 @@ void chown_tty (const struct passwd *info) * ID. Otherwise, use the user's primary group ID. */ - grent = getgr_nam_gid (getdef_str ("TTYGROUP")); + grent = getgr_nam_gid(getdef_str("TTYGROUP")); if (NULL != grent) { gid = grent->gr_gid; - gr_free (grent); + gr_free(grent); } else { gid = info->pw_gid; } @@ -50,19 +50,19 @@ void chown_tty (const struct passwd *info) * the group as determined above. */ - if ( (fchown (STDIN_FILENO, info->pw_uid, gid) != 0) - || (fchmod (STDIN_FILENO, getdef_num ("TTYPERM", 0600)) != 0)) { + if ( (fchown(STDIN_FILENO, info->pw_uid, gid) != 0) + || (fchmod(STDIN_FILENO, getdef_num("TTYPERM", 0600)) != 0)) { int err = errno; - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("Unable to change owner or mode of tty stdin: %s"), - strerror (err)); + strerror(err)); SYSLOG(LOG_WARN, "unable to change owner or mode of tty stdin for user `%s': %s\n", info->pw_name, strerror(err)); if (EROFS != err) { - closelog (); - exit (EXIT_FAILURE); + closelog(); + exit(EXIT_FAILURE); } } #ifdef __linux__ diff --git a/lib/cleanup.c b/lib/cleanup.c index 4fc12eae88..3dbe99fc33 100644 --- a/lib/cleanup.c +++ b/lib/cleanup.c @@ -43,7 +43,7 @@ static pid_t cleanup_pid = 0; * It is intended to be used as: * atexit (do_cleanups); */ -void do_cleanups (void) +void do_cleanups(void) { unsigned int i; diff --git a/lib/cleanup_group.c b/lib/cleanup_group.c index 130052879d..0adc78de9a 100644 --- a/lib/cleanup_group.c +++ b/lib/cleanup_group.c @@ -21,13 +21,13 @@ * * It should be registered when it is decided to add a group to the system. */ -void cleanup_report_add_group (void *group_name) +void cleanup_report_add_group(void *group_name) { const char *name = group_name; SYSLOG(LOG_ERR, "failed to add group %s", name); #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_GROUP, + audit_logger(AUDIT_ADD_GROUP, "", name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -39,27 +39,27 @@ void cleanup_report_add_group (void *group_name) * * It should be registered when it is decided to remove a group from the system. */ -void cleanup_report_del_group (void *group_name) +void cleanup_report_del_group(void *group_name) { const char *name = group_name; SYSLOG(LOG_ERR, "failed to remove group %s", name); #ifdef WITH_AUDIT - audit_logger (AUDIT_DEL_GROUP, + audit_logger(AUDIT_DEL_GROUP, "", name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); #endif } -void cleanup_report_mod_group (void *cleanup_info) +void cleanup_report_mod_group(void *cleanup_info) { const struct cleanup_info_mod *info; info = (const struct cleanup_info_mod *)cleanup_info; - SYSLOG(LOG_ERR, "failed to change %s (%s)", gr_dbname(), info->action); + SYSLOG(LOG_ERR, "failed to change %s(%s)", gr_dbname(), info->action); #ifdef WITH_AUDIT - audit_logger (AUDIT_GRP_MGMT, + audit_logger(AUDIT_GRP_MGMT, info->audit_msg, info->name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -67,14 +67,14 @@ void cleanup_report_mod_group (void *cleanup_info) } #ifdef SHADOWGRP -void cleanup_report_mod_gshadow (void *cleanup_info) +void cleanup_report_mod_gshadow(void *cleanup_info) { const struct cleanup_info_mod *info; info = (const struct cleanup_info_mod *)cleanup_info; - SYSLOG(LOG_ERR, "failed to change %s (%s)", sgr_dbname(), info->action); + SYSLOG(LOG_ERR, "failed to change %s(%s)", sgr_dbname(), info->action); #ifdef WITH_AUDIT - audit_logger (AUDIT_GRP_MGMT, + audit_logger(AUDIT_GRP_MGMT, info->audit_msg, info->name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -88,13 +88,13 @@ void cleanup_report_mod_gshadow (void *cleanup_info) * It should be registered when it is decided to add a group to the * group database. */ -void cleanup_report_add_group_group (void *group_name) +void cleanup_report_add_group_group(void *group_name) { const char *name = group_name; SYSLOG(LOG_ERR, "failed to add group %s to %s", name, gr_dbname()); #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_GROUP, + audit_logger(AUDIT_ADD_GROUP, "adding-group", name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -108,13 +108,13 @@ void cleanup_report_add_group_group (void *group_name) * It should be registered when it is decided to add a group to the * gshadow database. */ -void cleanup_report_add_group_gshadow (void *group_name) +void cleanup_report_add_group_gshadow(void *group_name) { const char *name = group_name; SYSLOG(LOG_ERR, "failed to add group %s to %s", name, sgr_dbname()); #ifdef WITH_AUDIT - audit_logger (AUDIT_GRP_MGMT, + audit_logger(AUDIT_GRP_MGMT, "adding-shadow-group", name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -129,13 +129,13 @@ void cleanup_report_add_group_gshadow (void *group_name) * It should be registered when it is decided to remove a group from the * regular group database. */ -void cleanup_report_del_group_group (void *group_name) +void cleanup_report_del_group_group(void *group_name) { const char *name = group_name; SYSLOG(LOG_ERR, "failed to remove group %s from %s", name, gr_dbname()); #ifdef WITH_AUDIT - audit_logger (AUDIT_DEL_GROUP, + audit_logger(AUDIT_DEL_GROUP, "removing-group", name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -150,13 +150,13 @@ void cleanup_report_del_group_group (void *group_name) * It should be registered when it is decided to remove a group from the * gshadow database. */ -void cleanup_report_del_group_gshadow (void *group_name) +void cleanup_report_del_group_gshadow(void *group_name) { const char *name = group_name; SYSLOG(LOG_ERR, "failed to remove group %s from %s", name, sgr_dbname()); #ifdef WITH_AUDIT - audit_logger (AUDIT_GRP_MGMT, + audit_logger(AUDIT_GRP_MGMT, "removing-shadow-group", name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -169,17 +169,17 @@ void cleanup_report_del_group_gshadow (void *group_name) * * It should be registered after the group file is successfully locked. */ -void cleanup_unlock_group (void *process_selinux) +void cleanup_unlock_group(void *process_selinux) { bool process = *((bool *) process_selinux); - if (gr_unlock (process) == 0) { - fprintf (log_get_logfd(), + if (gr_unlock(process) == 0) { + fprintf(log_get_logfd(), _("%s: failed to unlock %s\n"), - log_get_progname(), gr_dbname ()); + log_get_progname(), gr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", gr_dbname()); #ifdef WITH_AUDIT - audit_logger_message ("unlocking-group", + audit_logger_message("unlocking-group", SHADOW_AUDIT_FAILURE); #endif } @@ -191,17 +191,17 @@ void cleanup_unlock_group (void *process_selinux) * * It should be registered after the gshadow file is successfully locked. */ -void cleanup_unlock_gshadow (void *process_selinux) +void cleanup_unlock_gshadow(void *process_selinux) { bool process = *((bool *) process_selinux); - if (sgr_unlock (process) == 0) { - fprintf (log_get_logfd(), + if (sgr_unlock(process) == 0) { + fprintf(log_get_logfd(), _("%s: failed to unlock %s\n"), - log_get_progname(), sgr_dbname ()); + log_get_progname(), sgr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sgr_dbname()); #ifdef WITH_AUDIT - audit_logger_message ("unlocking-gshadow", + audit_logger_message("unlocking-gshadow", SHADOW_AUDIT_FAILURE); #endif } diff --git a/lib/cleanup_user.c b/lib/cleanup_user.c index 3f1a46cfb3..ddfe3e489d 100644 --- a/lib/cleanup_user.c +++ b/lib/cleanup_user.c @@ -20,27 +20,27 @@ * * It should be registered when it is decided to add a user to the system. */ -void cleanup_report_add_user (void *user_name) +void cleanup_report_add_user(void *user_name) { const char *name = user_name; SYSLOG(LOG_ERR, "failed to add user %s", name); #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_USER, + audit_logger(AUDIT_ADD_USER, "", name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); #endif } -void cleanup_report_mod_passwd (void *cleanup_info) +void cleanup_report_mod_passwd(void *cleanup_info) { const struct cleanup_info_mod *info; info = (const struct cleanup_info_mod *)cleanup_info; - SYSLOG(LOG_ERR, "failed to change %s (%s)", pw_dbname(), info->action); + SYSLOG(LOG_ERR, "failed to change %s(%s)", pw_dbname(), info->action); #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, info->audit_msg, info->name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -54,13 +54,13 @@ void cleanup_report_mod_passwd (void *cleanup_info) * 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) +void cleanup_report_add_user_passwd(void *user_name) { const char *name = user_name; SYSLOG(LOG_ERR, "failed to add user %s to %s", name, pw_dbname()); #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_USER, + audit_logger(AUDIT_ADD_USER, "adding-user", name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -74,13 +74,13 @@ void cleanup_report_add_user_passwd (void *user_name) * 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) +void cleanup_report_add_user_shadow(void *user_name) { const char *name = user_name; SYSLOG(LOG_ERR, "failed to add user %s to %s", name, spw_dbname()); #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "adding-shadow-user", name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -92,17 +92,17 @@ void cleanup_report_add_user_shadow (void *user_name) * * It should be registered after the passwd database is successfully locked. */ -void cleanup_unlock_passwd (void *process_selinux) +void cleanup_unlock_passwd(void *process_selinux) { bool process = *((bool *) process_selinux); - if (pw_unlock (process) == 0) { - fprintf (log_get_logfd(), + if (pw_unlock(process) == 0) { + fprintf(log_get_logfd(), _("%s: failed to unlock %s\n"), - log_get_progname(), pw_dbname ()); + log_get_progname(), pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); #ifdef WITH_AUDIT - audit_logger_message ("unlocking-passwd", + audit_logger_message("unlocking-passwd", SHADOW_AUDIT_FAILURE); #endif } @@ -113,17 +113,17 @@ void cleanup_unlock_passwd (void *process_selinux) * * It should be registered after the shadow database is successfully locked. */ -void cleanup_unlock_shadow (void *process_selinux) +void cleanup_unlock_shadow(void *process_selinux) { bool process = *((bool *) process_selinux); - if (spw_unlock (process) == 0) { - fprintf (log_get_logfd(), + if (spw_unlock(process) == 0) { + fprintf(log_get_logfd(), _("%s: failed to unlock %s\n"), - log_get_progname(), spw_dbname ()); + log_get_progname(), spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); #ifdef WITH_AUDIT - audit_logger_message ("unlocking-shadow", + audit_logger_message("unlocking-shadow", SHADOW_AUDIT_FAILURE); #endif } diff --git a/lib/commonio.c b/lib/commonio.c index 07927178ad..5c68fa73e2 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -50,9 +50,9 @@ static int do_lock_file (const char *file, const char *lock, bool log); static /*@null@*/ /*@dependent@*/FILE *fmkstemp_set_perms ( char *name, const struct stat *sb); -static int create_backup (const char *, FILE *); -static void free_linked_list (struct commonio_db *); -static void add_one_entry ( +static int create_backup(const char *, FILE *); +static void free_linked_list(struct commonio_db *); +static void add_one_entry( struct commonio_db *db, /*@owned@*/struct commonio_entry *p); static bool name_is_nis (const char *name); @@ -68,13 +68,13 @@ static /*@dependent@*/ /*@null@*/struct commonio_entry *next_entry_by_name ( static int lock_count = 0; static bool nscd_need_reload = false; -static int check_link_count (const char *file, bool log) +static int check_link_count(const char *file, bool log) { struct stat sb; - if (stat (file, &sb) != 0) { + if (stat(file, &sb) != 0) { if (log) { - (void) fprintf (log_get_logfd(), + (void) fprintf(log_get_logfd(), "%s: %s file stat error: %s\n", log_get_progname(), file, strerrno()); } @@ -84,7 +84,7 @@ static int check_link_count (const char *file, bool log) if (sb.st_nlink != 2) { if (log) { fprintf(log_get_logfd(), - "%s: %s: lock file already used (nlink: %ju)\n", + "%s: %s: lock file already used(nlink: %ju)\n", log_get_progname(), file, (uintmax_t) sb.st_nlink); } return 0; @@ -94,7 +94,7 @@ static int check_link_count (const char *file, bool log) } -static int do_lock_file (const char *file, const char *lock, bool log) +static int do_lock_file(const char *file, const char *lock, bool log) { int fd; int retval; @@ -102,113 +102,113 @@ static int do_lock_file (const char *file, const char *lock, bool log) pid_t pid; ssize_t len; - fd = open (file, O_CREAT | O_TRUNC | O_WRONLY, 0600); + fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0600); if (-1 == fd) { if (log) { - (void) fprintf (log_get_logfd(), + (void) fprintf(log_get_logfd(), "%s: %s: %s\n", log_get_progname(), file, strerrno()); } return 0; } - pid = getpid (); + pid = getpid(); stprintf_a(buf, "%lu", (unsigned long) pid); - len = (ssize_t) strlen (buf) + 1; + len = (ssize_t) strlen(buf) + 1; if (write_full(fd, buf, len) == -1) { if (log) { - (void) fprintf (log_get_logfd(), + (void) fprintf(log_get_logfd(), "%s: %s file write error: %s\n", log_get_progname(), file, strerrno()); } - (void) close (fd); - unlink (file); + (void) close(fd); + unlink(file); return 0; } - if (fdatasync (fd) == -1) { + if (fdatasync(fd) == -1) { if (log) { - (void) fprintf (log_get_logfd(), + (void) fprintf(log_get_logfd(), "%s: %s file sync error: %s\n", log_get_progname(), file, strerrno()); } - (void) close (fd); - unlink (file); + (void) close(fd); + unlink(file); return 0; } - close (fd); + close(fd); - if (link (file, lock) == 0) { - retval = check_link_count (file, log); - unlink (file); + if (link(file, lock) == 0) { + retval = check_link_count(file, log); + unlink(file); return retval; } - fd = open (lock, O_RDWR); + fd = open(lock, O_RDWR); if (-1 == fd) { if (log) { - (void) fprintf (log_get_logfd(), + (void) fprintf(log_get_logfd(), "%s: %s: %s\n", log_get_progname(), lock, strerrno()); } - unlink (file); + unlink(file); errno = EINVAL; return 0; } - len = read(fd, buf, sizeof(buf) - 1); - close (fd); + len = read(fd, buf, sizeof (buf) - 1); + close(fd); if (len <= 0) { if (log) { - (void) fprintf (log_get_logfd(), + (void) fprintf(log_get_logfd(), "%s: existing lock file %s without a PID\n", log_get_progname(), lock); } - unlink (file); + unlink(file); errno = EINVAL; return 0; } stpcpy(&buf[len], ""); if (get_pid(buf, &pid) == -1) { if (log) { - (void) fprintf (log_get_logfd(), + (void) fprintf(log_get_logfd(), "%s: existing lock file %s with an invalid PID '%s'\n", log_get_progname(), lock, buf); } - unlink (file); + unlink(file); errno = EINVAL; return 0; } - if (kill (pid, 0) == 0) { + if (kill(pid, 0) == 0) { if (log) { - (void) fprintf (log_get_logfd(), + (void) fprintf(log_get_logfd(), "%s: lock %s already used by PID %lu\n", log_get_progname(), lock, (unsigned long) pid); } - unlink (file); + unlink(file); errno = EEXIST; return 0; } - if (unlink (lock) != 0) { + if (unlink(lock) != 0) { if (log) { - (void) fprintf (log_get_logfd(), + (void) fprintf(log_get_logfd(), "%s: cannot get lock %s: %s\n", log_get_progname(), lock, strerrno()); } - unlink (file); + unlink(file); return 0; } retval = 0; - if (link (file, lock) == 0) { - retval = check_link_count (file, log); + if (link(file, lock) == 0) { + retval = check_link_count(file, log); } else { if (log) { - (void) fprintf (log_get_logfd(), + (void) fprintf(log_get_logfd(), "%s: cannot get lock %s: %s\n", log_get_progname(), lock, strerrno()); } } - unlink (file); + unlink(file); return retval; } @@ -236,12 +236,12 @@ static /*@null@*/ /*@dependent@*/FILE *fmkstemp_set_perms ( fail: (void) fclose (fp); /* fmkstemp_set_perms is used for intermediate files */ - (void) unlink (name); + (void) unlink(name); return NULL; } -static int create_backup (const char *name, FILE * fp) +static int create_backup(const char *name, FILE * fp) { char tmpf[PATH_MAX], target[PATH_MAX]; struct stat sb; @@ -250,7 +250,7 @@ static int create_backup (const char *name, FILE * fp) int c; stprintf_a(tmpf, "%s.cioXXXXXX", name); - if (fstat (fileno (fp), &sb) != 0) { + if (fstat(fileno(fp), &sb) != 0) { return -1; } @@ -377,9 +377,9 @@ int commonio_lock (struct commonio_db *db) * (no retries, it should always succeed). */ if (0 == lock_count) { - if (lckpwdf () == -1) { - if (geteuid () != 0) { - (void) fprintf (log_get_logfd(), + if (lckpwdf() == -1) { + if (geteuid() != 0) { + (void) fprintf(log_get_logfd(), "%s: Permission denied.\n", log_get_progname()); } @@ -391,7 +391,7 @@ int commonio_lock (struct commonio_db *db) return 1; /* success */ } - ulckpwdf (); + ulckpwdf(); return 0; /* failure */ } #endif /* !HAVE_LCKPWDF */ @@ -423,7 +423,7 @@ int commonio_lock (struct commonio_db *db) return 0; /* failure */ } -static void dec_lock_count (void) +static void dec_lock_count(void) { if (lock_count > 0) { lock_count--; @@ -431,28 +431,28 @@ static void dec_lock_count (void) /* Tell nscd when lock count goes to zero, if any of the files were changed. */ if (nscd_need_reload) { - nscd_flush_cache ("passwd"); - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP); + nscd_flush_cache("passwd"); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_PASSWD | SSSD_DB_GROUP); nscd_need_reload = false; } #ifdef HAVE_LCKPWDF - ulckpwdf (); + ulckpwdf(); #endif /* HAVE_LCKPWDF */ } } } -int commonio_unlock (struct commonio_db *db, bool process_selinux) +int commonio_unlock(struct commonio_db *db, bool process_selinux) { char lock[1029]; if (db->isopen) { db->readonly = true; - if (commonio_close (db, process_selinux) == 0) { + if (commonio_close(db, process_selinux) == 0) { if (db->locked) { - dec_lock_count (); + dec_lock_count(); } return 0; } @@ -464,8 +464,8 @@ int commonio_unlock (struct commonio_db *db, bool process_selinux) */ db->locked = false; stprintf_a(lock, "%s.lock", db->filename); - unlink (lock); - dec_lock_count (); + unlink(lock); + dec_lock_count(); return 1; } return 0; @@ -478,7 +478,7 @@ int commonio_unlock (struct commonio_db *db, bool process_selinux) * defines p->next, p->prev * (unfortunately, owned special are not supported) */ -static void add_one_entry (struct commonio_db *db, +static void add_one_entry(struct commonio_db *db, /*@owned@*/struct commonio_entry *p) { /*@-mustfreeonly@*/ @@ -510,7 +510,7 @@ static bool name_is_nis (const char *name) #endif #if KEEP_NIS_AT_END -static void add_one_entry_nis (struct commonio_db *db, +static void add_one_entry_nis(struct commonio_db *db, /*@owned@*/struct commonio_entry *newp); /* @@ -519,7 +519,7 @@ static void add_one_entry_nis (struct commonio_db *db, * defines newp->next, newp->prev * (unfortunately, owned special are not supported) */ -static void add_one_entry_nis (struct commonio_db *db, +static void add_one_entry_nis(struct commonio_db *db, /*@owned@*/struct commonio_entry *newp) { struct commonio_entry *p; @@ -617,12 +617,12 @@ commonio_open(struct commonio_db *db, int mode) goto cleanup_buf; } - line = strdup (buf); + line = strdup(buf); if (NULL == line) { goto cleanup_buf; } - if (name_is_nis (line)) { + if (name_is_nis(line)) { eptr = NULL; } else { eptr = db->ops->cio_parse(line); @@ -643,12 +643,12 @@ commonio_open(struct commonio_db *db, int mode) p->line = line; p->changed = false; - add_one_entry (db, p); + add_one_entry(db, p); } - free (buf); + free(buf); - if (ferror (db->fp) != 0) { + if (ferror(db->fp) != 0) { goto cleanup_errno; } @@ -663,14 +663,14 @@ commonio_open(struct commonio_db *db, int mode) if (NULL != eptr) db->ops->cio_free(eptr); cleanup_line: - free (line); + free(line); cleanup_buf: - free (buf); + free(buf); errno = ENOMEM; cleanup_errno: saved_errno = errno; - free_linked_list (db); - fclose (db->fp); + free_linked_list(db); + fclose(db->fp); db->fp = NULL; errno = saved_errno; return 0; @@ -681,7 +681,7 @@ commonio_open(struct commonio_db *db, int mode) * Sort given db according to cmp function (usually compares uids) */ int -commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *)) +commonio_sort(struct commonio_db *db, int(*cmp) (const void *, const void *)) { struct commonio_entry **entries, *ptr; size_t n = 0, i; @@ -729,7 +729,7 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *)) entries[n] = ptr; n++; } - qsort(entries, n, sizeof(struct commonio_entry *), cmp); + qsort(entries, n, sizeof (struct commonio_entry *), cmp); /* Take care of the head and tail separately */ db->head = entries[0]; @@ -755,7 +755,7 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *)) entries[i]->next = entries[i + 1]; } - free (entries); + free(entries); db->changed = true; return 0; @@ -764,7 +764,7 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *)) /* * Sort entries in db according to order in another. */ -int commonio_sort_wrt (struct commonio_db *shadow, +int commonio_sort_wrt(struct commonio_db *shadow, const struct commonio_db *passwd) { struct commonio_entry *head = NULL, *pw_ptr, *spw_ptr; @@ -791,7 +791,7 @@ int commonio_sort_wrt (struct commonio_db *shadow, if (NULL == spw_ptr) { continue; } - commonio_del_entry (shadow, spw_ptr); + commonio_del_entry(shadow, spw_ptr); spw_ptr->next = head; head = spw_ptr; } @@ -817,7 +817,7 @@ int commonio_sort_wrt (struct commonio_db *shadow, * * It returns 0 if all the entries could be written correctly. */ -static int write_all (const struct commonio_db *db) +static int write_all(const struct commonio_db *db) /*@requires notnull db->fp@*/ { const struct commonio_entry *p; @@ -881,7 +881,7 @@ commonio_close(struct commonio_db *db, MAYBE_UNUSED bool process_selinux) */ #ifdef WITH_SELINUX if (process_selinux - && set_selinux_file_context (db->filename, S_IFREG) != 0) { + && set_selinux_file_context(db->filename, S_IFREG) != 0) { errors = true; } #endif @@ -889,7 +889,7 @@ commonio_close(struct commonio_db *db, MAYBE_UNUSED bool process_selinux) errors = true; } - if (fclose (db->fp) != 0) { + if (fclose(db->fp) != 0) { errors = true; } @@ -897,7 +897,7 @@ commonio_close(struct commonio_db *db, MAYBE_UNUSED bool process_selinux) #ifdef WITH_SELINUX if (process_selinux - && reset_selinux_file_context () != 0) { + && reset_selinux_file_context() != 0) { errors = true; } #endif @@ -917,7 +917,7 @@ commonio_close(struct commonio_db *db, MAYBE_UNUSED bool process_selinux) #ifdef WITH_SELINUX if (process_selinux - && set_selinux_file_context (db->filename, S_IFREG) != 0) { + && set_selinux_file_context(db->filename, S_IFREG) != 0) { errors = true; } #endif @@ -927,19 +927,19 @@ commonio_close(struct commonio_db *db, MAYBE_UNUSED bool process_selinux) goto fail; } - if (write_all (db) != 0) { + if (write_all(db) != 0) { errors = true; } - if (fflush (db->fp) != 0) { + if (fflush(db->fp) != 0) { errors = true; } - if (fsync (fileno (db->fp)) != 0) { + if (fsync(fileno(db->fp)) != 0) { errors = true; } - if (fclose (db->fp) != 0) { + if (fclose(db->fp) != 0) { errors = true; } @@ -956,7 +956,7 @@ commonio_close(struct commonio_db *db, MAYBE_UNUSED bool process_selinux) #ifdef WITH_SELINUX if (process_selinux - && reset_selinux_file_context () != 0) { + && reset_selinux_file_context() != 0) { goto fail; } #endif @@ -967,7 +967,7 @@ commonio_close(struct commonio_db *db, MAYBE_UNUSED bool process_selinux) errors = true; success: - free_linked_list (db); + free_linked_list(db); return !errors; } @@ -1043,9 +1043,9 @@ int commonio_update (struct commonio_db *db, const void *eptr) p->changed = true; #if KEEP_NIS_AT_END - add_one_entry_nis (db, p); + add_one_entry_nis(db, p); #else /* !KEEP_NIS_AT_END */ - add_one_entry (db, p); + add_one_entry(db, p); #endif /* !KEEP_NIS_AT_END */ db->changed = true; @@ -1053,7 +1053,7 @@ int commonio_update (struct commonio_db *db, const void *eptr) } #ifdef ENABLE_SUBIDS -int commonio_append (struct commonio_db *db, const void *eptr) +int commonio_append(struct commonio_db *db, const void *eptr) { struct commonio_entry *p; void *nentry; @@ -1109,7 +1109,7 @@ void commonio_del_entry (struct commonio_db *db, const struct commonio_entry *p) /* * commonio_remove - Remove the entry of the given name from the database. */ -int commonio_remove (struct commonio_db *db, const char *name) +int commonio_remove(struct commonio_db *db, const char *name) { struct commonio_entry *p; @@ -1117,19 +1117,19 @@ int commonio_remove (struct commonio_db *db, const char *name) errno = EINVAL; return 0; } - p = find_entry_by_name (db, name); + p = find_entry_by_name(db, name); if (NULL == p) { errno = ENOENT; return 0; } - if (next_entry_by_name (db, p->next, name) != NULL) { - fprintf (log_get_logfd(), _("Multiple entries named '%s' in %s. Please fix this with pwck or grpck.\n"), name, db->filename); + if (next_entry_by_name(db, p->next, name) != NULL) { + fprintf(log_get_logfd(), _("Multiple entries named '%s' in %s. Please fix this with pwck or grpck.\n"), name, db->filename); return 0; } - commonio_del_entry (db, p); + commonio_del_entry(db, p); - free (p->line); + free(p->line); if (NULL != p->eptr) db->ops->cio_free(p->eptr); @@ -1170,7 +1170,7 @@ int commonio_remove (struct commonio_db *db, const char *name) * * It returns 0 on error, 1 on success. */ -int commonio_rewind (struct commonio_db *db) +int commonio_rewind(struct commonio_db *db) { if (!db->isopen) { errno = EINVAL; diff --git a/lib/commonio.h b/lib/commonio.h index 8507e0e477..54c764feee 100644 --- a/lib/commonio.h +++ b/lib/commonio.h @@ -58,7 +58,7 @@ struct commonio_ops { * Write the object to the file (this calls putpwent() * for struct passwd, for example). */ - int (*cio_put)(const void *, FILE *); + int(*cio_put)(const void *, FILE *); /* * open_hook and close_hook. @@ -115,12 +115,12 @@ struct commonio_db { bool setname:1; }; -extern int commonio_setname (struct commonio_db *, const char *); -extern bool commonio_present (const struct commonio_db *db); -extern int commonio_lock (struct commonio_db *); -extern int commonio_lock_nowait (struct commonio_db *, bool log); -extern int do_fcntl_lock (const char *file, bool log, short type); -extern int commonio_open (struct commonio_db *, int); +extern int commonio_setname(struct commonio_db *, const char *); +extern bool commonio_present(const struct commonio_db *db); +extern int commonio_lock(struct commonio_db *); +extern int commonio_lock_nowait(struct commonio_db *, bool log); +extern int do_fcntl_lock(const char *file, bool log, short type); +extern int commonio_open(struct commonio_db *, int); extern /*@observer@*/ /*@null@*/const void *commonio_locate (struct commonio_db *, const char *); extern int commonio_update (struct commonio_db *, const void *); #ifdef ENABLE_SUBIDS @@ -129,13 +129,13 @@ extern int commonio_append (struct commonio_db *, const void *); extern int commonio_remove (struct commonio_db *, const char *); extern int commonio_rewind (struct commonio_db *); extern /*@observer@*/ /*@null@*/const void *commonio_next (struct commonio_db *); -extern int commonio_close (struct commonio_db *, bool); -extern int commonio_unlock (struct commonio_db *, bool); -extern void commonio_del_entry (struct commonio_db *, +extern int commonio_close(struct commonio_db *, bool); +extern int commonio_unlock(struct commonio_db *, bool); +extern void commonio_del_entry(struct commonio_db *, const struct commonio_entry *); -extern int commonio_sort_wrt (struct commonio_db *shadow, +extern int commonio_sort_wrt(struct commonio_db *shadow, const struct commonio_db *passwd); -extern int commonio_sort (struct commonio_db *db, - int (*cmp) (const void *, const void *)); +extern int commonio_sort(struct commonio_db *db, + int(*cmp) (const void *, const void *)); #endif diff --git a/lib/console.c b/lib/console.c index 9df3e2a49e..7fc7e9793f 100644 --- a/lib/console.c +++ b/lib/console.c @@ -40,7 +40,7 @@ is_listed(const char *cfgin, const char *tty, bool def) * fallback to default. */ - cons = getdef_str (cfgin); + cons = getdef_str(cfgin); if (NULL == cons) { return def; } @@ -68,7 +68,7 @@ is_listed(const char *cfgin, const char *tty, bool def) * console - otherwise root will never be allowed to login. */ - fp = fopen (cons, "r"); + fp = fopen(cons, "r"); if (NULL == fp) { return def; } @@ -80,7 +80,7 @@ is_listed(const char *cfgin, const char *tty, bool def) while (fgets_a(buf, fp) != NULL) { stpsep(buf, "\n"); if (streq(buf, tty)) { - (void) fclose (fp); + (void) fclose(fp); return true; } } @@ -89,7 +89,7 @@ is_listed(const char *cfgin, const char *tty, bool def) * This tty isn't a console. */ - (void) fclose (fp); + (void) fclose(fp); return false; } @@ -103,10 +103,10 @@ is_listed(const char *cfgin, const char *tty, bool def) * that would allow an unauthorized root login. */ -bool console (const char *tty) +bool console(const char *tty) { tty = strprefix(tty, "/dev/") ?: tty; - return is_listed ("CONSOLE", tty, true); + return is_listed("CONSOLE", tty, true); } diff --git a/lib/copydir.c b/lib/copydir.c index 3976bf8e34..bdf65d6b95 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -57,31 +57,31 @@ struct path_info { const char *name; }; -static int copy_entry (const struct path_info *src, const struct path_info *dst, +static int copy_entry(const struct path_info *src, const struct path_info *dst, uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid); -static int copy_dir (const struct path_info *src, const struct path_info *dst, +static int copy_dir(const struct path_info *src, const struct path_info *dst, 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_symlink (const struct path_info *src, const struct path_info *dst, +static int copy_symlink(const struct path_info *src, const struct path_info *dst, 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, +static int copy_hardlink(const struct path_info *dst, struct link_name *lp); -static int copy_special (const struct path_info *src, const struct path_info *dst, +static int copy_special(const struct path_info *src, const struct path_info *dst, 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_file (const struct path_info *src, const struct path_info *dst, +static int copy_file(const struct path_info *src, const struct path_info *dst, 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 chownat_if_needed (const struct path_info *dst, const struct stat *statp, +static int chownat_if_needed(const struct path_info *dst, const struct stat *statp, uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid); -static int fchown_if_needed (int fdst, const struct stat *statp, +static int fchown_if_needed(int fdst, const struct stat *statp, uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid); @@ -102,13 +102,13 @@ error_acl(MAYBE_UNUSED struct error_context *_1, const char *fmt, ...) return; } - va_start (ap, fmt); - (void) fprintf (log_get_logfd(), _("%s: "), log_get_progname()); - if (vfprintf (log_get_logfd(), fmt, ap) != 0) { - (void) fputs (_(": "), log_get_logfd()); + va_start(ap, fmt); + (void) fprintf(log_get_logfd(), _("%s: "), log_get_progname()); + if (vfprintf(log_get_logfd(), fmt, ap) != 0) { + (void) fputs(_(": "), log_get_logfd()); } (void) fprintf(log_get_logfd(), "%s\n", strerrno()); - va_end (ap); + va_end(ap); } static struct error_context ctx = { @@ -130,13 +130,13 @@ static int perm_copy_path(const struct path_info *src, dst_fd = openat(dst->dirfd, dst->name, O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC); if (dst_fd < 0) { - (void) close (src_fd); + (void) close(src_fd); return -1; } ret = perm_copy_fd(src->full_path, src_fd, dst->full_path, dst_fd, errctx); - (void) close (src_fd); - (void) close (dst_fd); + (void) close(src_fd); + (void) close(dst_fd); return ret; } #endif /* WITH_ACL */ @@ -180,8 +180,8 @@ static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c struct link_name *lp; /* copy_tree () must be the entry point */ - assert (NULL != src_orig); - assert (NULL != dst_orig); + assert(NULL != src_orig); + assert(NULL != dst_orig); for (lp = links; NULL != lp; lp = lp->ln_next) { if ((lp->ln_dev == sb->st_dev) && (lp->ln_ino == sb->st_ino)) { @@ -204,7 +204,7 @@ static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c return NULL; } -static int copy_tree_impl (const struct path_info *src, const struct path_info *dst, +static int copy_tree_impl(const struct path_info *src, const struct path_info *dst, bool copy_root, uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid) @@ -217,23 +217,23 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info * if (copy_root) { struct stat sb; - if ( fstatat (dst->dirfd, dst->name, &sb, 0) == 0 + if ( fstatat(dst->dirfd, dst->name, &sb, 0) == 0 || errno != ENOENT) { return -1; } - if (fstatat (src->dirfd, src->name, &sb, AT_SYMLINK_NOFOLLOW) == -1) { + if (fstatat(src->dirfd, src->name, &sb, AT_SYMLINK_NOFOLLOW) == -1) { return -1; } - if (!S_ISDIR (sb.st_mode)) { - fprintf (log_get_logfd(), + if (!S_ISDIR(sb.st_mode)) { + fprintf(log_get_logfd(), "%s: %s is not a directory", log_get_progname(), src->full_path); return -1; } - return copy_entry (src, dst, old_uid, new_uid, old_gid, new_gid); + return copy_entry(src, dst, old_uid, new_uid, old_gid, new_gid); } /* @@ -242,14 +242,14 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info * * target is created. It assumes the target directory exists. */ - src_fd = openat (src->dirfd, src->name, O_DIRECTORY | O_RDONLY | O_NOFOLLOW | O_CLOEXEC); + src_fd = openat(src->dirfd, src->name, O_DIRECTORY | O_RDONLY | O_NOFOLLOW | O_CLOEXEC); if (src_fd < 0) { return -1; } - dst_fd = openat (dst->dirfd, dst->name, O_DIRECTORY | O_RDONLY | O_NOFOLLOW | O_CLOEXEC); + dst_fd = openat(dst->dirfd, dst->name, O_DIRECTORY | O_RDONLY | O_NOFOLLOW | O_CLOEXEC); if (dst_fd < 0) { - (void) close (src_fd); + (void) close(src_fd); return -1; } @@ -260,10 +260,10 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info * * regular files (and directories ...) are copied, and no file * is made set-ID. */ - dir = fdopendir (src_fd); + dir = fdopendir(src_fd); if (NULL == dir) { - (void) close (src_fd); - (void) close (dst_fd); + (void) close(src_fd); + (void) close(dst_fd); return -1; } @@ -311,8 +311,8 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info * skip: free(src_name); } - (void) closedir (dir); - (void) close (dst_fd); + (void) closedir(dir); + (void) close(dst_fd); if (set_orig) { src_orig = NULL; @@ -332,7 +332,7 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info * * be called recursively (hence the context is set on the * sub-functions of copy_entry). */ - if (reset_selinux_file_context () != 0) { + if (reset_selinux_file_context() != 0) { err = -1; } #endif /* WITH_SELINUX */ @@ -359,7 +359,7 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info * * old_gid) will be modified, unless old_uid (resp. old_gid) is set * to -1. */ -static int copy_entry (const struct path_info *src, const struct path_info *dst, +static int copy_entry(const struct path_info *src, const struct path_info *dst, uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid) { @@ -397,8 +397,8 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst, * Copy any symbolic links */ - else if (S_ISLNK (sb.st_mode)) { - err = copy_symlink (src, dst, &sb, mt, + else if (S_ISLNK(sb.st_mode)) { + err = copy_symlink(src, dst, &sb, mt, old_uid, new_uid, old_gid, new_gid); } @@ -406,8 +406,8 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst, * See if this is a previously copied link */ - else if ((lp = check_link (src->full_path, &sb)) != NULL) { - err = copy_hardlink (dst, lp); + else if ((lp = check_link(src->full_path, &sb)) != NULL) { + err = copy_hardlink(dst, lp); } /* @@ -416,8 +416,8 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst, * would be nice to copy everything ... */ - else if (!S_ISREG (sb.st_mode)) { - err = copy_special (src, dst, &sb, mt, + else if (!S_ISREG(sb.st_mode)) { + err = copy_special(src, dst, &sb, mt, old_uid, new_uid, old_gid, new_gid); } @@ -427,7 +427,7 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst, */ else { - err = copy_file (src, dst, &sb, mt, + err = copy_file(src, dst, &sb, mt, old_uid, new_uid, old_gid, new_gid); } @@ -444,7 +444,7 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst, * * Return 0 on success, -1 on error. */ -static int copy_dir (const struct path_info *src, const struct path_info *dst, +static int copy_dir(const struct path_info *src, const struct path_info *dst, const struct stat *statp, const struct timespec mt[], uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid) @@ -458,7 +458,7 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst, */ #ifdef WITH_SELINUX - if (set_selinux_file_context (dst->full_path, S_IFDIR) != 0) { + if (set_selinux_file_context(dst->full_path, S_IFDIR) != 0) { return -1; } #endif /* WITH_SELINUX */ @@ -467,21 +467,21 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst, * 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, + return (copy_tree_impl(src, dst, false, old_uid, new_uid, old_gid, new_gid) != 0); } - if ( (mkdirat (dst->dirfd, dst->name, 0700) != 0) - || (chownat_if_needed (dst, statp, + if ( (mkdirat(dst->dirfd, dst->name, 0700) != 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) + || (fchmodat(dst->dirfd, dst->name, statp->st_mode & 07777, AT_SYMLINK_NOFOLLOW) != 0) #ifdef WITH_ACL - || ( (perm_copy_path (src, dst, &ctx) != 0) + || ( (perm_copy_path(src, dst, &ctx) != 0) && (errno != 0)) #endif /* WITH_ACL */ - || (copy_tree_impl (src, dst, false, + || (copy_tree_impl(src, dst, false, old_uid, new_uid, old_gid, new_gid) != 0) - || (utimensat (dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) != 0)) { + || (utimensat(dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) != 0)) { err = -1; } @@ -498,7 +498,7 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst, * * Return 0 on success, -1 on error. */ -static int copy_symlink (const struct path_info *src, const struct path_info *dst, +static int copy_symlink(const struct path_info *src, const struct path_info *dst, const struct stat *statp, const struct timespec mt[], uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid) @@ -534,13 +534,13 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds } #ifdef WITH_SELINUX - if (set_selinux_file_context (dst->full_path, S_IFLNK) != 0) { - free (oldlink); + if (set_selinux_file_context(dst->full_path, S_IFLNK) != 0) { + free(oldlink); return -1; } #endif /* WITH_SELINUX */ - if ( (symlinkat (oldlink, dst->dirfd, dst->name) != 0) - || (chownat_if_needed (dst, statp, + if ( (symlinkat(oldlink, dst->dirfd, dst->name) != 0) + || (chownat_if_needed(dst, statp, old_uid, new_uid, old_gid, new_gid) != 0)) { /* FIXME: there are no modes on symlinks, right? * ACL could be copied, but this would be much more @@ -549,12 +549,12 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds * We currently only document that ACL and Extended * Attributes are not copied. */ - free (oldlink); + free(oldlink); return -1; } - free (oldlink); + free(oldlink); - if (utimensat (dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) != 0) { + if (utimensat(dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) != 0) { return -1; } @@ -568,7 +568,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, +static int copy_hardlink(const struct path_info *dst, struct link_name *lp) { /* FIXME: selinux, ACL, Extended Attributes needed? */ @@ -581,7 +581,7 @@ static int copy_hardlink (const struct path_info *dst, * and forget about this link if it was the last reference */ lp->ln_count--; if (lp->ln_count <= 0) { - remove_link (lp); + remove_link(lp); } return 0; @@ -639,7 +639,7 @@ copy_special(MAYBE_UNUSED const struct path_info *src, const struct path_info *d * * Return 0 on success, -1 on error. */ -static int copy_file (const struct path_info *src, const struct path_info *dst, +static int copy_file(const struct path_info *src, const struct path_info *dst, const struct stat *statp, const struct timespec mt[], uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid) @@ -648,30 +648,30 @@ static int copy_file (const struct path_info *src, const struct path_info *dst, int ifd; int ofd; - ifd = openat (src->dirfd, src->name, O_RDONLY|O_NOFOLLOW|O_CLOEXEC); + ifd = openat(src->dirfd, src->name, O_RDONLY|O_NOFOLLOW|O_CLOEXEC); if (ifd < 0) { return -1; } #ifdef WITH_SELINUX - if (set_selinux_file_context (dst->full_path, S_IFREG) != 0) { - (void) close (ifd); + if (set_selinux_file_context(dst->full_path, S_IFREG) != 0) { + (void) close(ifd); return -1; } #endif /* WITH_SELINUX */ - ofd = openat (dst->dirfd, dst->name, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); + ofd = openat(dst->dirfd, dst->name, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0600); if ( (ofd < 0) - || (fchown_if_needed (ofd, statp, + || (fchown_if_needed(ofd, statp, old_uid, new_uid, old_gid, new_gid) != 0) - || (fchmod (ofd, statp->st_mode & 07777) != 0) + || (fchmod(ofd, statp->st_mode & 07777) != 0) #ifdef WITH_ACL - || ( (perm_copy_fd (src->full_path, ifd, dst->full_path, ofd, &ctx) != 0) + || ( (perm_copy_fd(src->full_path, ifd, dst->full_path, ofd, &ctx) != 0) && (errno != 0)) #endif /* WITH_ACL */ ) { if (ofd >= 0) { - (void) close (ofd); + (void) close(ofd); } - (void) close (ifd); + (void) close(ifd); return -1; } @@ -679,13 +679,13 @@ static int copy_file (const struct path_info *src, const struct path_info *dst, char buf[8192]; ssize_t cnt; - cnt = read(ifd, buf, sizeof(buf)); + cnt = read(ifd, buf, sizeof (buf)); if (cnt < 0) { if (errno == EINTR) { continue; } - (void) close (ofd); - (void) close (ifd); + (void) close(ofd); + (void) close(ifd); return -1; } if (cnt == 0) { @@ -693,18 +693,18 @@ static int copy_file (const struct path_info *src, const struct path_info *dst, } if (write_full(ofd, buf, cnt) == -1) { - (void) close (ofd); - (void) close (ifd); + (void) close(ofd); + (void) close(ifd); return -1; } } - (void) close (ifd); - if (close (ofd) != 0 && errno != EINTR) { + (void) close(ifd); + if (close(ofd) != 0 && errno != EINTR) { return -1; } - if (utimensat (dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) != 0) { + if (utimensat(dst->dirfd, dst->name, mt, AT_SYMLINK_NOFOLLOW) != 0) { return -1; } @@ -712,7 +712,7 @@ static int copy_file (const struct path_info *src, const struct path_info *dst, } #define def_chown_if_needed(chown_function, type_dst) \ -static int chown_function ## _if_needed (type_dst dst, \ +static int chown_function ## _if_needed(type_dst dst, \ const struct stat *statp, \ uid_t old_uid, uid_t new_uid, \ gid_t old_gid, gid_t new_gid) \ @@ -738,12 +738,12 @@ static int chown_function ## _if_needed (type_dst dst, \ tmpgid = statp->st_gid; \ } \ \ - return chown_function (dst, tmpuid, tmpgid); \ + return chown_function(dst, tmpuid, tmpgid); \ } -def_chown_if_needed (fchown, int) +def_chown_if_needed(fchown, int) -static int chownat_if_needed (const struct path_info *dst, +static int chownat_if_needed(const struct path_info *dst, const struct stat *statp, uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid) @@ -769,7 +769,7 @@ static int chownat_if_needed (const struct path_info *dst, tmpgid = statp->st_gid; } - return fchownat (dst->dirfd, dst->name, tmpuid, tmpgid, AT_SYMLINK_NOFOLLOW); + return fchownat(dst->dirfd, dst->name, tmpuid, tmpgid, AT_SYMLINK_NOFOLLOW); } /* @@ -786,7 +786,7 @@ static int chownat_if_needed (const struct path_info *dst, * The same logic applies for the group-ownership and * old_gid/new_gid. */ -int copy_tree (const char *src_root, const char *dst_root, +int copy_tree(const char *src_root, const char *dst_root, bool copy_root, uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid) diff --git a/lib/csrand.c b/lib/csrand.c index 27ca1b823c..f5f3321740 100644 --- a/lib/csrand.c +++ b/lib/csrand.c @@ -43,7 +43,7 @@ csrand(void) #ifdef HAVE_GETRANDOM /* Likewise getrandom. */ - if (getrandom(&r, sizeof(r), 0) == sizeof(r)) + if (getrandom(&r, sizeof (r), 0) == sizeof (r)) return r; #endif @@ -58,7 +58,7 @@ csrand(void) if (fd == -1) goto fail; - if (read(fd, &r, sizeof(r)) != sizeof(r)) { + if (read(fd, &r, sizeof (r)) != sizeof (r)) { close(fd); goto fail; } diff --git a/lib/encrypt.c b/lib/encrypt.c index d21f962f36..9474ea1a89 100644 --- a/lib/encrypt.c +++ b/lib/encrypt.c @@ -37,7 +37,7 @@ /* Some crypt() do not return NULL if the algorithm is not * supported, and return a DES encrypted password. */ - if ((NULL != salt) && strprefix(salt, "$") && (strlen (cp) <= 13)) + if ((NULL != salt) && strprefix(salt, "$") && (strlen(cp) <= 13)) { /*@observer@*/const char *method; switch (salt[1]) @@ -75,7 +75,7 @@ return cp; /* nonstandard crypt() in libc, better bail out */ } - strcpy (cipher, cp); + strcpy(cipher, cp); return cipher; } diff --git a/lib/env.c b/lib/env.c index cdbd87d626..0b0bfce497 100644 --- a/lib/env.c +++ b/lib/env.c @@ -66,7 +66,7 @@ static const char *const noslash[] = { /* * initenv() must be called once before using addenv(). */ -void initenv (void) +void initenv(void) { newenvp = xmalloc_T(NEWENVP_STEP, char *); *newenvp = NULL; @@ -89,7 +89,7 @@ void addenv (const char *string, /*@null@*/const char *value) * just ignore the whole string. */ - cp = strchr (newstring, '='); + cp = strchr(newstring, '='); if (NULL == cp) { free(newstring); return; @@ -101,7 +101,7 @@ void addenv (const char *string, /*@null@*/const char *value) * If this environment variable is already set, change its value. */ for (i = 0; i < newenvc; i++) { - if ( (strncmp (newstring, newenvp[i], n) == 0) + if ( (strncmp(newstring, newenvp[i], n) == 0) && (('=' == newenvp[i][n]) || ('\0' == newenvp[i][n]))) { break; } @@ -157,14 +157,14 @@ void addenv (const char *string, /*@null@*/const char *value) /* * set_env - copy command line arguments into the environment */ -void set_env (int argc, char *const *argv) +void set_env(int argc, char *const *argv) { int noname = 1; char variable[1024]; char *cp; for (; argc > 0; argc--, argv++) { - if (strlen(*argv) >= sizeof(variable)) { + if (strlen(*argv) >= sizeof (variable)) { continue; /* ignore long entries */ } @@ -203,7 +203,7 @@ void set_env (int argc, char *const *argv) * but... I feel better with that silly precaution. -j. */ -void sanitize_env (void) +void sanitize_env(void) { char **envp = environ; const char *const *bad; diff --git a/lib/failure.c b/lib/failure.c index 107c526a33..b913fde19a 100644 --- a/lib/failure.c +++ b/lib/failure.c @@ -31,20 +31,20 @@ * failure() creates a new (struct faillog) entry or updates an * existing one with the current failed login information. */ -void failure (uid_t uid, const char *tty, struct faillog *fl) +void failure(uid_t uid, const char *tty, struct faillog *fl) { int fd; - off_t offset_uid = (off_t) sizeof(*fl) * uid; + off_t offset_uid = (off_t) sizeof (*fl) * uid; /* * Don't do anything if failure logging isn't set up. */ - if (access (FAILLOG_FILE, F_OK) != 0) { + if (access(FAILLOG_FILE, F_OK) != 0) { return; } - fd = open (FAILLOG_FILE, O_RDWR); + fd = open(FAILLOG_FILE, O_RDWR); if (fd < 0) { SYSLOG(LOG_WARN, "Can't write faillog entry for UID %lu in %s: %m", @@ -58,8 +58,8 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) * share just about everything else ... */ - if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (read(fd, fl, sizeof(*fl)) != (ssize_t) sizeof(*fl))) { + if ( (lseek(fd, offset_uid, SEEK_SET) != offset_uid) + || (read(fd, fl, sizeof (*fl)) != (ssize_t) sizeof (*fl))) { /* This is not necessarily a failure. The file is * initially zero length. * @@ -67,7 +67,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) * might reset the counter. But the new failure will be * logged. */ - memzero(fl, sizeof(*fl)); + memzero(fl, sizeof (*fl)); } /* @@ -91,12 +91,12 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) * seem that great. */ - if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (write_full(fd, fl, sizeof(*fl)) == -1)) { + if ( (lseek(fd, offset_uid, SEEK_SET) != offset_uid) + || (write_full(fd, fl, sizeof (*fl)) == -1)) { goto err_write; } - if (close (fd) != 0 && errno != EINTR) { + if (close(fd) != 0 && errno != EINTR) { goto err_close; } @@ -105,7 +105,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) err_write: { int saved_errno = errno; - (void) close (fd); + (void) close(fd); errno = saved_errno; } err_close: @@ -114,7 +114,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) (unsigned long) uid, FAILLOG_FILE); } -static bool too_many_failures (const struct faillog *fl) +static bool too_many_failures(const struct faillog *fl) { time_t now; @@ -146,24 +146,24 @@ static bool too_many_failures (const struct faillog *fl) * validated. */ -int failcheck (uid_t uid, struct faillog *fl, bool failed) +int failcheck(uid_t uid, struct faillog *fl, bool failed) { int fd; struct faillog fail; - off_t offset_uid = (off_t) sizeof(*fl) * uid; + off_t offset_uid = (off_t) sizeof (*fl) * uid; /* * Suppress the check if the log file isn't there. */ - if (access (FAILLOG_FILE, F_OK) != 0) { + if (access(FAILLOG_FILE, F_OK) != 0) { return 1; } - fd = open (FAILLOG_FILE, failed?O_RDONLY:O_RDWR); + 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: %m; " + "Can't open the faillog file(%s) to check UID %lu: %m; " "User access authorized.", FAILLOG_FILE, (unsigned long) uid); return 1; @@ -181,14 +181,14 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) * no need to reset the count. */ - if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (read(fd, fl, sizeof(*fl)) != (ssize_t) sizeof(*fl))) { - (void) close (fd); + if ( (lseek(fd, offset_uid, SEEK_SET) != offset_uid) + || (read(fd, fl, sizeof (*fl)) != (ssize_t) sizeof (*fl))) { + (void) close(fd); return 1; } - if (too_many_failures (fl)) { - (void) close (fd); + if (too_many_failures(fl)) { + (void) close(fd); return 0; } @@ -203,16 +203,16 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) fail = *fl; fail.fail_cnt = 0; - if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (write_full(fd, &fail, sizeof(fail)) == -1)) { + if ( (lseek(fd, offset_uid, SEEK_SET) != offset_uid) + || (write_full(fd, &fail, sizeof (fail)) == -1)) { goto err_write; } - if (close (fd) != 0 && errno != EINTR) { + if (close(fd) != 0 && errno != EINTR) { goto err_close; } } else { - (void) close (fd); + (void) close(fd); } return 1; @@ -220,7 +220,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) err_write: { int saved_errno = errno; - (void) close (fd); + (void) close(fd); errno = saved_errno; } err_close: @@ -237,7 +237,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) * message which is displayed at login time. */ -void failprint (const struct faillog *fail) +void failprint(const struct faillog *fail) { struct tm *tp; char lasttimeb[256]; @@ -247,7 +247,7 @@ void failprint (const struct faillog *fail) return; } - tp = localtime (&(fail->fail_time)); + tp = localtime(&(fail->fail_time)); /* * Print all information we have. diff --git a/lib/failure.h b/lib/failure.h index 1352b68c1e..c396246c37 100644 --- a/lib/failure.h +++ b/lib/failure.h @@ -20,7 +20,7 @@ * failure() creates a new (struct faillog) entry or updates an * existing one with the current failed login information. */ -extern void failure (uid_t, const char *, struct faillog *); +extern void failure(uid_t, const char *, struct faillog *); /* * failcheck - check for failures > allowable @@ -30,7 +30,7 @@ extern void failure (uid_t, const char *, struct faillog *); * returns FALSE to indicate that the login should be denied even though * the password is valid. */ -extern int failcheck (uid_t uid, struct faillog *fl, bool failed); +extern int failcheck(uid_t uid, struct faillog *fl, bool failed); /* * failprint - print line of failure information @@ -38,7 +38,7 @@ extern int failcheck (uid_t uid, struct faillog *fl, bool failed); * failprint takes a (struct faillog) entry and formats it into a * message which is displayed at login time. */ -extern void failprint (const struct faillog *); +extern void failprint(const struct faillog *); #endif diff --git a/lib/fields.c b/lib/fields.c index 759dea755f..335adf9f07 100644 --- a/lib/fields.c +++ b/lib/fields.c @@ -65,8 +65,8 @@ change_field(char *buf, size_t maxsize, const char *prompt) char *cp; char newf[MIN(200, maxsize)]; - printf ("\t%s [%s]: ", prompt, buf); - (void) fflush (stdout); + printf("\t%s [%s]: ", prompt, buf); + (void) fflush(stdout); if (fgets_a(newf, stdin) == NULL) return; @@ -81,6 +81,6 @@ change_field(char *buf, size_t maxsize, const char *prompt) */ stpcpy(stprspn(newf, " \t"), ""); cp = stpspn(newf, " \t"); - strcpy (buf, cp); + strcpy(buf, cp); } } diff --git a/lib/find_new_gid.c b/lib/find_new_gid.c index 4e458cf0b0..355ab49de4 100644 --- a/lib/find_new_gid.c +++ b/lib/find_new_gid.c @@ -35,7 +35,7 @@ * preferred_min: the special-case minimum value for a specifically- * requested ID, which may be lower than the standard min_id */ -static int get_ranges (bool sys_group, gid_t *min_id, gid_t *max_id, +static int get_ranges(bool sys_group, gid_t *min_id, gid_t *max_id, gid_t *preferred_min) { gid_t gid_def_max = 0; @@ -53,8 +53,8 @@ static int get_ranges (bool sys_group, gid_t *min_id, gid_t *max_id, * 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 = getdef_ulong ("GID_MIN", 1000UL) - 1; - *max_id = getdef_ulong ("SYS_GID_MAX", 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) { @@ -77,8 +77,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 = getdef_ulong ("GID_MIN", 1000UL); - *max_id = 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 @@ -109,7 +109,7 @@ static int get_ranges (bool sys_group, gid_t *min_id, gid_t *max_id, * If the ID is outside the range, return ERANGE * In other cases, return errno from getgrgid() */ -static int check_gid (const gid_t gid, +static int check_gid(const gid_t gid, const gid_t gid_min, const gid_t gid_max, const bool *used_gids) @@ -157,7 +157,7 @@ static int check_gid (const gid_t gid, * * Return 0 on success, -1 if no unused GIDs are available. */ -int find_new_gid (bool sys_group, +int find_new_gid(bool sys_group, gid_t *gid, /*@null@*/gid_t const *preferred_gid) { @@ -175,7 +175,7 @@ int find_new_gid (bool sys_group, * First, figure out what ID range is appropriate for * automatic assignment */ - result = get_ranges (sys_group, &gid_min, &gid_max, &preferred_min); + result = get_ranges(sys_group, &gid_min, &gid_max, &preferred_min); if (result == EINVAL) { return -1; } @@ -187,7 +187,7 @@ int find_new_gid (bool sys_group, /* * Make sure the GID isn't queued for use already */ - if (gr_locate_gid (*preferred_gid) == NULL) { + if (gr_locate_gid(*preferred_gid) == NULL) { *gid = *preferred_gid; return 0; } @@ -210,10 +210,10 @@ int find_new_gid (bool sys_group, * more likely to want to stop and address the * issue. */ - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: Encountered error attempting to use " "preferred GID: %s\n"), - log_get_progname(), strerror (result)); + log_get_progname(), strerror(result)); return -1; } } @@ -247,7 +247,7 @@ int find_new_gid (bool sys_group, } /* First look for the lowest and highest value in the local database */ - (void) gr_rewind (); + (void) gr_rewind(); highest_found = gid_min; lowest_found = gid_max; while (NULL != (grp = gr_next())) { @@ -306,7 +306,7 @@ int find_new_gid (bool sys_group, if (result == 0) { /* This GID is available. Return it. */ *gid = id; - free (used_gids); + free(used_gids); return 0; } else if (result == EEXIST || result == EINVAL) { /* @@ -322,10 +322,10 @@ int find_new_gid (bool sys_group, * */ if (!nospam) { - fprintf (log_get_logfd(), - _("%s: Can't get unique system GID (%s). " + fprintf(log_get_logfd(), + _("%s: Can't get unique system GID(%s). " "Suppressing additional messages.\n"), - log_get_progname(), strerror (result)); + log_get_progname(), strerror(result)); SYSLOG(LOG_ERR, "Error checking available GIDs: %s", strerror(result)); @@ -348,7 +348,7 @@ int find_new_gid (bool sys_group, */ if (lowest_found != gid_max) { for (id = gid_max; id >= gid_min; id--) { - result = check_gid (id, gid_min, gid_max, used_gids); + result = check_gid(id, gid_min, gid_max, used_gids); if (result == 0) { /* This GID is available. Return it. */ *gid = id; @@ -368,10 +368,10 @@ int find_new_gid (bool sys_group, * */ if (!nospam) { - fprintf (log_get_logfd(), - _("%s: Can't get unique system GID (%s). " + fprintf(log_get_logfd(), + _("%s: Can't get unique system GID(%s). " "Suppressing additional messages.\n"), - log_get_progname(), strerror (result)); + log_get_progname(), strerror(result)); SYSLOG(LOG_ERR, "Error checking available GIDs: %s", strerror(result)); @@ -415,7 +415,7 @@ int find_new_gid (bool sys_group, if (result == 0) { /* This GID is available. Return it. */ *gid = id; - free (used_gids); + free(used_gids); return 0; } else if (result == EEXIST || result == EINVAL) { /* @@ -431,10 +431,10 @@ int find_new_gid (bool sys_group, * */ if (!nospam) { - fprintf (log_get_logfd(), - _("%s: Can't get unique GID (%s). " + fprintf(log_get_logfd(), + _("%s: Can't get unique GID(%s). " "Suppressing additional messages.\n"), - log_get_progname(), strerror (result)); + log_get_progname(), strerror(result)); SYSLOG(LOG_ERR, "Error checking available GIDs: %s", strerror(result)); @@ -457,7 +457,7 @@ int find_new_gid (bool sys_group, */ if (highest_found != gid_min) { for (id = gid_min; id <= gid_max; id++) { - result = check_gid (id, gid_min, gid_max, used_gids); + result = check_gid(id, gid_min, gid_max, used_gids); if (result == 0) { /* This GID is available. Return it. */ *gid = id; @@ -477,10 +477,10 @@ int find_new_gid (bool sys_group, * */ if (!nospam) { - fprintf (log_get_logfd(), - _("%s: Can't get unique GID (%s). " + fprintf(log_get_logfd(), + _("%s: Can't get unique GID(%s). " "Suppressing additional messages.\n"), - log_get_progname(), strerror (result)); + log_get_progname(), strerror(result)); SYSLOG(LOG_ERR, "Error checking available GIDs: %s", strerror(result)); diff --git a/lib/find_new_sub_gids.c b/lib/find_new_sub_gids.c index beb902ed6f..ad504cbd32 100644 --- a/lib/find_new_sub_gids.c +++ b/lib/find_new_sub_gids.c @@ -28,30 +28,30 @@ * * Return 0 on success, -1 if no unused GIDs are available. */ -int find_new_sub_gids (id_t *range_start, unsigned long *range_count) +int find_new_sub_gids(id_t *range_start, unsigned long *range_count) { unsigned long min, max; unsigned long count; id_t start; - assert (range_start != NULL); - assert (range_count != NULL); + assert(range_start != NULL); + assert(range_count != NULL); - min = getdef_ulong ("SUB_GID_MIN", 100000UL); - max = getdef_ulong ("SUB_GID_MAX", 600100000UL); - count = getdef_ulong ("SUB_GID_COUNT", 65536); + min = getdef_ulong("SUB_GID_MIN", 100000UL); + max = getdef_ulong("SUB_GID_MAX", 600100000UL); + count = getdef_ulong("SUB_GID_COUNT", 65536); if (min > max || count >= max || (min + count - 1) > max) { - (void) fprintf (log_get_logfd(), - _("%s: Invalid configuration: SUB_GID_MIN (%lu)," - " SUB_GID_MAX (%lu), SUB_GID_COUNT (%lu)\n"), + (void) fprintf(log_get_logfd(), + _("%s: Invalid configuration: SUB_GID_MIN(%lu)," + " SUB_GID_MAX(%lu), SUB_GID_COUNT(%lu)\n"), log_get_progname(), min, max, count); return -1; } start = sub_gid_find_free_range(min, max, count); if (start == (id_t)-1) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: Can't get unique subordinate GID range\n"), log_get_progname()); SYSLOG(LOG_WARN, "no more available subordinate GIDs on the system"); diff --git a/lib/find_new_sub_uids.c b/lib/find_new_sub_uids.c index c9c4993d48..8968ff710e 100644 --- a/lib/find_new_sub_uids.c +++ b/lib/find_new_sub_uids.c @@ -28,30 +28,30 @@ * * Return 0 on success, -1 if no unused UIDs are available. */ -int find_new_sub_uids (id_t *range_start, unsigned long *range_count) +int find_new_sub_uids(id_t *range_start, unsigned long *range_count) { unsigned long min, max; unsigned long count; id_t start; - assert (range_start != NULL); - assert (range_count != NULL); + assert(range_start != NULL); + assert(range_count != NULL); - min = getdef_ulong ("SUB_UID_MIN", 100000UL); - max = getdef_ulong ("SUB_UID_MAX", 600100000UL); - count = getdef_ulong ("SUB_UID_COUNT", 65536); + min = getdef_ulong("SUB_UID_MIN", 100000UL); + max = getdef_ulong("SUB_UID_MAX", 600100000UL); + count = getdef_ulong("SUB_UID_COUNT", 65536); if (min > max || count >= max || (min + count - 1) > max) { - (void) fprintf (log_get_logfd(), - _("%s: Invalid configuration: SUB_UID_MIN (%lu)," - " SUB_UID_MAX (%lu), SUB_UID_COUNT (%lu)\n"), + (void) fprintf(log_get_logfd(), + _("%s: Invalid configuration: SUB_UID_MIN(%lu)," + " SUB_UID_MAX(%lu), SUB_UID_COUNT(%lu)\n"), log_get_progname(), min, max, count); return -1; } start = sub_uid_find_free_range(min, max, count); if (start == (id_t)-1) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: Can't get unique subordinate UID range\n"), log_get_progname()); SYSLOG(LOG_WARN, "no more available subordinate UIDs on the system"); diff --git a/lib/find_new_uid.c b/lib/find_new_uid.c index 9ca6953f09..bf1749bc18 100644 --- a/lib/find_new_uid.c +++ b/lib/find_new_uid.c @@ -34,7 +34,7 @@ * preferred_min: the special-case minimum value for a specifically- * requested ID, which may be lower than the standard min_id */ -static int get_ranges (bool sys_user, uid_t *min_id, uid_t *max_id, +static int get_ranges(bool sys_user, uid_t *min_id, uid_t *max_id, uid_t *preferred_min) { uid_t uid_def_max = 0; @@ -52,8 +52,8 @@ static int get_ranges (bool sys_user, uid_t *min_id, uid_t *max_id, * 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 = getdef_ulong ("UID_MIN", 1000UL) - 1; - *max_id = getdef_ulong ("SYS_UID_MAX", 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) { @@ -76,8 +76,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 = getdef_ulong ("UID_MIN", 1000UL); - *max_id = 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 @@ -174,7 +174,7 @@ int find_new_uid(bool sys_user, * First, figure out what ID range is appropriate for * automatic assignment */ - result = get_ranges (sys_user, &uid_min, &uid_max, &preferred_min); + result = get_ranges(sys_user, &uid_min, &uid_max, &preferred_min); if (result == EINVAL) { return -1; } @@ -186,7 +186,7 @@ int find_new_uid(bool sys_user, /* * Make sure the UID isn't queued for use already */ - if (pw_locate_uid (*preferred_uid) == NULL) { + if (pw_locate_uid(*preferred_uid) == NULL) { *uid = *preferred_uid; return 0; } @@ -209,10 +209,10 @@ int find_new_uid(bool sys_user, * more likely to want to stop and address the * issue. */ - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: Encountered error attempting to use " "preferred UID: %s\n"), - log_get_progname(), strerror (result)); + log_get_progname(), strerror(result)); return -1; } } @@ -246,7 +246,7 @@ int find_new_uid(bool sys_user, } /* First look for the lowest and highest value in the local database */ - (void) pw_rewind (); + (void) pw_rewind(); highest_found = uid_min; lowest_found = uid_max; while (NULL != (pwd = pw_next())) { @@ -305,7 +305,7 @@ int find_new_uid(bool sys_user, if (result == 0) { /* This UID is available. Return it. */ *uid = id; - free (used_uids); + free(used_uids); return 0; } else if (result == EEXIST || result == EINVAL) { /* @@ -321,10 +321,10 @@ int find_new_uid(bool sys_user, * */ if (!nospam) { - fprintf (log_get_logfd(), - _("%s: Can't get unique system UID (%s). " + fprintf(log_get_logfd(), + _("%s: Can't get unique system UID(%s). " "Suppressing additional messages.\n"), - log_get_progname(), strerror (result)); + log_get_progname(), strerror(result)); SYSLOG(LOG_ERR, "Error checking available UIDs: %s", strerror(result)); @@ -347,7 +347,7 @@ int find_new_uid(bool sys_user, */ if (lowest_found != uid_max) { for (id = uid_max; id >= uid_min; id--) { - result = check_uid (id, uid_min, uid_max, used_uids); + result = check_uid(id, uid_min, uid_max, used_uids); if (result == 0) { /* This UID is available. Return it. */ *uid = id; @@ -367,10 +367,10 @@ int find_new_uid(bool sys_user, * */ if (!nospam) { - fprintf (log_get_logfd(), - _("%s: Can't get unique system UID (%s). " + fprintf(log_get_logfd(), + _("%s: Can't get unique system UID(%s). " "Suppressing additional messages.\n"), - log_get_progname(), strerror (result)); + log_get_progname(), strerror(result)); SYSLOG(LOG_ERR, "Error checking available UIDs: %s", strerror(result)); @@ -414,7 +414,7 @@ int find_new_uid(bool sys_user, if (result == 0) { /* This UID is available. Return it. */ *uid = id; - free (used_uids); + free(used_uids); return 0; } else if (result == EEXIST || result == EINVAL) { /* @@ -430,10 +430,10 @@ int find_new_uid(bool sys_user, * */ if (!nospam) { - fprintf (log_get_logfd(), - _("%s: Can't get unique UID (%s). " + fprintf(log_get_logfd(), + _("%s: Can't get unique UID(%s). " "Suppressing additional messages.\n"), - log_get_progname(), strerror (result)); + log_get_progname(), strerror(result)); SYSLOG(LOG_ERR, "Error checking available UIDs: %s", strerror(result)); @@ -456,7 +456,7 @@ int find_new_uid(bool sys_user, */ if (highest_found != uid_min) { for (id = uid_min; id <= uid_max; id++) { - result = check_uid (id, uid_min, uid_max, used_uids); + result = check_uid(id, uid_min, uid_max, used_uids); if (result == 0) { /* This UID is available. Return it. */ *uid = id; @@ -476,10 +476,10 @@ int find_new_uid(bool sys_user, * */ if (!nospam) { - fprintf (log_get_logfd(), - _("%s: Can't get unique UID (%s). " + fprintf(log_get_logfd(), + _("%s: Can't get unique UID(%s). " "Suppressing additional messages.\n"), - log_get_progname(), strerror (result)); + log_get_progname(), strerror(result)); SYSLOG(LOG_ERR, "Error checking available UIDs: %s", strerror(result)); diff --git a/lib/getdef.c b/lib/getdef.c index 3a9a423ceb..ca4a588680 100644 --- a/lib/getdef.c +++ b/lib/getdef.c @@ -183,7 +183,7 @@ static bool def_loaded = false; /* are defs already loaded? */ /* local function prototypes */ static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *, const char *); -static void def_load (void); +static void def_load(void); /* @@ -212,15 +212,15 @@ static void def_load (void); * Return TRUE if specified item is defined as "yes", else FALSE. */ -bool getdef_bool (const char *item) +bool getdef_bool(const char *item) { struct itemdef *d; if (!def_loaded) { - def_load (); + def_load(); } - d = def_find (item, NULL); + d = def_find(item, NULL); if ((NULL == d) || (NULL == d->value)) { return false; } @@ -244,16 +244,16 @@ getdef_num(const char *item, int dflt) struct itemdef *d; if (!def_loaded) { - def_load (); + def_load(); } - d = def_find (item, NULL); + d = def_find(item, NULL); if ((NULL == d) || (NULL == d->value)) { return dflt; } if (a2si(&val, d->value, NULL, 0, -1, INT_MAX) == -1) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("configuration error - cannot parse %s value: '%s'"), item, d->value); return dflt; @@ -278,16 +278,16 @@ getdef_unum(const char *item, unsigned int dflt) struct itemdef *d; if (!def_loaded) { - def_load (); + def_load(); } - d = def_find (item, NULL); + d = def_find(item, NULL); if ((NULL == d) || (NULL == d->value)) { return dflt; } if (a2ui(&val, d->value, NULL, 0, 0, UINT_MAX) == -1) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("configuration error - cannot parse %s value: '%s'"), item, d->value); return dflt; @@ -305,22 +305,22 @@ getdef_unum(const char *item, unsigned int dflt) * values are handled. */ -long getdef_long (const char *item, long dflt) +long getdef_long(const char *item, long dflt) { struct itemdef *d; long val; if (!def_loaded) { - def_load (); + def_load(); } - d = def_find (item, NULL); + d = def_find(item, NULL); if ((NULL == d) || (NULL == d->value)) { return dflt; } if (a2sl(&val, d->value, NULL, 0, -1, LONG_MAX) == -1) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("configuration error - cannot parse %s value: '%s'"), item, d->value); return dflt; @@ -337,22 +337,22 @@ long getdef_long (const char *item, long dflt) * values are handled. */ -unsigned long getdef_ulong (const char *item, unsigned long dflt) +unsigned long getdef_ulong(const char *item, unsigned long dflt) { struct itemdef *d; unsigned long val; if (!def_loaded) { - def_load (); + def_load(); } - d = def_find (item, NULL); + d = def_find(item, NULL); if ((NULL == d) || (NULL == d->value)) { return dflt; } if (str2ul(&val, d->value) == -1) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("configuration error - cannot parse %s value: '%s'"), item, d->value); return dflt; @@ -366,35 +366,35 @@ unsigned long getdef_ulong (const char *item, unsigned long dflt) * (also used when loading the initial defaults) */ -int putdef_str (const char *name, const char *value, const char *srcfile) +int putdef_str(const char *name, const char *value, const char *srcfile) { struct itemdef *d; char *cp; if (!def_loaded) { - def_load (); + def_load(); } /* * Locate the slot to save the value. If this parameter * is unknown then "def_find" will print an err message. */ - d = def_find (name, srcfile); + d = def_find(name, srcfile); if (NULL == d) return -1; /* * Save off the value. */ - cp = strdup (value); + cp = strdup(value); if (NULL == cp) { - (void) fputs (_("Could not allocate space for config info.\n"), + (void) fputs(_("Could not allocate space for config info.\n"), log_get_logfd()); SYSLOG(LOG_ERR, "could not allocate space for config info"); return -1; } - free (d->value); + free(d->value); d->value = cp; return 0; } @@ -433,7 +433,7 @@ static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name, cons goto out; } } - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("configuration error - unknown item '%s' (notify administrator)\n"), name); if (srcfile != NULL) @@ -449,7 +449,7 @@ static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name, cons * must be called prior to any def* calls. */ -void setdef_config_file (const char* file) +void setdef_config_file(const char* file) { #ifdef USE_ECONF sysconfdir = xaprintf("%s/%s", file, sysconfdir); @@ -468,7 +468,7 @@ void setdef_config_file (const char* file) */ #ifdef USE_ECONF -static void def_load (void) +static void def_load(void) { econf_file *defs_file = NULL; econf_err error; @@ -481,20 +481,20 @@ static void def_load (void) */ def_loaded = true; - error = econf_readDirs (&defs_file, vendordir, sysconfdir, "login", "defs", " \t", "#"); + error = econf_readDirs(&defs_file, vendordir, sysconfdir, "login", "defs", " \t", "#"); if (error) { if (error == ECONF_NOFILE) return; SYSLOG(LOG_CRIT, "cannot open login definitions [%s]", econf_errString(error)); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } if ((error = econf_getKeys(defs_file, NULL, &key_number, &keys))) { SYSLOG(LOG_CRIT, "cannot read login definitions [%s]", econf_errString(error)); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } for (size_t i = 0; i < key_number; i++) { @@ -504,7 +504,7 @@ static void def_load (void) if (error) { SYSLOG(LOG_CRIT, "failed reading key %zu from econf [%s]", i, econf_errString(error)); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } /* @@ -514,16 +514,16 @@ static void def_load (void) * The error was already reported to the user and to * syslog. The tools will just use their default values. */ - (void)putdef_str (keys[i], value, econf_getPath(defs_file)); + (void)putdef_str(keys[i], value, econf_getPath(defs_file)); free(value); } - econf_free (keys); - econf_free (defs_file); + econf_free(keys); + econf_free(defs_file); } #else /* USE_ECONF */ -static void def_load (void) +static void def_load(void) { FILE *fp; char buf[1024], *name, *value, *s; @@ -537,7 +537,7 @@ static void def_load (void) /* * Open the configuration definitions file. */ - fp = fopen (def_fname, "r"); + fp = fopen(def_fname, "r"); if (NULL == fp) { if (errno == ENOENT) return; @@ -545,7 +545,7 @@ static void def_load (void) int err = errno; SYSLOG(LOG_CRIT, "cannot open login definitions %s [%s]", def_fname, strerror(err)); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } /* @@ -579,47 +579,47 @@ static void def_load (void) * The error was already reported to the user and to * syslog. The tools will just use their default values. */ - (void)putdef_str (name, value, def_fname); + (void)putdef_str(name, value, def_fname); } - if (ferror (fp) != 0) { + if (ferror(fp) != 0) { int err = errno; SYSLOG(LOG_CRIT, "cannot read login definitions %s [%s]", def_fname, strerror(err)); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } - (void) fclose (fp); + (void) fclose(fp); } #endif /* USE_ECONF */ #ifdef CKDEFS -int main (int argc, char **argv) +int main(int argc, char **argv) { int i; char *cp; struct itemdef *d; - def_load (); + def_load(); for (i = 0; i < countof(def_table); ++i) { - d = def_find (def_table[i].name, NULL); + d = def_find(def_table[i].name, NULL); if (NULL == d) { - printf ("error - lookup '%s' failed\n", + printf("error - lookup '%s' failed\n", def_table[i].name); } else { - printf ("%4d %-24s %s\n", i + 1, d->name, d->value); + printf("%4d %-24s %s\n", i + 1, d->name, d->value); } } for (i = 1; i < argc; i++) { - cp = getdef_str (argv[1]); + cp = getdef_str(argv[1]); if (NULL != cp) { - printf ("%s `%s'\n", argv[1], cp); + printf("%s `%s'\n", argv[1], cp); } else { - printf ("%s not found\n", argv[1]); + printf("%s not found\n", argv[1]); } } - exit (EXIT_SUCCESS); + exit(EXIT_SUCCESS); } #endif diff --git a/lib/getdef.h b/lib/getdef.h index e687a2ee6a..7cba574b13 100644 --- a/lib/getdef.h +++ b/lib/getdef.h @@ -22,8 +22,8 @@ extern int getdef_num (const char *, int); extern unsigned long getdef_ulong (const char *, unsigned long); extern unsigned int getdef_unum (const char *, unsigned int); extern /*@observer@*/ /*@null@*/const char *getdef_str (const char *); -extern int putdef_str (const char *, const char *, const char *); -extern void setdef_config_file (const char* file); +extern int putdef_str(const char *, const char *, const char *); +extern void setdef_config_file(const char* file); /* default UMASK value if not specified in /etc/login.defs */ #define GETDEF_DEFAULT_UMASK 022 diff --git a/lib/groupio.c b/lib/groupio.c index 119afa33df..163555e7ce 100644 --- a/lib/groupio.c +++ b/lib/groupio.c @@ -38,7 +38,7 @@ static /*@null@*/ /*@only@*/void *group_dup (const void *ent) { const struct group *gr = ent; - return __gr_dup (gr); + return __gr_dup(gr); } static void @@ -76,16 +76,16 @@ static int group_put (const void *ent, FILE * file) if (NULL != gr->gr_mem) { size_t i; for (i = 0; NULL != gr->gr_mem[i]; i++) { - if (valid_field (gr->gr_mem[i], ",:\n") == -1) { + if (valid_field(gr->gr_mem[i], ",:\n") == -1) { return -1; } } } - return (putgrent (gr, file) == -1) ? -1 : 0; + return (putgrent(gr, file) == -1) ? -1 : 0; } -static int group_close_hook (void) +static int group_close_hook(void) { unsigned int max_members = getdef_unum("MAX_MEMBERS_PER_GROUP", 0); @@ -93,7 +93,7 @@ static int group_close_hook (void) return 1; } - return split_groups (max_members); + return split_groups(max_members); } static struct commonio_ops group_ops = { @@ -126,9 +126,9 @@ static /*@owned@*/struct commonio_db group_db = { false /* setname */ }; -int gr_setdbname (const char *filename) +int gr_setdbname(const char *filename) { - return commonio_setname (&group_db, filename); + return commonio_setname(&group_db, filename); } /*@observer@*/const char *gr_dbname (void) @@ -148,7 +148,7 @@ int gr_open (int mode) /*@observer@*/ /*@null@*/const struct group *gr_locate (const char *name) { - return commonio_locate (&group_db, name); + return commonio_locate(&group_db, name); } /*@observer@*/ /*@null@*/const struct group *gr_locate_gid (gid_t gid) @@ -180,20 +180,20 @@ int gr_rewind (void) /*@observer@*/ /*@null@*/const struct group *gr_next (void) { - return commonio_next (&group_db); + return commonio_next(&group_db); } -int gr_close (bool process_selinux) +int gr_close(bool process_selinux) { - return commonio_close (&group_db, process_selinux); + return commonio_close(&group_db, process_selinux); } -int gr_unlock (bool process_selinux) +int gr_unlock(bool process_selinux) { - return commonio_unlock (&group_db, process_selinux); + return commonio_unlock(&group_db, process_selinux); } -void __gr_set_changed (void) +void __gr_set_changed(void) { group_db.changed = true; } @@ -208,12 +208,12 @@ void __gr_set_changed (void) return &group_db; } -void __gr_del_entry (const struct commonio_entry *ent) +void __gr_del_entry(const struct commonio_entry *ent) { - commonio_del_entry (&group_db, ent); + commonio_del_entry(&group_db, ent); } -static int gr_cmp (const void *p1, const void *p2) +static int gr_cmp(const void *p1, const void *p2) { const struct commonio_entry *const *ce1; const struct commonio_entry *const *ce2; @@ -271,7 +271,7 @@ static int group_open_hook (void) /* Both group entries refer to the same * group. It is a split group. Merge the * members. */ - gr1 = merge_group_entries (gr1, gr2); + gr1 = merge_group_entries(gr1, gr2); if (NULL == gr1) return 0; /* Unlink gr2 */ @@ -279,11 +279,11 @@ static int group_open_hook (void) gr2->next->prev = gr2->prev; } /* gr2 does not start with head */ - assert (NULL != gr2->prev); + assert(NULL != gr2->prev); gr2->prev->next = gr2->next; } } - assert (NULL != gr1); + assert(NULL != gr1); } return 1; @@ -382,7 +382,7 @@ static /*@null@*/struct commonio_entry *merge_group_entries ( * * Return 0 on failure (errno set) and 1 on success. */ -static int split_groups (unsigned int max_members) +static int split_groups(unsigned int max_members) { struct commonio_entry *gr; @@ -421,18 +421,18 @@ static int split_groups (unsigned int max_members) /* Enforce the maximum number of members on gptr */ for (i = max_members; NULL != gptr->gr_mem[i]; i++) { - free (gptr->gr_mem[i]); + free(gptr->gr_mem[i]); gptr->gr_mem[i] = NULL; } /* Shift all the members */ /* The number of members in new_gptr will be check later */ for (i = 0; NULL != new_gptr->gr_mem[i + max_members]; i++) { - free (new_gptr->gr_mem[i]); + free(new_gptr->gr_mem[i]); new_gptr->gr_mem[i] = new_gptr->gr_mem[i + max_members]; new_gptr->gr_mem[i + max_members] = NULL; } for (; NULL != new_gptr->gr_mem[i]; i++) { - free (new_gptr->gr_mem[i]); + free(new_gptr->gr_mem[i]); new_gptr->gr_mem[i] = NULL; } diff --git a/lib/groupmem.c b/lib/groupmem.c index 1ebe2f9ba0..458c29eb6b 100644 --- a/lib/groupmem.c +++ b/lib/groupmem.c @@ -56,7 +56,7 @@ return NULL; } for (i = 0; grent->gr_mem[i]; i++) { - gr->gr_mem[i] = strdup (grent->gr_mem[i]); + gr->gr_mem[i] = strdup(grent->gr_mem[i]); if (NULL == gr->gr_mem[i]) { gr_free(gr); return NULL; @@ -67,14 +67,14 @@ return gr; } -void gr_free_members (struct group *grent) +void gr_free_members(struct group *grent) { if (NULL != grent->gr_mem) { size_t i; for (i = 0; NULL != grent->gr_mem[i]; i++) { - free (grent->gr_mem[i]); + free(grent->gr_mem[i]); } - free (grent->gr_mem); + free(grent->gr_mem); grent->gr_mem = NULL; } } diff --git a/lib/hushed.c b/lib/hushed.c index 1b1fc40a2e..6498eccc24 100644 --- a/lib/hushed.c +++ b/lib/hushed.c @@ -33,7 +33,7 @@ * Look in the hushed-logins file (or user's home directory) to see * if the user is to receive the login-time messages. */ -bool hushed (const char *username) +bool hushed(const char *username) { bool found; char buf[BUFSIZ]; @@ -46,12 +46,12 @@ bool hushed (const char *username) * defined, default to a noisy login. */ - hushfile = getdef_str ("HUSHLOGIN_FILE"); + hushfile = getdef_str("HUSHLOGIN_FILE"); if (NULL == hushfile) { return false; } - pw = getpwnam (username); + pw = getpwnam(username); if (NULL == pw) { return false; } @@ -63,7 +63,7 @@ bool hushed (const char *username) if (hushfile[0] != '/') { stprintf_a(buf, "%s/%s", pw->pw_dir, hushfile); - return (access (buf, F_OK) == 0); + return (access(buf, F_OK) == 0); } /* @@ -71,7 +71,7 @@ bool hushed (const char *username) * and see if this user, or its shell is in there. */ - fp = fopen (hushfile, "r"); + fp = fopen(hushfile, "r"); if (NULL == fp) { return false; } @@ -80,7 +80,7 @@ bool hushed (const char *username) found = streq(buf, pw->pw_shell) || streq(buf, pw->pw_name); } - (void) fclose (fp); + (void) fclose(fp); return found; } diff --git a/lib/idmapping.c b/lib/idmapping.c index 88a0c00e47..a1aff899e8 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -161,7 +161,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. */ - bzero(data, 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 diff --git a/lib/limits.c b/lib/limits.c index 129a99fd75..1e6ae601d6 100644 --- a/lib/limits.c +++ b/lib/limits.c @@ -50,7 +50,7 @@ * value - string value to be read * multiplier - value*multiplier is the actual limit */ -static int setrlimit_value (unsigned int resource, +static int setrlimit_value(unsigned int resource, const char *value, unsigned int multiplier) { @@ -80,7 +80,7 @@ static int setrlimit_value (unsigned int resource, rlim.rlim_cur = limit; rlim.rlim_max = limit; - if (setrlimit (resource, &rlim) != 0) { + if (setrlimit(resource, &rlim) != 0) { return LOGIN_ERROR_RLIMIT; } return 0; @@ -95,7 +95,7 @@ set_prio(const char *value) if (str2si(&prio, value) == -1) return 0; - if (setpriority (PRIO_PROCESS, 0, prio) != 0) { + if (setpriority(PRIO_PROCESS, 0, prio) != 0) { return LOGIN_ERROR_RLIMIT; } return 0; @@ -110,7 +110,7 @@ set_umask(const char *value) if (str2i(mode_t, &mask, value) == -1) return 0; - (void) umask (mask); + (void) umask(mask); return 0; } @@ -136,7 +136,7 @@ static int check_logins (const char *name, const char *maxlogins) count = active_sessions_count(name, limit); if (count > limit) { - SYSLOG(LOG_WARN, "Too many logins (max %lu) for %s\n", limit, name); + SYSLOG(LOG_WARN, "Too many logins(max %lu) for %s\n", limit, name); return LOGIN_ERROR_LOGIN; } return 0; @@ -177,7 +177,7 @@ static int check_logins (const char *name, const char *maxlogins) * buf - the limits string * name - the username */ -static int do_user_limits (const char *buf, const char *name) +static int do_user_limits(const char *buf, const char *name) { const char *pp; int retval = 0; @@ -209,7 +209,7 @@ static int do_user_limits (const char *buf, const char *name) case 'c': case 'C': /* RLIMIT_CORE - max core file size (KB) */ - retval |= setrlimit_value (RLIMIT_CORE, pp, 1024); + retval |= setrlimit_value(RLIMIT_CORE, pp, 1024); break; case 'd': case 'D': @@ -219,7 +219,7 @@ static int do_user_limits (const char *buf, const char *name) case 'f': case 'F': /* RLIMIT_FSIZE - Maximum filesize (KB) */ - retval |= setrlimit_value (RLIMIT_FSIZE, pp, 1024); + retval |= setrlimit_value(RLIMIT_FSIZE, pp, 1024); break; #ifdef RLIMIT_NICE case 'i': @@ -235,7 +235,7 @@ static int do_user_limits (const char *buf, const char *name) case 'l': case 'L': /* LIMIT the number of concurrent logins */ - retval |= check_logins (name, pp); + retval |= check_logins(name, pp); break; #ifdef RLIMIT_MEMLOCK case 'm': @@ -247,7 +247,7 @@ static int do_user_limits (const char *buf, const char *name) case 'n': case 'N': /* RLIMIT_NOFILE - max number of open files */ - retval |= setrlimit_value (RLIMIT_NOFILE, pp, 1); + retval |= setrlimit_value(RLIMIT_NOFILE, pp, 1); break; #ifdef RLIMIT_RTPRIO case 'o': @@ -264,7 +264,7 @@ static int do_user_limits (const char *buf, const char *name) case 'r': case 'R': /* RLIMIT_RSS - max resident set size (KB) */ - retval |= setrlimit_value (RLIMIT_RSS, pp, 1024); + retval |= setrlimit_value(RLIMIT_RSS, pp, 1024); break; #endif case 's': @@ -275,7 +275,7 @@ static int do_user_limits (const char *buf, const char *name) case 't': case 'T': /* RLIMIT_CPU - max CPU time (MIN) */ - retval |= setrlimit_value (RLIMIT_CPU, pp, 60); + retval |= setrlimit_value(RLIMIT_CPU, pp, 60); break; #ifdef RLIMIT_NPROC case 'u': @@ -315,7 +315,7 @@ static int do_user_limits (const char *buf, const char *name) * Returns true when user is in the group, false when not. * Any error is treated as false. */ -static bool user_in_group (const char *uname, const char *gname) +static bool user_in_group(const char *uname, const char *gname) { struct group *groupdata; @@ -326,16 +326,16 @@ static bool user_in_group (const char *uname, const char *gname) /* We are not claiming to be re-entrant! * In case of paranoia or a multithreaded login program, * one needs to add some mess for getgrnam_r. */ - groupdata = getgrnam (gname); + groupdata = getgrnam(gname); if (NULL == groupdata) { SYSLOG(LOG_WARN, "Nonexisting group `%s' in limits file.", gname); return false; } - return is_on_list (groupdata->gr_mem, uname); + return is_on_list(groupdata->gr_mem, uname); } -static int setup_user_limits (const char *uname) +static int setup_user_limits(const char *uname) { FILE *fil; char buf[1024]; @@ -352,7 +352,7 @@ static int setup_user_limits (const char *uname) memzero_a(tempbuf); /* start the checks */ - fil = fopen (LIMITS_FILE, "r"); + fil = fopen(LIMITS_FILE, "r"); if (fil == NULL) { return 0; } @@ -387,25 +387,25 @@ static int setup_user_limits (const char *uname) * the last encountered entry for a matching group rules. * If there is no matching group entry, the default limits rule. */ - if (sscanf (buf, "%s%[ACDFIKLMNOPRSTUacdfiklmnoprstu0-9 \t-]", + if (sscanf(buf, "%s%[ACDFIKLMNOPRSTUacdfiklmnoprstu0-9 \t-]", name, tempbuf) == 2) { if (streq(name, uname)) { - strcpy (limits, tempbuf); + strcpy(limits, tempbuf); break; } else if (streq(name, "*")) { - strcpy (deflimits, tempbuf); + strcpy(deflimits, tempbuf); } else if (strprefix(name, "@")) { /* If the user is in the group, the group * limits apply unless later a line for * the specific user is found. */ - if (user_in_group (uname, name+1)) { - strcpy (limits, tempbuf); + if (user_in_group(uname, name+1)) { + strcpy(limits, tempbuf); } } } } - (void) fclose (fil); + (void) fclose(fil); if (streq(limits, "")) { /* no user specific limits */ if (streq(deflimits, "")) { /* no default limits */ @@ -443,12 +443,12 @@ static void setup_usergroups (const struct passwd *info) * set the process nice, ulimit, and umask from the password file entry */ -void setup_limits (const struct passwd *info) +void setup_limits(const struct passwd *info) { char *cp; - if (getdef_bool ("USERGROUPS_ENAB")) { - setup_usergroups (info); + if (getdef_bool("USERGROUPS_ENAB")) { + setup_usergroups(info); } /* @@ -457,10 +457,10 @@ void setup_limits (const struct passwd *info) * values the defaults for this login session. */ - if (getdef_bool ("QUOTAS_ENAB")) { + if (getdef_bool("QUOTAS_ENAB")) { 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()); + if ((setup_user_limits(info->pw_name) & LOGIN_ERROR_LOGIN) != 0) { + (void) fputs(_("Too many logins.\n"), log_get_logfd()); (void) sleep (2); /* XXX: should be FAIL_DELAY */ exit (EXIT_FAILURE); } @@ -495,7 +495,7 @@ void setup_limits (const struct passwd *info) int blocks; if ( (str2si(&blocks, val) == -1) - || (set_filesize_limit (blocks) != 0)) { + || (set_filesize_limit(blocks) != 0)) { SYSLOG(LOG_WARN, "Can't set the ulimit for user %s", info->pw_name); @@ -512,7 +512,7 @@ void setup_limits (const struct passwd *info) "Can't set umask value for user %s", info->pw_name); } else { - (void) umask (mask); + (void) umask(mask); } continue; diff --git a/lib/list.c b/lib/list.c index 8fa0e085ac..3f18972a10 100644 --- a/lib/list.c +++ b/lib/list.c @@ -33,8 +33,8 @@ add_list(/*@returned@*/ /*@only@*/char **list, const char *member) int i; char **tmp; - assert (NULL != member); - assert (NULL != list); + assert(NULL != member); + assert(NULL != list); /* * Scan the list for the new name. Return the original list @@ -64,7 +64,7 @@ add_list(/*@returned@*/ /*@only@*/char **list, const char *member) tmp[i] = list[i]; } - tmp[i] = xstrdup (member); + tmp[i] = xstrdup(member); tmp[i+1] = NULL; return tmp; @@ -84,8 +84,8 @@ del_list(/*@returned@*/ /*@only@*/char **list, const char *member) int i, j; char **tmp; - assert (NULL != member); - assert (NULL != list); + assert(NULL != member); + assert(NULL != list); /* * Scan the list for the old name. Return the original list @@ -173,10 +173,10 @@ free_list(char **list) * function with list of members, the list elements are not enforced to be * constant strings here. */ -bool is_on_list (char *const *list, const char *member) +bool is_on_list(char *const *list, const char *member) { - assert (NULL != member); - assert (NULL != list); + assert(NULL != member); + assert(NULL != list); while (NULL != *list) { if (streq(*list, member)) { @@ -205,7 +205,7 @@ comma_to_list(const char *comma) * Make a copy since we are going to be modifying the list */ - members = xstrdup (comma); + members = xstrdup(comma); /* * Allocate the array we're going to store the pointers into. @@ -221,7 +221,7 @@ comma_to_list(const char *comma) if (streq(members, "")) { *array = NULL; - free (members); + free(members); return array; } diff --git a/lib/lockpw.c b/lib/lockpw.c index 4f357b48b9..36797d7c46 100644 --- a/lib/lockpw.c +++ b/lib/lockpw.c @@ -19,7 +19,7 @@ /* * lckpwdf - lock the password files */ -int lckpwdf (void) +int lckpwdf(void) { int i; @@ -28,10 +28,10 @@ int lckpwdf (void) */ for (i = 0; i < 15; i++) - if (pw_lock ()) + if (pw_lock()) break; else - sleep (1); + sleep(1); /* * Did we run out of time? @@ -46,17 +46,17 @@ int lckpwdf (void) */ for (; i < 15; i++) - if (spw_lock ()) + if (spw_lock()) break; else - sleep (1); + sleep(1); /* * Out of time yet? */ if (i == 15) { - pw_unlock (true); + pw_unlock(true); return -1; } @@ -71,14 +71,14 @@ int lckpwdf (void) * ulckpwdf - unlock the password files */ -int ulckpwdf (void) +int ulckpwdf(void) { /* * Unlock both files. */ - return (pw_unlock (true) && spw_unlock (true))? 0 : -1; + return (pw_unlock(true) && spw_unlock(true))? 0 : -1; } #else extern int ISO_C_forbids_an_empty_translation_unit; diff --git a/lib/log.c b/lib/log.c index 52abbead16..a9c76e3c41 100644 --- a/lib/log.c +++ b/lib/log.c @@ -31,7 +31,7 @@ * UID is extracted from the global (struct passwd) entry and the * TTY information is gotten from the (struct utmpx). */ -void dolastlog ( +void dolastlog( struct lastlog *ll, const struct passwd *pw, /*@unique@*/const char *line, @@ -56,13 +56,13 @@ void dolastlog ( * for this UID. Negative UID's will create problems, but ... */ - offset = (off_t) pw->pw_uid * sizeof(newlog); + offset = (off_t) pw->pw_uid * sizeof (newlog); - if (lseek (fd, offset, SEEK_SET) != offset) { + if (lseek(fd, offset, SEEK_SET) != offset) { SYSLOG(LOG_WARN, "Can't read last lastlog entry for UID %lu in %s. Entry not updated.", (unsigned long) pw->pw_uid, _PATH_LASTLOG); - (void) close (fd); + (void) close(fd); return; } @@ -72,8 +72,8 @@ void dolastlog ( * the way we read the old one in. */ - if (read(fd, &newlog, sizeof(newlog)) != (ssize_t) sizeof(newlog)) { - memzero(&newlog, sizeof(newlog)); + if (read(fd, &newlog, sizeof (newlog)) != (ssize_t) sizeof (newlog)) { + memzero(&newlog, sizeof (newlog)); } if (NULL != ll) { *ll = newlog; @@ -86,12 +86,12 @@ void dolastlog ( #if HAVE_LL_HOST strncpy_a(newlog.ll_host, host); #endif - if ( (lseek (fd, offset, SEEK_SET) != offset) - || (write_full(fd, &newlog, sizeof(newlog)) == -1)) { + if ( (lseek(fd, offset, SEEK_SET) != offset) + || (write_full(fd, &newlog, sizeof (newlog)) == -1)) { goto err_write; } - if (close (fd) != 0 && errno != EINTR) { + if (close(fd) != 0 && errno != EINTR) { goto err_close; } @@ -100,7 +100,7 @@ void dolastlog ( err_write: { int saved_errno = errno; - (void) close (fd); + (void) close(fd); errno = saved_errno; } err_close: diff --git a/lib/logind.c b/lib/logind.c index 3ba3341af0..0c3870fe17 100644 --- a/lib/logind.c +++ b/lib/logind.c @@ -14,7 +14,7 @@ #include -int get_session_host (char **out, pid_t main_pid) +int get_session_host(char **out, pid_t main_pid) { char *host = NULL; char *session = NULL; @@ -24,7 +24,7 @@ int get_session_host (char **out, pid_t main_pid) if (ret < 0) { return ret; } - ret = sd_session_get_remote_host (session, &host); + ret = sd_session_get_remote_host(session, &host); if (ret < 0) { goto done; } @@ -32,7 +32,7 @@ int get_session_host (char **out, pid_t main_pid) *out = host; done: - free (session); + free(session); return ret; } diff --git a/lib/loginprompt.c b/lib/loginprompt.c index 9eeae3ddb0..a937c2be3c 100644 --- a/lib/loginprompt.c +++ b/lib/loginprompt.c @@ -27,7 +27,7 @@ static void login_exit(MAYBE_UNUSED int _1) { - _exit (EXIT_FAILURE); + _exit(EXIT_FAILURE); } /* @@ -44,7 +44,7 @@ login_prompt(char *name, int namesize) char *cp; int i; FILE *fp; - const char *fname = getdef_str ("ISSUE_FILE"); + const char *fname = getdef_str("ISSUE_FILE"); sighandler_t sigquit; sighandler_t sigtstp; @@ -55,8 +55,8 @@ login_prompt(char *name, int namesize) * instead of core dumping. Do the same thing for SIGTSTP. */ - sigquit = signal (SIGQUIT, login_exit); - sigtstp = signal (SIGTSTP, login_exit); + sigquit = signal(SIGQUIT, login_exit); + sigtstp = signal(SIGTSTP, login_exit); /* * See if the user has configured the issue file to @@ -64,18 +64,18 @@ login_prompt(char *name, int namesize) */ if (NULL != fname) { - fp = fopen (fname, "r"); + fp = fopen(fname, "r"); if (NULL != fp) { - while ((i = getc (fp)) != EOF) { - (void) putc (i, stdout); + while ((i = getc(fp)) != EOF) { + (void) putc(i, stdout); } - (void) fclose (fp); + (void) fclose(fp); } } - (void) gethostname(buf, sizeof(buf)); - printf (_("\n%s login: "), buf); - (void) fflush (stdout); + (void) gethostname(buf, sizeof (buf)); + printf(_("\n%s login: "), buf); + (void) fflush(stdout); /* * Read the user's response. The trailing newline will be @@ -84,7 +84,7 @@ login_prompt(char *name, int namesize) memzero_a(buf); if (fgets_a(buf, stdin) == NULL) - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); if (stpsep(buf, "\n") == NULL) exit(EXIT_FAILURE); @@ -101,7 +101,7 @@ login_prompt(char *name, int namesize) * Set the SIGQUIT handler back to its original value */ - (void) signal (SIGQUIT, sigquit); - (void) signal (SIGTSTP, sigtstp); + (void) signal(SIGQUIT, sigquit); + (void) signal(SIGTSTP, sigtstp); } diff --git a/lib/mail.c b/lib/mail.c index b48cee1cb9..839c20ef78 100644 --- a/lib/mail.c +++ b/lib/mail.c @@ -19,46 +19,46 @@ #include "string/sprintf/aprintf.h" -void mailcheck (void) +void mailcheck(void) { struct stat statbuf; char *mailbox; - if (!getdef_bool ("MAIL_CHECK_ENAB")) { + if (!getdef_bool("MAIL_CHECK_ENAB")) { return; } /* * Check incoming mail in Maildir format - J. */ - mailbox = getenv ("MAILDIR"); + mailbox = getenv("MAILDIR"); if (NULL != mailbox) { char *newmail; newmail = xaprintf("%s/new", mailbox); - if (stat (newmail, &statbuf) != -1 && statbuf.st_size != 0) { + if (stat(newmail, &statbuf) != -1 && statbuf.st_size != 0) { if (statbuf.st_mtime > statbuf.st_atime) { free(newmail); - (void) puts (_("You have new mail.")); + (void) puts(_("You have new mail.")); return; } } free(newmail); } - mailbox = getenv ("MAIL"); + mailbox = getenv("MAIL"); if (NULL == mailbox) { return; } - if ( (stat (mailbox, &statbuf) == -1) + if ( (stat(mailbox, &statbuf) == -1) || (statbuf.st_size == 0)) { - (void) puts (_("No mail.")); + (void) puts(_("No mail.")); } else if (statbuf.st_atime > statbuf.st_mtime) { - (void) puts (_("You have mail.")); + (void) puts(_("You have mail.")); } else { - (void) puts (_("You have new mail.")); + (void) puts(_("You have new mail.")); } } diff --git a/lib/motd.c b/lib/motd.c index 147e5a1eb7..cf4c86d651 100644 --- a/lib/motd.c +++ b/lib/motd.c @@ -34,7 +34,7 @@ motd(void) char *mb; int c; - motdfile = getdef_str ("MOTD_FILE"); + motdfile = getdef_str("MOTD_FILE"); if (NULL == motdfile) return 0; @@ -44,7 +44,7 @@ motd(void) mb = motdlist; while (NULL != (motdfile = strsep(&mb, ":"))) { - fp = fopen (motdfile, "r"); + fp = fopen(motdfile, "r"); if (fp == NULL) continue; @@ -53,8 +53,8 @@ motd(void) } fclose(fp); } - fflush (stdout); + fflush(stdout); - free (motdlist); + free(motdlist); return 0; } diff --git a/lib/myname.c b/lib/myname.c index 2c2f218d14..585fe31e74 100644 --- a/lib/myname.c +++ b/lib/myname.c @@ -39,15 +39,15 @@ * the original user, like getlogin() does). Does this matter? */ if ((NULL != cp) && !streq(cp, "")) { - pw = xgetpwnam (cp); + pw = xgetpwnam(cp); if ((NULL != pw) && (pw->pw_uid == ruid)) { return pw; } if (NULL != pw) { - pw_free (pw); + pw_free(pw); } } - return xgetpwuid (ruid); + return xgetpwuid(ruid); } diff --git a/lib/nscd.c b/lib/nscd.c index 732164ceac..cd359272d3 100644 --- a/lib/nscd.c +++ b/lib/nscd.c @@ -17,14 +17,14 @@ /* * nscd_flush_cache - flush specified service buffer in nscd cache */ -int nscd_flush_cache (const char *service) +int nscd_flush_cache(const char *service) { int status, code; const char *cmd = "/usr/sbin/nscd"; const char *spawnedArgs[] = {"nscd", "-i", service, NULL}; const char *spawnedEnv[] = {NULL}; - if (run_command (cmd, spawnedArgs, spawnedEnv, &status) != 0) { + if (run_command(cmd, spawnedArgs, spawnedEnv, &status) != 0) { /* run_command writes its own more detailed message. */ (void) fprintf (log_get_logfd(), _(MSG_NSCD_FLUSH_CACHE_FAILED), log_get_progname()); return -1; diff --git a/lib/nscd.h b/lib/nscd.h index a430b00f05..c37660978d 100644 --- a/lib/nscd.h +++ b/lib/nscd.h @@ -5,7 +5,7 @@ * nscd_flush_cache - flush specified service buffer in nscd cache */ #ifdef USE_NSCD -extern int nscd_flush_cache (const char *service); +extern int nscd_flush_cache(const char *service); #else #define nscd_flush_cache(service) (0) #endif diff --git a/lib/nss.c b/lib/nss.c index 5957390741..3f6ea9ab10 100644 --- a/lib/nss.c +++ b/lib/nss.c @@ -103,7 +103,7 @@ nss_init(const char *nsswitch_path) { goto null_subid; } if (strlen(p) > 50) { - fprintf(log_get_logfd(), "Subid NSS module name too long (longer than 50 characters): %s\n", p); + fprintf(log_get_logfd(), "Subid NSS module name too long(longer than 50 characters): %s\n", p); fprintf(log_get_logfd(), "Using files\n"); goto null_subid; } diff --git a/lib/obscure.c b/lib/obscure.c index 9a53df85e3..68763a1d5d 100644 --- a/lib/obscure.c +++ b/lib/obscure.c @@ -38,7 +38,7 @@ palindrome(const char *new) { size_t i, j; - i = strlen (new); + i = strlen(new); for (j = 0; j < i; j++) { if (new[i - j - 1] != new[j]) { @@ -63,7 +63,7 @@ static bool similar (/*@notnull@*/const char *old, /*@notnull@*/const char *new) * the new password is long enough. Please feel free to suggest * something better... --marekm */ - if (strlen (new) >= 8) { + if (strlen(new) >= 8) { return false; } @@ -120,8 +120,8 @@ static /*@observer@*//*@null@*/const char *obscure_msg ( char *new1, *old1; const char *msg; - oldlen = strlen (old); - newlen = strlen (new); + oldlen = strlen(old); + newlen = strlen(new); obscure_get_range(&minlen, &maxlen); @@ -132,7 +132,7 @@ static /*@observer@*//*@null@*/const char *obscure_msg ( /* * Remaining checks are optional. */ - if (!getdef_bool ("OBSCURE_CHECKS_ENAB")) { + if (!getdef_bool("OBSCURE_CHECKS_ENAB")) { return NULL; } @@ -156,8 +156,8 @@ static /*@observer@*//*@null@*/const char *obscure_msg ( return NULL; } - new1 = xstrdup (new); - old1 = xstrdup (old); + new1 = xstrdup(new); + old1 = xstrdup(old); if (newlen > (size_t) maxlen) stpcpy(&new1[maxlen], ""); if (oldlen > (size_t) maxlen) @@ -165,8 +165,8 @@ static /*@observer@*//*@null@*/const char *obscure_msg ( msg = password_check(old1, new1); - freezero (new1, newlen); - freezero (old1, oldlen); + freezero(new1, newlen); + freezero(old1, oldlen); return msg; } @@ -185,7 +185,7 @@ obscure(const char *old, const char *new) const char *msg = obscure_msg(old, new); if (NULL != msg) { - printf (_("Bad password: %s. "), msg); + printf(_("Bad password: %s. "), msg); return false; } return true; @@ -214,7 +214,7 @@ obscure_get_range(int *minlen, int *maxlen) return; } - method = getdef_str ("ENCRYPT_METHOD"); + method = getdef_str("ENCRYPT_METHOD"); if (NULL != method) { if ( streq(method, "MD5") || streq(method, "SHA256") @@ -229,5 +229,5 @@ obscure_get_range(int *minlen, int *maxlen) return; } } - *maxlen = getdef_num ("PASS_MAX_LEN", 8); + *maxlen = getdef_num("PASS_MAX_LEN", 8); } diff --git a/lib/pam_pass.c b/lib/pam_pass.c index d6372e1a2c..f739aab85f 100644 --- a/lib/pam_pass.c +++ b/lib/pam_pass.c @@ -28,7 +28,7 @@ #include "prototypes.h" #include "shadowlog.h" -void do_pam_passwd (const char *user, bool silent, bool change_expired) +void do_pam_passwd(const char *user, bool silent, bool change_expired) { pam_handle_t *pamh = NULL; int flags = 0, ret; @@ -38,23 +38,23 @@ void do_pam_passwd (const char *user, bool silent, bool change_expired) if (change_expired) flags |= PAM_CHANGE_EXPIRED_AUTHTOK; - ret = pam_start ("passwd", user, &conv, &pamh); + ret = pam_start("passwd", user, &conv, &pamh); if (ret != PAM_SUCCESS) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("passwd: pam_start() failed, error %d\n"), ret); - exit (E_PAM_ERR); + exit(E_PAM_ERR); } - ret = pam_chauthtok (pamh, flags); + ret = pam_chauthtok(pamh, flags); if (ret != PAM_SUCCESS) { - fprintf (log_get_logfd(), _("passwd: %s\n"), pam_strerror (pamh, ret)); - fputs (_("passwd: password unchanged\n"), log_get_logfd()); - pam_end (pamh, ret); - exit (E_PAM_ERR); + fprintf(log_get_logfd(), _("passwd: %s\n"), pam_strerror(pamh, ret)); + fputs(_("passwd: password unchanged\n"), log_get_logfd()); + pam_end(pamh, ret); + exit(E_PAM_ERR); } - fputs (_("passwd: password updated successfully\n"), log_get_logfd()); - (void) pam_end (pamh, PAM_SUCCESS); + fputs(_("passwd: password updated successfully\n"), log_get_logfd()); + (void) pam_end(pamh, PAM_SUCCESS); } #else /* !USE_PAM */ extern int ISO_C_forbids_an_empty_translation_unit; diff --git a/lib/pam_pass_non_interactive.c b/lib/pam_pass_non_interactive.c index 6a8dcd78cf..b1a7362487 100644 --- a/lib/pam_pass_non_interactive.c +++ b/lib/pam_pass_non_interactive.c @@ -116,31 +116,31 @@ static int ni_conv (int num_msg, * * Return 0 on success, 1 on failure. */ -int do_pam_passwd_non_interactive (const char *pam_service, +int do_pam_passwd_non_interactive(const char *pam_service, const char *username, const char* password) { pam_handle_t *pamh = NULL; int ret; - ret = pam_start (pam_service, username, &non_interactive_pam_conv, &pamh); + ret = pam_start(pam_service, username, &non_interactive_pam_conv, &pamh); if (ret != PAM_SUCCESS) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: (user %s) pam_start failure %d\n"), log_get_progname(), username, ret); return 1; } non_interactive_password = password; - ret = pam_chauthtok (pamh, 0); + ret = pam_chauthtok(pamh, 0); if (ret != PAM_SUCCESS) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: (user %s) pam_chauthtok() failed, error:\n" "%s\n"), - log_get_progname(), username, pam_strerror (pamh, ret)); + log_get_progname(), username, pam_strerror(pamh, ret)); } - (void) pam_end (pamh, PAM_SUCCESS); + (void) pam_end(pamh, PAM_SUCCESS); return ((PAM_SUCCESS == ret) ? 0 : 1); } diff --git a/lib/port.c b/lib/port.c index 8cf6f39fb9..1ae3679648 100644 --- a/lib/port.c +++ b/lib/port.c @@ -38,7 +38,7 @@ static FILE *ports; * A match returns 0, failure returns non-zero. */ -static int portcmp (const char *pattern, const char *port) +static int portcmp(const char *pattern, const char *port) { const char *orig = port; @@ -63,12 +63,12 @@ static int portcmp (const char *pattern, const char *port) * opened for reading. */ -static void setportent (void) +static void setportent(void) { if (NULL != ports) { - rewind (ports); + rewind(ports); } else { - ports = fopen (PORTS, "r"); + ports = fopen(PORTS, "r"); } } @@ -80,10 +80,10 @@ static void setportent (void) * open. */ -static void endportent (void) +static void endportent(void) { if (NULL != ports) { - (void) fclose (ports); + (void) fclose(ports); } ports = NULL; @@ -121,7 +121,7 @@ getportent(void) */ if (NULL == ports) { - setportent (); + setportent(); } if (NULL == ports) { @@ -261,7 +261,7 @@ getportent(void) * representing the times of day. */ - for (dtime = 0; isdigit (cp[i]); i++) { + for (dtime = 0; isdigit(cp[i]); i++) { dtime = dtime * 10 + cp[i] - '0'; } @@ -271,7 +271,7 @@ getportent(void) port.pt_times[j].t_start = dtime; cp = cp + i + 1; - for (dtime = 0, i = 0; isdigit (cp[i]); i++) { + for (dtime = 0, i = 0; isdigit(cp[i]); i++) { dtime = dtime * 10 + cp[i] - '0'; } @@ -341,7 +341,7 @@ getttyuser(const char *tty, const char *user) * the user name and TTY given. */ -bool isttytime (const char *id, const char *port, time_t when) +bool isttytime(const char *id, const char *port, time_t when) { int i; int dtime; @@ -354,7 +354,7 @@ bool isttytime (const char *id, const char *port, time_t when) * entry to match all users. */ - pp = getttyuser (port, id); + pp = getttyuser(port, id); if (NULL == pp) { return true; } @@ -373,7 +373,7 @@ bool isttytime (const char *id, const char *port, time_t when) * comparison against the time values in the TTY entry. */ - tm = localtime (&when); + tm = localtime(&when); dtime = tm->tm_hour * 100 + tm->tm_min; /* @@ -384,7 +384,7 @@ bool isttytime (const char *id, const char *port, time_t when) */ for (i = 0; pp->pt_times[i].t_start != -1; i++) { - if (!(pp->pt_times[i].t_days & PORT_DAY (tm->tm_wday))) { + if (!(pp->pt_times[i].t_days & PORT_DAY(tm->tm_wday))) { continue; } diff --git a/lib/prefix_flag.c b/lib/prefix_flag.c index 7496805e9a..8efd7ed3b9 100644 --- a/lib/prefix_flag.c +++ b/lib/prefix_flag.c @@ -52,7 +52,7 @@ static FILE* fp_grent = NULL; * * The audit, syslog, or locale files shall be open before */ -extern const char* process_prefix_flag (const char* short_opt, int argc, char **argv) +extern const char* process_prefix_flag(const char* short_opt, int argc, char **argv) { const char *prefix = NULL; @@ -66,19 +66,19 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char ** || streq(argv[i], short_opt)) { if (NULL != prefix) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: multiple --prefix options\n"), log_get_progname()); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } if (val) { prefix = val; } else if (i + 1 == argc) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: option '%s' requires an argument\n"), log_get_progname(), argv[i]); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } else { prefix = argv[++ i]; } diff --git a/lib/prototypes.h b/lib/prototypes.h index 411f8d559c..fe31e86a72 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -67,13 +67,13 @@ extern int chown_tree (const char *root, gid_t old_gid, gid_t new_gid); /* chowntty.c */ -extern void chown_tty (const struct passwd *); +extern void chown_tty(const struct passwd *); /* cleanup.c */ typedef /*@null@*/void (*cleanup_function) (/*@null@*/void *arg); void add_cleanup (/*@notnull@*/cleanup_function pcf, /*@null@*/void *arg); void del_cleanup (/*@notnull@*/cleanup_function pcf); -void do_cleanups (void); +void do_cleanups(void); /* cleanup_group.c */ struct cleanup_info_mod { @@ -81,30 +81,30 @@ struct cleanup_info_mod { char *action; /*@observer@*/const char *name; }; -void cleanup_report_add_group (void *group_name); -void cleanup_report_add_group_group (void *group_name); +void cleanup_report_add_group(void *group_name); +void cleanup_report_add_group_group(void *group_name); #ifdef SHADOWGRP -void cleanup_report_add_group_gshadow (void *group_name); +void cleanup_report_add_group_gshadow(void *group_name); #endif -void cleanup_report_del_group (void *group_name); -void cleanup_report_del_group_group (void *group_name); +void cleanup_report_del_group(void *group_name); +void cleanup_report_del_group_group(void *group_name); #ifdef SHADOWGRP -void cleanup_report_del_group_gshadow (void *group_name); +void cleanup_report_del_group_gshadow(void *group_name); #endif -void cleanup_report_mod_passwd (void *cleanup_info); -void cleanup_report_mod_group (void *cleanup_info); -void cleanup_report_mod_gshadow (void *cleanup_info); -void cleanup_unlock_group (void *process_selinux); +void cleanup_report_mod_passwd(void *cleanup_info); +void cleanup_report_mod_group(void *cleanup_info); +void cleanup_report_mod_gshadow(void *cleanup_info); +void cleanup_unlock_group(void *process_selinux); #ifdef SHADOWGRP -void cleanup_unlock_gshadow (void *process_selinux); +void cleanup_unlock_gshadow(void *process_selinux); #endif -void cleanup_unlock_passwd (void *process_selinux); +void cleanup_unlock_passwd(void *process_selinux); /* console.c */ extern bool console (const char *); /* copydir.c */ -extern int copy_tree (const char *src_root, const char *dst_root, +extern int copy_tree(const char *src_root, const char *dst_root, bool copy_root, uid_t old_uid, uid_t new_uid, gid_t old_gid, gid_t new_gid); @@ -114,26 +114,26 @@ extern /*@exposed@*//*@null@*/char *pw_encrypt (const char *, const char *); /* env.c */ extern void addenv (const char *, /*@null@*/const char *); -extern void initenv (void); -extern void set_env (int, char *const *); -extern void sanitize_env (void); +extern void initenv(void); +extern void set_env(int, char *const *); +extern void sanitize_env(void); /* fd.c */ extern void check_fds (void); /* find_new_gid.c */ -extern int find_new_gid (bool sys_group, +extern int find_new_gid(bool sys_group, gid_t *gid, /*@null@*/gid_t const *preferred_gid); /* find_new_uid.c */ -extern int find_new_uid (bool sys_user, +extern int find_new_uid(bool sys_user, uid_t *uid, /*@null@*/uid_t const *preferred_uid); #ifdef ENABLE_SUBIDS /* find_new_sub_gids.c */ -extern int find_new_sub_gids (id_t *range_start, unsigned long *range_count); +extern int find_new_sub_gids(id_t *range_start, unsigned long *range_count); /* find_new_sub_uids.c */ extern int find_new_sub_uids (id_t *range_start, unsigned long *range_count); @@ -152,7 +152,7 @@ extern int getrange (const char *range, unsigned long *max, bool *has_max); /* gettime.c */ -extern time_t gettime (void); +extern time_t gettime(void); /* groupio.c */ extern void __gr_del_entry (const struct commonio_entry *ent); @@ -171,7 +171,7 @@ extern bool hushed (const char *username); /* audit_help.c */ #ifdef WITH_AUDIT extern int audit_fd; -extern void audit_help_open (void); +extern void audit_help_open(void); /* Use AUDIT_NO_ID when a name is provided to audit_logger instead of an ID */ #define AUDIT_NO_ID ((unsigned int) -1) typedef enum { @@ -188,20 +188,20 @@ void audit_logger_with_group(int type, const char *op, const char *name, /* limits.c */ #ifndef USE_PAM -extern void setup_limits (const struct passwd *); +extern void setup_limits(const struct passwd *); #endif /* list.c */ extern /*@only@*/char **add_list (/*@returned@*/ /*@only@*/char **, const char *); extern /*@only@*/char **del_list (/*@returned@*/ /*@only@*/char **, const char *); extern /*@only@*/char **dup_list (char *const *); -extern void free_list (char **); -extern bool is_on_list (char *const *list, const char *member); +extern void free_list(char **); +extern bool is_on_list(char *const *list, const char *member); extern /*@only@*/char **comma_to_list (const char *); #ifdef ENABLE_LASTLOG /* log.c */ -extern void dolastlog ( +extern void dolastlog( struct lastlog *ll, const struct passwd *pw, /*@unique@*/const char *line, @@ -212,7 +212,7 @@ extern void dolastlog ( extern int login_access (const char *user, const char *from); /* loginprompt.c */ -extern void login_prompt (char *, int); +extern void login_prompt(char *, int); /* mail.c */ extern void mailcheck (void); @@ -241,7 +241,7 @@ struct subid_nss_ops { * returns success if the module was able to determine an answer (true or false), * else an error status. */ - enum subid_status (*has_range)(const char *owner, unsigned long start, unsigned long count, enum subid_type idtype, bool *result); + enum subid_status(*has_range)(const char *owner, unsigned long start, unsigned long count, enum subid_type idtype, bool *result); /* * nss_list_owner_ranges: list the subid ranges delegated to a user. @@ -256,7 +256,7 @@ struct subid_nss_ops { * returns success if the module was able to determine an answer, * else an error status. */ - enum subid_status (*list_owner_ranges)(const char *owner, enum subid_type id_type, struct subid_range **ranges, int *count); + enum subid_status(*list_owner_ranges)(const char *owner, enum subid_type id_type, struct subid_range **ranges, int *count); /* * nss_find_subid_owners: find uids who own a given subuid or subgid. @@ -270,7 +270,7 @@ struct subid_nss_ops { * returns success if the module was able to determine an answer, * else an error status. */ - enum subid_status (*find_subid_owners)(unsigned long id, enum subid_type id_type, uid_t **uids, int *count); + enum subid_status(*find_subid_owners)(unsigned long id, enum subid_type id_type, uid_t **uids, int *count); /* * nss_free: free a memory block allocated by a subid plugin. @@ -283,7 +283,7 @@ struct subid_nss_ops { * pointer is set to free(3) for backward compatibility. However, it is * strongly recommended to define this routine explicitly. */ - void (*free)(void *ptr); + void(*free)(void *ptr); /* The dlsym handle to close */ void *handle; @@ -294,7 +294,7 @@ extern struct subid_nss_ops *get_subid_nss_handle(void); /* pam_pass_non_interactive.c */ #ifdef USE_PAM -extern int do_pam_passwd_non_interactive (const char *pam_service, +extern int do_pam_passwd_non_interactive(const char *pam_service, const char *username, const char* password); #endif /* USE_PAM */ @@ -305,14 +305,14 @@ extern void obscure_get_range(int *, int *); /* pam_pass.c */ #ifdef USE_PAM -extern void do_pam_passwd (const char *user, bool silent, bool change_expired); +extern void do_pam_passwd(const char *user, bool silent, bool change_expired); #endif /* port.c */ extern bool isttytime (const char *, const char *, time_t); /* prefix_flag.c */ -extern const char* process_prefix_flag (const char* short_opt, int argc, char **argv); +extern const char* process_prefix_flag(const char* short_opt, int argc, char **argv); extern struct group *prefix_getgrnam(const char *name); extern struct group *prefix_getgrgid(gid_t gid); extern struct passwd *prefix_getpwuid(uid_t uid); @@ -342,8 +342,8 @@ extern void passwd_check(const char *, const char *); extern void pwd_init (void); /* pwio.c */ -extern void __pw_del_entry (const struct commonio_entry *ent); -extern struct commonio_db *__pw_get_db (void); +extern void __pw_del_entry(const struct commonio_entry *ent); +extern struct commonio_db *__pw_get_db(void); extern /*@dependent@*/ /*@null@*/struct commonio_entry *__pw_get_head (void); /* pwmem.c */ @@ -356,7 +356,7 @@ unsigned long csrand_uniform (unsigned long n); unsigned long csrand_interval (unsigned long min, unsigned long max); /* remove_tree.c */ -extern int remove_tree (const char *root, bool remove_root); +extern int remove_tree(const char *root, bool remove_root); /* root_flag.c */ extern void process_root_flag (const char* short_opt, int argc, char **argv); @@ -366,10 +366,10 @@ extern /*@observer@*/const char *crypt_make_salt (/*@null@*//*@observer@*/const /* selinux.c */ #ifdef WITH_SELINUX -extern int set_selinux_file_context (const char *dst_name, mode_t mode); -extern void reset_selinux_handle (void); -extern int reset_selinux_file_context (void); -extern int check_selinux_permit (const char *perm_name); +extern int set_selinux_file_context(const char *dst_name, mode_t mode); +extern void reset_selinux_handle(void); +extern int reset_selinux_file_context(void); +extern int check_selinux_permit(const char *perm_name); #endif /* semanage.c */ @@ -379,30 +379,30 @@ extern int del_seuser(const char *login_name); #endif /* setugid.c */ -extern int setup_groups (const struct passwd *info); -extern int change_uid (const struct passwd *info); +extern int setup_groups(const struct passwd *info); +extern int change_uid(const struct passwd *info); #if !defined(USE_PAM) -extern int setup_uid_gid (const struct passwd *info, bool is_console); +extern int setup_uid_gid(const struct passwd *info, bool is_console); #else -extern int setup_uid_gid (const struct passwd *info); +extern int setup_uid_gid(const struct passwd *info); #endif /* setup.c */ extern void setup (struct passwd *); /* setupenv.c */ -extern void setup_env (struct passwd *); +extern void setup_env(struct passwd *); /* sgroupio.c */ extern void __sgr_del_entry (const struct commonio_entry *ent); extern /*@null@*/ /*@only@*/struct sgrp *__sgr_dup (const struct sgrp *sgent); extern void sgr_free(/*@only@*/struct sgrp *sgent); extern /*@dependent@*/ /*@null@*/struct commonio_entry *__sgr_get_head (void); -extern void __sgr_set_changed (void); +extern void __sgr_set_changed(void); /* shadowio.c */ extern /*@dependent@*/ /*@null@*/struct commonio_entry *__spw_get_head (void); -extern void __spw_del_entry (const struct commonio_entry *ent); +extern void __spw_del_entry(const struct commonio_entry *ent); /* shadowmem.c */ extern /*@null@*/ /*@only@*/struct spwd *__spw_dup (const struct spwd *spent); @@ -417,7 +417,7 @@ extern int run_command(const char *cmd, const char *argv[], /*@null@*/const char *envp[], int *restrict status); /* strtoday.c */ -extern long strtoday (const char *); +extern long strtoday(const char *); /* suauth.c */ extern int check_su_auth (const char *actual_id, @@ -425,7 +425,7 @@ extern int check_su_auth (const char *actual_id, bool su_to_root); /* sulog.c */ -extern void sulog (const char *tty, +extern void sulog(const char *tty, bool success, const char *oldname, const char *name); @@ -434,7 +434,7 @@ extern void sulog (const char *tty, extern void subsystem (const struct passwd *); /* ttytype.c */ -extern void ttytype (const char *); +extern void ttytype(const char *); /* tz.c */ #ifndef USE_PAM @@ -445,7 +445,7 @@ extern /*@observer@*/const char *tz (const char *); extern int set_filesize_limit (int blocks); /* user_busy.c */ -extern int user_busy (const char *name, uid_t uid); +extern int user_busy(const char *name, uid_t uid); /* * Session management: utmp.c or logind.c @@ -461,7 +461,7 @@ extern int user_busy (const char *name, uid_t uid); * @return 0 or a positive integer if the host was obtained properly, * another value on error. */ -extern int get_session_host (char **out, pid_t main_pid); +extern int get_session_host(char **out, pid_t main_pid); #ifndef ENABLE_LOGIND /** * @brief Update or create an utmp entry in utmp, wtmp, utmpw, or wtmpx @@ -475,7 +475,7 @@ extern int get_session_host (char **out, pid_t main_pid); * @return 0 if utmp was updated properly, * 1 on error. */ -extern int update_utmp (const char *user, +extern int update_utmp(const char *user, const char *tty, const char *host, pid_t main_pid); diff --git a/lib/pwauth.c b/lib/pwauth.c index 0f0d2ff77c..06f5724ddf 100644 --- a/lib/pwauth.c +++ b/lib/pwauth.c @@ -34,9 +34,9 @@ #ifdef __linux__ /* standard password prompt by default */ -static const char *PROMPT = gettext_noop ("Password: "); +static const char *PROMPT = gettext_noop("Password: "); #else -static const char *PROMPT = gettext_noop ("%s's Password: "); +static const char *PROMPT = gettext_noop("%s's Password: "); #endif @@ -92,7 +92,7 @@ pw_auth(const char *cipher, const char *user) # define skeychallenge(s,u,c) skeychallenge(s,u,c,sizeof(c)) # endif - if (skeychallenge (&skey, user, challenge_info) == 0) { + if (skeychallenge(&skey, user, challenge_info) == 0) { use_skey = true; } #endif @@ -101,13 +101,13 @@ pw_auth(const char *cipher, const char *user) * Prompt for the password as required. */ - cp = getdef_str ("LOGIN_STRING"); + cp = getdef_str("LOGIN_STRING"); if (NULL == cp) { cp = _(PROMPT); } #ifdef SKEY if (use_skey) { - printf ("[%s]\n", challenge_info); + printf("[%s]\n", challenge_info); } #endif @@ -122,9 +122,9 @@ pw_auth(const char *cipher, const char *user) * the results there as well. */ - encrypted = pw_encrypt (input, cipher); + encrypted = pw_encrypt(input, cipher); if (NULL != encrypted) { - retval = strcmp (encrypted, cipher); + retval = strcmp(encrypted, cipher); } else { retval = -1; } @@ -146,7 +146,7 @@ pw_auth(const char *cipher, const char *user) if ((0 != retval) && use_skey) { int passcheck = -1; - if (skeyverify (&skey, input) == 0) { + if (skeyverify(&skey, input) == 0) { passcheck = skey.n; } if (passcheck > 0) { diff --git a/lib/pwd2spwd.c b/lib/pwd2spwd.c index ea1bf064b2..890dbb1daf 100644 --- a/lib/pwd2spwd.c +++ b/lib/pwd2spwd.c @@ -22,7 +22,7 @@ * information in the pointed-to (struct passwd). */ -struct spwd *pwd_to_spwd (const struct passwd *pw) +struct spwd *pwd_to_spwd(const struct passwd *pw) { static struct spwd sp; diff --git a/lib/pwd_init.c b/lib/pwd_init.c index bd2cfd3ff5..53513ec03b 100644 --- a/lib/pwd_init.c +++ b/lib/pwd_init.c @@ -24,33 +24,33 @@ * values. Call this before modifying password files, so that * it is less likely to fail in the middle of operation. */ -void pwd_init (void) +void pwd_init(void) { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; - setrlimit (RLIMIT_CORE, &rlim); + setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY; - setrlimit (RLIMIT_AS, &rlim); + setrlimit(RLIMIT_AS, &rlim); - setrlimit (RLIMIT_CPU, &rlim); - setrlimit (RLIMIT_DATA, &rlim); - setrlimit (RLIMIT_FSIZE, &rlim); - setrlimit (RLIMIT_NOFILE, &rlim); + setrlimit(RLIMIT_CPU, &rlim); + setrlimit(RLIMIT_DATA, &rlim); + setrlimit(RLIMIT_FSIZE, &rlim); + setrlimit(RLIMIT_NOFILE, &rlim); #ifdef RLIMIT_RSS - setrlimit (RLIMIT_RSS, &rlim); + setrlimit(RLIMIT_RSS, &rlim); #endif - setrlimit (RLIMIT_STACK, &rlim); - - signal (SIGALRM, SIG_IGN); - signal (SIGHUP, SIG_IGN); - signal (SIGINT, SIG_IGN); - signal (SIGPIPE, SIG_IGN); - signal (SIGQUIT, SIG_IGN); - signal (SIGTERM, SIG_IGN); - signal (SIGTSTP, SIG_IGN); - signal (SIGTTOU, SIG_IGN); - - umask (077); + setrlimit(RLIMIT_STACK, &rlim); + + signal(SIGALRM, SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGINT, SIG_IGN); + signal(SIGPIPE, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + signal(SIGTERM, SIG_IGN); + signal(SIGTSTP, SIG_IGN); + signal(SIGTTOU, SIG_IGN); + + umask(077); } diff --git a/lib/pwio.c b/lib/pwio.c index 57ed4a4527..fecc559f39 100644 --- a/lib/pwio.c +++ b/lib/pwio.c @@ -33,40 +33,40 @@ passwd_free(/*@only@*/void *ent) { struct passwd *pw = ent; - pw_free (pw); + pw_free(pw); } -static const char *passwd_getname (const void *ent) +static const char *passwd_getname(const void *ent) { const struct passwd *pw = ent; return pw->pw_name; } -static void *passwd_parse (const char *line) +static void *passwd_parse(const char *line) { - return sgetpwent (line); + return sgetpwent(line); } -static int passwd_put (const void *ent, FILE * file) +static int passwd_put(const void *ent, FILE * file) { const struct passwd *pw = ent; if ( (NULL == pw) - || (valid_field (pw->pw_name, ":\n") == -1) - || (valid_field (pw->pw_passwd, ":\n") == -1) + || (valid_field(pw->pw_name, ":\n") == -1) + || (valid_field(pw->pw_passwd, ":\n") == -1) || (pw->pw_uid == (uid_t)-1) || (pw->pw_gid == (gid_t)-1) - || (valid_field (pw->pw_gecos, ":\n") == -1) - || (valid_field (pw->pw_dir, ":\n") == -1) - || (valid_field (pw->pw_shell, ":\n") == -1) - || (strlen (pw->pw_name) + strlen (pw->pw_passwd) + - strlen (pw->pw_gecos) + strlen (pw->pw_dir) + - strlen (pw->pw_shell) + 100 > PASSWD_ENTRY_MAX_LENGTH)) { + || (valid_field(pw->pw_gecos, ":\n") == -1) + || (valid_field(pw->pw_dir, ":\n") == -1) + || (valid_field(pw->pw_shell, ":\n") == -1) + || (strlen(pw->pw_name) + strlen(pw->pw_passwd) + + strlen(pw->pw_gecos) + strlen(pw->pw_dir) + + strlen(pw->pw_shell) + 100 > PASSWD_ENTRY_MAX_LENGTH)) { return -1; } - return (putpwent (pw, file) == -1) ? -1 : 0; + return (putpwent(pw, file) == -1) ? -1 : 0; } static struct commonio_ops passwd_ops = { @@ -109,14 +109,14 @@ int pw_setdbname (const char *filename) return passwd_db.filename; } -int pw_lock (void) +int pw_lock(void) { - return commonio_lock (&passwd_db); + return commonio_lock(&passwd_db); } -int pw_open (int mode) +int pw_open(int mode) { - return commonio_open (&passwd_db, mode); + return commonio_open(&passwd_db, mode); } /*@observer@*/ /*@null@*/const struct passwd *pw_locate (const char *name) @@ -128,27 +128,27 @@ int pw_open (int mode) { const struct passwd *pwd; - pw_rewind (); - while ( ((pwd = pw_next ()) != NULL) + pw_rewind(); + while ( ((pwd = pw_next()) != NULL) && (pwd->pw_uid != uid)) { } return pwd; } -int pw_update (const struct passwd *pw) +int pw_update(const struct passwd *pw) { - return commonio_update (&passwd_db, pw); + return commonio_update(&passwd_db, pw); } -int pw_remove (const char *name) +int pw_remove(const char *name) { - return commonio_remove (&passwd_db, name); + return commonio_remove(&passwd_db, name); } -int pw_rewind (void) +int pw_rewind(void) { - return commonio_rewind (&passwd_db); + return commonio_rewind(&passwd_db); } /*@observer@*/ /*@null@*/const struct passwd *pw_next (void) @@ -171,17 +171,17 @@ int pw_unlock (bool process_selinux) return passwd_db.head; } -void __pw_del_entry (const struct commonio_entry *ent) +void __pw_del_entry(const struct commonio_entry *ent) { - commonio_del_entry (&passwd_db, ent); + commonio_del_entry(&passwd_db, ent); } -struct commonio_db *__pw_get_db (void) +struct commonio_db *__pw_get_db(void) { return &passwd_db; } -static int pw_cmp (const void *p1, const void *p2) +static int pw_cmp(const void *p1, const void *p2) { const struct commonio_entry *const *ce1; const struct commonio_entry *const *ce2; diff --git a/lib/readpassphrase.c b/lib/readpassphrase.c index 7deab5a619..fbe145e010 100644 --- a/lib/readpassphrase.c +++ b/lib/readpassphrase.c @@ -62,7 +62,7 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) /* I suppose we could alloc on demand in this case (XXX). */ if (bufsiz == 0) { errno = EINVAL; - return(NULL); + return (NULL); } restart: @@ -79,7 +79,7 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) (input = output = open(_PATH_TTY, O_RDWR)) == -1) { if (flags & RPP_REQUIRE_TTY) { errno = ENOTTY; - return(NULL); + return (NULL); } input = STDIN_FILENO; output = STDERR_FILENO; @@ -100,9 +100,9 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) #endif (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term); } else { - memset(&term, 0, sizeof(term)); + memset(&term, 0, sizeof (term)); term.c_lflag |= ECHO; - memset(&oterm, 0, sizeof(oterm)); + memset(&oterm, 0, sizeof (oterm)); oterm.c_lflag |= ECHO; } @@ -147,7 +147,7 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) (void)write(output, "\n", 1); /* Restore old terminal settings and signals. */ - if (memcmp(&term, &oterm, sizeof(term)) != 0) { + if (memcmp(&term, &oterm, sizeof (term)) != 0) { const int sigttou = signo[SIGTTOU]; /* Ignore SIGTTOU generated when we are not the fg pgrp. */ @@ -188,7 +188,7 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) if (save_errno) errno = save_errno; - return(nr == -1 ? NULL : buf); + return (nr == -1 ? NULL : buf); } static void handler(int s) diff --git a/lib/remove_tree.c b/lib/remove_tree.c index 71173c0665..7d5702ec2a 100644 --- a/lib/remove_tree.c +++ b/lib/remove_tree.c @@ -25,27 +25,27 @@ #include "string/strcmp/streq.h" -static int remove_tree_at (int at_fd, const char *path, bool remove_root) +static int remove_tree_at(int at_fd, const char *path, bool remove_root) { DIR *dir; const struct dirent *ent; int dir_fd, rc = 0; - dir_fd = openat (at_fd, path, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); + dir_fd = openat(at_fd, path, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); if (dir_fd < 0) { return -1; } - dir = fdopendir (dir_fd); + dir = fdopendir(dir_fd); if (!dir) { - (void) close (dir_fd); + (void) close(dir_fd); return -1; } /* * Open the source directory and delete each entry. */ - while ((ent = readdir (dir))) { + while ((ent = readdir(dir))) { struct stat ent_sb; /* @@ -56,16 +56,16 @@ static int remove_tree_at (int at_fd, const char *path, bool remove_root) continue; } - rc = fstatat (dirfd(dir), ent->d_name, &ent_sb, AT_SYMLINK_NOFOLLOW); + rc = fstatat(dirfd(dir), ent->d_name, &ent_sb, AT_SYMLINK_NOFOLLOW); if (rc < 0) { break; } - if (S_ISDIR (ent_sb.st_mode)) { + if (S_ISDIR(ent_sb.st_mode)) { /* * Recursively delete this directory. */ - if (remove_tree_at (dirfd(dir), ent->d_name, true) != 0) { + if (remove_tree_at(dirfd(dir), ent->d_name, true) != 0) { rc = -1; break; } @@ -73,17 +73,17 @@ static int remove_tree_at (int at_fd, const char *path, bool remove_root) /* * Delete the file. */ - if (unlinkat (dirfd(dir), ent->d_name, 0) != 0) { + if (unlinkat(dirfd(dir), ent->d_name, 0) != 0) { rc = -1; break; } } } - (void) closedir (dir); + (void) closedir(dir); if (remove_root && (0 == rc)) { - if (unlinkat (at_fd, path, AT_REMOVEDIR) != 0) { + if (unlinkat(at_fd, path, AT_REMOVEDIR) != 0) { rc = -1; } } @@ -98,7 +98,7 @@ static int remove_tree_at (int at_fd, const char *path, bool remove_root) * and directories. * At the end, it deletes the root directory itself. */ -int remove_tree (const char *root, bool remove_root) +int remove_tree(const char *root, bool remove_root) { - return remove_tree_at (AT_FDCWD, root, remove_root); + return remove_tree_at(AT_FDCWD, root, remove_root); } diff --git a/lib/root_flag.c b/lib/root_flag.c index 38ef0b4cdc..25f9e35e93 100644 --- a/lib/root_flag.c +++ b/lib/root_flag.c @@ -32,7 +32,7 @@ static void change_root (const char* newroot); * * The audit, syslog, or locale files shall be open before */ -extern void process_root_flag (const char* short_opt, int argc, char **argv) +extern void process_root_flag(const char* short_opt, int argc, char **argv) { const char *newroot = NULL; @@ -46,19 +46,19 @@ extern void process_root_flag (const char* short_opt, int argc, char **argv) || streq(argv[i], short_opt)) { if (NULL != newroot) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: multiple --root options\n"), log_get_progname()); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } if (val) { newroot = val; } else if (i + 1 == argc) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: option '%s' requires an argument\n"), log_get_progname(), argv[i]); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } else { newroot = argv[++ i]; } @@ -66,11 +66,11 @@ extern void process_root_flag (const char* short_opt, int argc, char **argv) } if (NULL != newroot) { - change_root (newroot); + change_root(newroot); } } -static void change_root (const char* newroot) +static void change_root(const char* newroot) { /* Drop privileges */ if ( (setregid (getgid (), getgid ()) != 0) diff --git a/lib/run_part.h b/lib/run_part.h index 889d281c49..d3ea71383d 100644 --- a/lib/run_part.h +++ b/lib/run_part.h @@ -1,6 +1,6 @@ #ifndef _RUN_PART_H #define _RUN_PART_H -int run_parts (const char *directory, const char *name, const char *action); +int run_parts(const char *directory, const char *name, const char *action); #endif /* _RUN_PART_H */ diff --git a/lib/salt.c b/lib/salt.c index e662e03c17..0ced58b79e 100644 --- a/lib/salt.c +++ b/lib/salt.c @@ -109,8 +109,8 @@ static /*@observer@*/unsigned long SHA_get_salt_rounds (/*@null@*/const int *pre unsigned long rounds; if (NULL == prefered_rounds) { - long min_rounds = getdef_long ("SHA_CRYPT_MIN_ROUNDS", -1); - long max_rounds = getdef_long ("SHA_CRYPT_MAX_ROUNDS", -1); + long min_rounds = getdef_long("SHA_CRYPT_MIN_ROUNDS", -1); + long max_rounds = getdef_long("SHA_CRYPT_MAX_ROUNDS", -1); if ((-1 == min_rounds) && (-1 == max_rounds)) { rounds = SHA_ROUNDS_DEFAULT; @@ -128,7 +128,7 @@ static /*@observer@*/unsigned long SHA_get_salt_rounds (/*@null@*/const int *pre max_rounds = min_rounds; } - rounds = csrand_interval (min_rounds, max_rounds); + rounds = csrand_interval(min_rounds, max_rounds); } } else if (0 == *prefered_rounds) { rounds = SHA_ROUNDS_DEFAULT; @@ -170,9 +170,9 @@ static /*@observer@*/void SHA_salt_rounds_to_buf (char *buf, unsigned long round * 00000000011111111 * 12345678901234567 */ - assert (GENSALT_SETTING_SIZE > buf_begin + 17); + assert(GENSALT_SETTING_SIZE > buf_begin + 17); - (void) snprintf (buf + buf_begin, 18, "rounds=%lu$", rounds); + (void) snprintf(buf + buf_begin, 18, "rounds=%lu$", rounds); } #ifdef USE_BCRYPT @@ -182,8 +182,8 @@ static /*@observer@*/unsigned long BCRYPT_get_salt_rounds (/*@null@*/const int * unsigned long rounds; if (NULL == prefered_rounds) { - long min_rounds = getdef_long ("BCRYPT_MIN_ROUNDS", -1); - long max_rounds = getdef_long ("BCRYPT_MAX_ROUNDS", -1); + long min_rounds = getdef_long("BCRYPT_MIN_ROUNDS", -1); + long max_rounds = getdef_long("BCRYPT_MAX_ROUNDS", -1); if ((-1 == min_rounds) && (-1 == max_rounds)) { rounds = B_ROUNDS_DEFAULT; @@ -200,7 +200,7 @@ static /*@observer@*/unsigned long BCRYPT_get_salt_rounds (/*@null@*/const int * max_rounds = min_rounds; } - rounds = csrand_interval (min_rounds, max_rounds); + rounds = csrand_interval(min_rounds, max_rounds); } } else if (0 == *prefered_rounds) { rounds = B_ROUNDS_DEFAULT; @@ -248,9 +248,9 @@ static /*@observer@*/void BCRYPT_salt_rounds_to_buf (char *buf, unsigned long ro * 000 * 123 */ - assert (GENSALT_SETTING_SIZE > buf_begin + 3); + assert(GENSALT_SETTING_SIZE > buf_begin + 3); - (void) snprintf (buf + buf_begin, 4, "%2.2lu$", rounds); + (void) snprintf(buf + buf_begin, 4, "%2.2lu$", rounds); } #endif /* USE_BCRYPT */ @@ -261,7 +261,7 @@ static /*@observer@*/unsigned long YESCRYPT_get_salt_cost (/*@null@*/const int * unsigned long cost; if (NULL == prefered_cost) { - cost = getdef_num ("YESCRYPT_COST_FACTOR", Y_COST_DEFAULT); + cost = getdef_num("YESCRYPT_COST_FACTOR", Y_COST_DEFAULT); } else if (0 == *prefered_cost) { cost = Y_COST_DEFAULT; } else { @@ -297,7 +297,7 @@ static /*@observer@*/void YESCRYPT_salt_cost_to_buf (char *buf, unsigned long co * 0000 * 1234 */ - assert (GENSALT_SETTING_SIZE > buf_begin + 4); + assert(GENSALT_SETTING_SIZE > buf_begin + 4); p = &buf[buf_begin]; p = stpcpy(p, "j"); @@ -412,14 +412,14 @@ static /*@observer@*/const char *gensalt (size_t salt_size) /* Should not happen, but... */ if (NULL == retval) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("Unable to generate a salt from setting " "\"%s\", check your settings in " "ENCRYPT_METHOD and the corresponding " "configuration for your selected hash " "method.\n"), result); - exit (1); + exit(1); } return retval; @@ -428,8 +428,8 @@ static /*@observer@*/const char *gensalt (size_t salt_size) assert (GENSALT_SETTING_SIZE > strlen (result) + salt_len); /* Concatenate a pseudo random salt. */ - strncat (result, gensalt (salt_len), - GENSALT_SETTING_SIZE - strlen (result) - 1); + strncat(result, gensalt(salt_len), + GENSALT_SETTING_SIZE - strlen(result) - 1); return result; #endif /* USE_XCRYPT_GENSALT */ diff --git a/lib/search/cmp/cmp.h b/lib/search/cmp/cmp.h index d9ed1ab096..fad3068b4c 100644 --- a/lib/search/cmp/cmp.h +++ b/lib/search/cmp/cmp.h @@ -11,7 +11,7 @@ #define CMP(T) \ ( \ - _Generic((T){0}, \ + _Generic ((T){0}, \ int: cmp_int, \ long: cmp_long, \ unsigned int: cmp_uint, \ diff --git a/lib/search/l/lfind.c b/lib/search/l/lfind.c index 2d55709fa8..195b1a6f79 100644 --- a/lib/search/l/lfind.c +++ b/lib/search/l/lfind.c @@ -10,4 +10,4 @@ extern inline void *lfind_(const void *k, const void *a, size_t n, size_t ksize, - typeof(int (const void *k, const void *elt)) *cmp); + typeof (int(const void *k, const void *elt)) *cmp); diff --git a/lib/search/l/lfind.h b/lib/search/l/lfind.h index 7bbd16e0e3..e3325782c5 100644 --- a/lib/search/l/lfind.h +++ b/lib/search/l/lfind.h @@ -19,21 +19,21 @@ #define lfind_T(T, ...) lfind_T_(typeas(T), __VA_ARGS__) #define lfind_T_(T, k, a, n, cmp) \ ({ \ - _Generic(k, T *: (void)0, const T *: (void)0); \ - _Generic(a, T *: (void)0, const T *: (void)0); \ - (T *){lfind_(k, a, n, sizeof(T), cmp)}; \ + _Generic (k, T *: (void)0, const T *: (void)0); \ + _Generic (a, T *: (void)0, const T *: (void)0); \ + (T *){lfind_(k, a, n, sizeof (T), cmp)}; \ }) #define LFIND(T, ...) lfind_T(T, __VA_ARGS__, CMP(T)) inline void *lfind_(const void *k, const void *a, size_t n, size_t ksize, - typeof(int (const void *k, const void *elt)) *cmp); + typeof (int(const void *k, const void *elt)) *cmp); inline void * lfind_(const void *k, const void *a, size_t n, size_t ksize, - typeof(int (const void *k, const void *elt)) *cmp) + typeof (int(const void *k, const void *elt)) *cmp) { // lfind(3) wants a pointer to n for historic reasons. return lfind(k, a, &n, ksize, cmp); diff --git a/lib/search/l/lsearch.h b/lib/search/l/lsearch.h index 04337c3152..31c4dccc4b 100644 --- a/lib/search/l/lsearch.h +++ b/lib/search/l/lsearch.h @@ -18,9 +18,9 @@ #define lsearch_T(T, ...) lsearch_T_(typeas(T), __VA_ARGS__) #define lsearch_T_(T, k, a, n, cmp) do \ { \ - _Generic(k, T *: (void)0, const T *: (void)0); \ - _Generic(a, T *: (void)0); \ - lsearch(k, a, n, sizeof(T), cmp); \ + _Generic (k, T *: (void)0, const T *: (void)0); \ + _Generic (a, T *: (void)0); \ + lsearch(k, a, n, sizeof (T), cmp); \ } while (0) #define LSEARCH(T, ...) lsearch_T(T, __VA_ARGS__, CMP(T)) diff --git a/lib/search/sort/qsort.h b/lib/search/sort/qsort.h index de1ad71d19..f3ee3cdd71 100644 --- a/lib/search/sort/qsort.h +++ b/lib/search/sort/qsort.h @@ -18,8 +18,8 @@ #define qsort_T(T, ...) qsort_T_(typeas(T), __VA_ARGS__) #define qsort_T_(T, a, n, cmp) do \ { \ - _Generic(a, T *: (void)0); \ - qsort(a, n, sizeof(T), cmp); \ + _Generic (a, T *: (void)0); \ + qsort(a, n, sizeof (T), cmp); \ } while (0) #define QSORT(T, ...) qsort_T(T, __VA_ARGS__, CMP(T)) diff --git a/lib/selinux.c b/lib/selinux.c index 4b6bf8521b..a496c4c0f5 100644 --- a/lib/selinux.c +++ b/lib/selinux.c @@ -47,10 +47,10 @@ void reset_selinux_handle (void) * Callers may have to Reset SELinux to create files with default * contexts with reset_selinux_file_context */ -int set_selinux_file_context (const char *dst_name, mode_t mode) +int set_selinux_file_context(const char *dst_name, mode_t mode) { if (!selinux_checked) { - selinux_enabled = is_selinux_enabled () > 0; + selinux_enabled = is_selinux_enabled() > 0; selinux_checked = true; } @@ -63,7 +63,7 @@ int set_selinux_file_context (const char *dst_name, mode_t mode) if (selabel_hnd == NULL) { selabel_hnd = selabel_open(SELABEL_CTX_FILE, NULL, 0); if (selabel_hnd == NULL) { - return security_getenforce () != 0; + return security_getenforce() != 0; } (void) atexit(cleanup); } @@ -79,10 +79,10 @@ int set_selinux_file_context (const char *dst_name, mode_t mode) } /* Set the security context for the next created file */ - r = setfscreatecon_raw (fcontext_raw); - freecon (fcontext_raw); + r = setfscreatecon_raw(fcontext_raw); + freecon(fcontext_raw); if (r < 0) { - return security_getenforce () != 0; + return security_getenforce() != 0; } } return 0; @@ -95,15 +95,15 @@ int set_selinux_file_context (const char *dst_name, mode_t mode) * reset_selinux_file_context () should be called after the context * was changed with set_selinux_file_context () */ -int reset_selinux_file_context (void) +int reset_selinux_file_context(void) { if (!selinux_checked) { - selinux_enabled = is_selinux_enabled () > 0; + selinux_enabled = is_selinux_enabled() > 0; selinux_checked = true; } if (selinux_enabled) { - if (setfscreatecon_raw (NULL) != 0) { - return security_getenforce () != 0; + if (setfscreatecon_raw(NULL) != 0) { + return security_getenforce() != 0; } } return 0; @@ -113,22 +113,22 @@ int reset_selinux_file_context (void) * Log callback for libselinux internal error reporting. */ format_attr(printf, 2, 3) -static int selinux_log_cb (int type, const char *fmt, ...) { +static int selinux_log_cb(int type, const char *fmt, ...) { va_list ap; char *buf; #ifdef WITH_AUDIT static int selinux_audit_fd = -2; #endif - va_start (ap, fmt); + va_start(ap, fmt); buf = vaprintf(fmt, ap); - va_end (ap); + va_end(ap); if (buf == NULL) return 0; #ifdef WITH_AUDIT if (-2 == selinux_audit_fd) { - selinux_audit_fd = audit_open (); + selinux_audit_fd = audit_open(); if (-1 == selinux_audit_fd) { /* You get these only when the kernel doesn't have @@ -137,7 +137,7 @@ static int selinux_log_cb (int type, const char *fmt, ...) { && (errno != EPROTONOSUPPORT) && (errno != EAFNOSUPPORT)) { - (void) fputs (_("Cannot open audit interface.\n"), + (void) fputs(_("Cannot open audit interface.\n"), log_get_logfd()); SYSLOG(LOG_WARN, "Cannot open audit interface."); } @@ -146,13 +146,13 @@ static int selinux_log_cb (int type, const char *fmt, ...) { if (-1 != selinux_audit_fd) { if (SELINUX_AVC == type) { - if (audit_log_user_avc_message (selinux_audit_fd, + if (audit_log_user_avc_message(selinux_audit_fd, AUDIT_USER_AVC, buf, NULL, NULL, NULL, 0) > 0) { goto skip_syslog; } } else if (SELINUX_ERROR == type) { - if (audit_log_user_avc_message (selinux_audit_fd, + if (audit_log_user_avc_message(selinux_audit_fd, AUDIT_USER_SELINUX_ERR, buf, NULL, NULL, NULL, 0) > 0) { goto skip_syslog; @@ -164,7 +164,7 @@ static int selinux_log_cb (int type, const char *fmt, ...) { SYSLOG(LOG_WARN, "libselinux: %s", buf); skip_syslog: - free (buf); + free(buf); return 0; } @@ -179,29 +179,29 @@ static int selinux_log_cb (int type, const char *fmt, ...) { * or something failed but running in * permissive mode */ -int check_selinux_permit (const char *perm_name) +int check_selinux_permit(const char *perm_name) { char *user_context_raw; int r; - if (0 == is_selinux_enabled ()) { + if (0 == is_selinux_enabled()) { return 0; } - selinux_set_callback (SELINUX_CB_LOG, (union selinux_callback) { .func_log = selinux_log_cb }); + selinux_set_callback(SELINUX_CB_LOG, (union selinux_callback) { .func_log = selinux_log_cb }); - if (getprevcon_raw (&user_context_raw) != 0) { - fprintf (log_get_logfd(), + if (getprevcon_raw(&user_context_raw) != 0) { + fprintf(log_get_logfd(), _("%s: can not get previous SELinux process context: %s\n"), log_get_progname(), strerrno()); SYSLOG(LOG_WARN, "can not get previous SELinux process context: %s", strerrno()); - return (security_getenforce () != 0); + return (security_getenforce() != 0); } - r = selinux_check_access (user_context_raw, user_context_raw, "passwd", perm_name, NULL); - freecon (user_context_raw); + r = selinux_check_access(user_context_raw, user_context_raw, "passwd", perm_name, NULL); + freecon(user_context_raw); return r; } diff --git a/lib/semanage.c b/lib/semanage.c index 1653e7710c..1363f0be2b 100644 --- a/lib/semanage.c +++ b/lib/semanage.c @@ -35,16 +35,16 @@ static void semanage_error_callback(MAYBE_UNUSED void *_1, char * message = NULL; va_list ap; - va_start (ap, fmt); + va_start(ap, fmt); message = vaprintf(fmt, ap); - va_end (ap); + va_end(ap); if (message == NULL) return; - switch (semanage_msg_get_level (handle)) { + switch (semanage_msg_get_level(handle)) { case SEMANAGE_MSG_ERR: case SEMANAGE_MSG_WARN: - fprintf (log_get_logfd(), _("[libsemanage]: %s\n"), message); + fprintf(log_get_logfd(), _("[libsemanage]: %s\n"), message); break; case SEMANAGE_MSG_INFO: /* nop */ @@ -230,48 +230,48 @@ int set_seuser (const char *login_name, const char *seuser_name, const char *ser return 0; } - handle = semanage_init (); + handle = semanage_init(); if (NULL == handle) { - fprintf (log_get_logfd(), _("Cannot init SELinux management\n")); + fprintf(log_get_logfd(), _("Cannot init SELinux management\n")); ret = 1; goto done; } - ret = semanage_seuser_key_create (handle, login_name, &key); + ret = semanage_seuser_key_create(handle, login_name, &key); if (ret != 0) { - fprintf (log_get_logfd(), _("Cannot create SELinux user key\n")); + fprintf(log_get_logfd(), _("Cannot create SELinux user key\n")); ret = 1; goto done; } - ret = semanage_seuser_exists (handle, key, &seuser_exists); + ret = semanage_seuser_exists(handle, key, &seuser_exists); if (ret < 0) { - fprintf (log_get_logfd(), _("Cannot verify the SELinux user\n")); + fprintf(log_get_logfd(), _("Cannot verify the SELinux user\n")); ret = 1; goto done; } if (0 != seuser_exists) { - ret = semanage_user_mod (handle, key, login_name, seuser_name, serange); + ret = semanage_user_mod(handle, key, login_name, seuser_name, serange); if (ret != 0) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("Cannot modify SELinux user mapping\n")); ret = 1; goto done; } } else { - ret = semanage_user_add (handle, key, login_name, seuser_name, serange); + ret = semanage_user_add(handle, key, login_name, seuser_name, serange); if (ret != 0) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("Cannot add SELinux user mapping\n")); ret = 1; goto done; } } - ret = semanage_commit (handle); + ret = semanage_commit(handle); if (ret < 0) { - fprintf (log_get_logfd(), _("Cannot commit SELinux transaction\n")); + fprintf(log_get_logfd(), _("Cannot commit SELinux transaction\n")); ret = 1; goto done; } @@ -280,44 +280,44 @@ int set_seuser (const char *login_name, const char *seuser_name, const char *ser reset_selinux_handle(); done: - semanage_seuser_key_free (key); + semanage_seuser_key_free(key); if (handle) - semanage_disconnect (handle); - semanage_handle_destroy (handle); + semanage_disconnect(handle); + semanage_handle_destroy(handle); return ret; } -int del_seuser (const char *login_name) +int del_seuser(const char *login_name) { semanage_handle_t *handle = NULL; semanage_seuser_key_t *key = NULL; int ret; int exists = 0; - handle = semanage_init (); + handle = semanage_init(); if (NULL == handle) { - fprintf (log_get_logfd(), _("Cannot init SELinux management\n")); + fprintf(log_get_logfd(), _("Cannot init SELinux management\n")); ret = 1; goto done; } - ret = semanage_seuser_key_create (handle, login_name, &key); + ret = semanage_seuser_key_create(handle, login_name, &key); if (ret != 0) { - fprintf (log_get_logfd(), _("Cannot create SELinux user key\n")); + fprintf(log_get_logfd(), _("Cannot create SELinux user key\n")); ret = 1; goto done; } - ret = semanage_seuser_exists (handle, key, &exists); + ret = semanage_seuser_exists(handle, key, &exists); if (ret < 0) { - fprintf (log_get_logfd(), _("Cannot verify the SELinux user\n")); + fprintf(log_get_logfd(), _("Cannot verify the SELinux user\n")); ret = 1; goto done; } if (0 == exists) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("Login mapping for %s is not defined, OK if default mapping was used\n"), login_name); ret = 0; /* probably default mapping */ @@ -339,28 +339,28 @@ int del_seuser (const char *login_name) goto done; } - ret = semanage_seuser_del_local (handle, key); + ret = semanage_seuser_del_local(handle, key); if (ret != 0) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("Could not delete login mapping for %s"), login_name); ret = 1; goto done; } - ret = semanage_commit (handle); + ret = semanage_commit(handle); if (ret < 0) { - fprintf (log_get_logfd(), _("Cannot commit SELinux transaction\n")); + fprintf(log_get_logfd(), _("Cannot commit SELinux transaction\n")); ret = 1; goto done; } ret = 0; done: - semanage_seuser_key_free (key); + semanage_seuser_key_free(key); if (handle) - semanage_disconnect (handle); - semanage_handle_destroy (handle); + semanage_disconnect(handle); + semanage_handle_destroy(handle); return ret; } #else /* !WITH_SELINUX */ diff --git a/lib/setugid.c b/lib/setugid.c index d8a3588bdf..cfc3ab6cbb 100644 --- a/lib/setugid.c +++ b/lib/setugid.c @@ -33,18 +33,18 @@ * * Returns 0 on success, or -1 on failure. */ -int setup_groups (const struct passwd *info) +int setup_groups(const struct passwd *info) { /* * Set the real group ID to the primary group ID in the password * file. */ - if (setgid (info->pw_gid) == -1) { + if (setgid(info->pw_gid) == -1) { int err = errno; - perror ("setgid"); + perror("setgid"); SYSLOG(LOG_ERR, "bad group ID `%d' for user `%s': %s\n", info->pw_gid, info->pw_name, strerror(err)); - closelog (); + closelog(); return -1; } @@ -52,12 +52,12 @@ int setup_groups (const struct passwd *info) * For systems which support multiple concurrent groups, go get * the group set from the /etc/group file. */ - if (initgroups (info->pw_name, info->pw_gid) == -1) { + if (initgroups(info->pw_name, info->pw_gid) == -1) { int err = errno; - perror ("initgroups"); + perror("initgroups"); SYSLOG(LOG_ERR, "initgroups failed for user `%s': %s\n", info->pw_name, strerror(err)); - closelog (); + closelog(); return -1; } @@ -69,17 +69,17 @@ int setup_groups (const struct passwd *info) * * Returns 0 on success, or -1 on failure. */ -int change_uid (const struct passwd *info) +int change_uid(const struct passwd *info) { /* * Set the real UID to the UID value in the password file. */ - if (setuid (info->pw_uid) != 0) { + if (setuid(info->pw_uid) != 0) { int err = errno; - perror ("setuid"); + perror("setuid"); SYSLOG(LOG_ERR, "bad user ID `%d' for user `%s': %s\n", (int) info->pw_uid, info->pw_name, strerror(err)); - closelog (); + closelog(); return -1; } return 0; @@ -97,26 +97,26 @@ int change_uid (const struct passwd *info) */ #if !defined(USE_PAM) -int setup_uid_gid (const struct passwd *info, bool is_console) +int setup_uid_gid(const struct passwd *info, bool is_console) #else -int setup_uid_gid (const struct passwd *info) +int setup_uid_gid(const struct passwd *info) #endif { - if (setup_groups (info) < 0) { + if (setup_groups(info) < 0) { return -1; } #if !defined(USE_PAM) if (is_console) { - const char *cp = getdef_str ("CONSOLE_GROUPS"); + const char *cp = getdef_str("CONSOLE_GROUPS"); - if ((NULL != cp) && (add_groups (cp) != 0)) { - perror ("Warning: add_groups"); + if ((NULL != cp) && (add_groups(cp) != 0)) { + perror("Warning: add_groups"); } } #endif // !USE_PAM - if (change_uid (info) < 0) { + if (change_uid(info) < 0) { return -1; } diff --git a/lib/setupenv.c b/lib/setupenv.c index efa0f2d820..09352d1299 100644 --- a/lib/setupenv.c +++ b/lib/setupenv.c @@ -44,13 +44,13 @@ addenv_path(const char *varname, const char *dirname, const char *filename) free(buf); } -static void read_env_file (const char *filename) +static void read_env_file(const char *filename) { FILE *fp; char buf[1024]; char *cp, *name, *val; - fp = fopen (filename, "r"); + fp = fopen(filename, "r"); if (NULL == fp) { return; } @@ -78,9 +78,9 @@ static void read_env_file (const char *filename) * XXX - should handle quotes, backslash escapes, etc. * like the shell does. */ - addenv (name, val); + addenv(name, val); } - (void) fclose (fp); + (void) fclose(fp); } #endif /* USE_PAM */ @@ -91,7 +91,7 @@ static void read_env_file (const char *filename) * variables. */ -void setup_env (struct passwd *info) +void setup_env(struct passwd *info) { #ifndef USE_PAM const char *envf; @@ -109,58 +109,58 @@ void setup_env (struct passwd *info) * this a configurable option. --marekm */ - if (chdir (info->pw_dir) == -1) { - if (!getdef_bool ("DEFAULT_HOME") || chdir ("/") == -1) { - fprintf (log_get_logfd(), _("Unable to cd to '%s'\n"), + if (chdir(info->pw_dir) == -1) { + if (!getdef_bool("DEFAULT_HOME") || chdir("/") == -1) { + fprintf(log_get_logfd(), _("Unable to cd to '%s'\n"), info->pw_dir); SYSLOG(LOG_WARN, "unable to cd to `%s' for user `%s'\n", info->pw_dir, info->pw_name); - closelog (); - exit (EXIT_FAILURE); + closelog(); + exit(EXIT_FAILURE); } - (void) puts (_("No directory, logging in with HOME=/")); - free (info->pw_dir); - info->pw_dir = xstrdup ("/"); + (void) puts(_("No directory, logging in with HOME=/")); + free(info->pw_dir); + info->pw_dir = xstrdup("/"); } /* * Create the HOME environmental variable and export it. */ - addenv ("HOME", info->pw_dir); + addenv("HOME", info->pw_dir); /* * Create the SHELL environmental variable and export it. */ if ((NULL == info->pw_shell) || streq(info->pw_shell, "")) { - free (info->pw_shell); - info->pw_shell = xstrdup (SHELL); + free(info->pw_shell); + info->pw_shell = xstrdup(SHELL); } - addenv ("SHELL", info->pw_shell); + addenv("SHELL", info->pw_shell); /* * Export the user name. For BSD derived systems, it's "USER", for * all others it's "LOGNAME". We set both of them. */ - addenv ("USER", info->pw_name); - addenv ("LOGNAME", info->pw_name); + addenv("USER", info->pw_name); + addenv("LOGNAME", info->pw_name); /* * Create the PATH environmental variable and export it. */ - cp = getdef_str ((info->pw_uid == 0) ? "ENV_SUPATH" : "ENV_PATH"); + cp = getdef_str((info->pw_uid == 0) ? "ENV_SUPATH" : "ENV_PATH"); if (NULL == cp) { /* not specified, use a minimal default */ addenv ((info->pw_uid == 0) ? "PATH=/sbin:/bin:/usr/sbin:/usr/bin" : "PATH=/bin:/usr/bin", NULL); } else if (strchr(cp, '=')) { /* specified as name=value (PATH=...) */ - addenv (cp, NULL); + addenv(cp, NULL); } else { /* only value specified without "PATH=" */ addenv ("PATH", cp); @@ -172,19 +172,19 @@ void setup_env (struct passwd *info) * knows the prefix. */ - if (getdef_bool ("MAIL_CHECK_ENAB")) { - cp = getdef_str ("MAIL_DIR"); + if (getdef_bool("MAIL_CHECK_ENAB")) { + cp = getdef_str("MAIL_DIR"); if (NULL != cp) { - addenv_path ("MAIL", cp, info->pw_name); + addenv_path("MAIL", cp, info->pw_name); } else { - cp = getdef_str ("MAIL_FILE"); + cp = getdef_str("MAIL_FILE"); if (NULL != cp) { - addenv_path ("MAIL", info->pw_dir, cp); + addenv_path("MAIL", info->pw_dir, cp); } else { #if defined(MAIL_SPOOL_FILE) - addenv_path ("MAIL", info->pw_dir, MAIL_SPOOL_FILE); + addenv_path("MAIL", info->pw_dir, MAIL_SPOOL_FILE); #elif defined(MAIL_SPOOL_DIR) - addenv_path ("MAIL", MAIL_SPOOL_DIR, info->pw_name); + addenv_path("MAIL", MAIL_SPOOL_DIR, info->pw_name); #endif } } @@ -193,9 +193,9 @@ void setup_env (struct passwd *info) /* * Read environment from optional config file. --marekm */ - envf = getdef_str ("ENVIRON_FILE"); + envf = getdef_str("ENVIRON_FILE"); if (NULL != envf) { - read_env_file (envf); + read_env_file(envf); } #endif /* !USE_PAM */ } diff --git a/lib/sgroupio.c b/lib/sgroupio.c index ad3adc3463..573e05aefb 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -44,15 +44,15 @@ sg->sg_namp = strdup (sgent->sg_namp); /*@=mustfreeonly@*/ if (NULL == sg->sg_namp) { - free (sg); + free(sg); return NULL; } /*@-mustfreeonly@*/ sg->sg_passwd = strdup (sgent->sg_passwd); /*@=mustfreeonly@*/ if (NULL == sg->sg_passwd) { - free (sg->sg_namp); - free (sg); + free(sg->sg_namp); + free(sg); return NULL; } @@ -61,21 +61,21 @@ sg->sg_adm = malloc_T(i + 1, char *); /*@=mustfreeonly@*/ if (NULL == sg->sg_adm) { - free (sg->sg_passwd); - free (sg->sg_namp); - free (sg); + free(sg->sg_passwd); + free(sg->sg_namp); + free(sg); return NULL; } for (i = 0; NULL != sgent->sg_adm[i]; i++) { - sg->sg_adm[i] = strdup (sgent->sg_adm[i]); + sg->sg_adm[i] = strdup(sgent->sg_adm[i]); if (NULL == sg->sg_adm[i]) { for (i = 0; NULL != sg->sg_adm[i]; i++) { - free (sg->sg_adm[i]); + free(sg->sg_adm[i]); } - free (sg->sg_adm); - free (sg->sg_passwd); - free (sg->sg_namp); - free (sg); + free(sg->sg_adm); + free(sg->sg_passwd); + free(sg->sg_namp); + free(sg); return NULL; } } @@ -87,28 +87,28 @@ /*@=mustfreeonly@*/ if (NULL == sg->sg_mem) { for (i = 0; NULL != sg->sg_adm[i]; i++) { - free (sg->sg_adm[i]); + free(sg->sg_adm[i]); } - free (sg->sg_adm); - free (sg->sg_passwd); - free (sg->sg_namp); - free (sg); + free(sg->sg_adm); + free(sg->sg_passwd); + free(sg->sg_namp); + free(sg); return NULL; } for (i = 0; NULL != sgent->sg_mem[i]; i++) { - sg->sg_mem[i] = strdup (sgent->sg_mem[i]); + sg->sg_mem[i] = strdup(sgent->sg_mem[i]); if (NULL == sg->sg_mem[i]) { for (i = 0; NULL != sg->sg_mem[i]; i++) { - free (sg->sg_mem[i]); + free(sg->sg_mem[i]); } - free (sg->sg_mem); + free(sg->sg_mem); for (i = 0; NULL != sg->sg_adm[i]; i++) { - free (sg->sg_adm[i]); + free(sg->sg_adm[i]); } - free (sg->sg_adm); - free (sg->sg_passwd); - free (sg->sg_namp); - free (sg); + free(sg->sg_adm); + free(sg->sg_passwd); + free(sg->sg_namp); + free(sg); return NULL; } } @@ -129,7 +129,7 @@ gshadow_free(/*@only@*/void *ent) { struct sgrp *sg = ent; - sgr_free (sg); + sgr_free(sg); } void @@ -177,7 +177,7 @@ static int gshadow_put (const void *ent, FILE * file) if (NULL != sg->sg_adm) { size_t i; for (i = 0; NULL != sg->sg_adm[i]; i++) { - if (valid_field (sg->sg_adm[i], ",:\n") == -1) { + if (valid_field(sg->sg_adm[i], ",:\n") == -1) { return -1; } } @@ -226,9 +226,9 @@ static struct commonio_db gshadow_db = { false /* setname */ }; -int sgr_setdbname (const char *filename) +int sgr_setdbname(const char *filename) { - return commonio_setname (&gshadow_db, filename); + return commonio_setname(&gshadow_db, filename); } /*@observer@*/const char *sgr_dbname (void) @@ -255,22 +255,22 @@ int sgr_open (int mode) /*@observer@*/ /*@null@*/const struct sgrp *sgr_locate (const char *name) { - return commonio_locate (&gshadow_db, name); + return commonio_locate(&gshadow_db, name); } -int sgr_update (const struct sgrp *sg) +int sgr_update(const struct sgrp *sg) { - return commonio_update (&gshadow_db, sg); + return commonio_update(&gshadow_db, sg); } -int sgr_remove (const char *name) +int sgr_remove(const char *name) { - return commonio_remove (&gshadow_db, name); + return commonio_remove(&gshadow_db, name); } -int sgr_rewind (void) +int sgr_rewind(void) { - return commonio_rewind (&gshadow_db); + return commonio_rewind(&gshadow_db); } /*@null@*/const struct sgrp *sgr_next (void) @@ -298,9 +298,9 @@ void __sgr_set_changed (void) return gshadow_db.head; } -void __sgr_del_entry (const struct commonio_entry *ent) +void __sgr_del_entry(const struct commonio_entry *ent) { - commonio_del_entry (&gshadow_db, ent); + commonio_del_entry(&gshadow_db, ent); } /* Sort with respect to group ordering. */ diff --git a/lib/sgroupio.h b/lib/sgroupio.h index 567e380a57..c0a336c21c 100644 --- a/lib/sgroupio.h +++ b/lib/sgroupio.h @@ -21,15 +21,15 @@ extern int sgr_close (bool process_selinux); extern bool sgr_file_present (void); extern /*@observer@*/ /*@null@*/const struct sgrp *sgr_locate (const char *name); -extern int sgr_lock (void); -extern int sgr_setdbname (const char *filename); +extern int sgr_lock(void); +extern int sgr_setdbname(const char *filename); extern /*@observer@*/const char *sgr_dbname (void); extern /*@null@*/const struct sgrp *sgr_next (void); -extern int sgr_open (int mode); -extern int sgr_remove (const char *name); -extern int sgr_rewind (void); -extern int sgr_unlock (bool process_selinux); -extern int sgr_update (const struct sgrp *sg); -extern int sgr_sort (void); +extern int sgr_open(int mode); +extern int sgr_remove(const char *name); +extern int sgr_rewind(void); +extern int sgr_unlock(bool process_selinux); +extern int sgr_update(const struct sgrp *sg); +extern int sgr_sort(void); #endif diff --git a/lib/shadow/gshadow/getsgent.c b/lib/shadow/gshadow/getsgent.c index 0e4c55977d..8a25c07fc1 100644 --- a/lib/shadow/gshadow/getsgent.c +++ b/lib/shadow/gshadow/getsgent.c @@ -24,7 +24,7 @@ struct sgrp * getsgent(void) { if (NULL == gshadow) { - setsgent (); + setsgent(); } return fgetsgent(gshadow); } diff --git a/lib/shadow/gshadow/getsgnam.c b/lib/shadow/gshadow/getsgnam.c index 86fb9ad49d..4e2047c6a1 100644 --- a/lib/shadow/gshadow/getsgnam.c +++ b/lib/shadow/gshadow/getsgnam.c @@ -29,10 +29,10 @@ getsgnam(const char *name) { struct sgrp *sgrp; - setsgent (); + setsgent(); - while (NULL != (sgrp = getsgent ())) { - if (strcmp (name, sgrp->sg_namp) == 0) { + while (NULL != (sgrp = getsgent())) { + if (strcmp(name, sgrp->sg_namp) == 0) { break; } } diff --git a/lib/shadow/gshadow/putsgent.c b/lib/shadow/gshadow/putsgent.c index 7a7b98727f..9a0fa6a7a1 100644 --- a/lib/shadow/gshadow/putsgent.c +++ b/lib/shadow/gshadow/putsgent.c @@ -85,11 +85,11 @@ putsgent(const struct sgrp *sgrp, FILE *fp) stpcpy(cp, "\n"); if (fputs(buf, fp) == EOF) { - free (buf); + free(buf); return -1; } - free (buf); + free(buf); return 0; } #endif diff --git a/lib/shadowio.c b/lib/shadowio.c index bf875036ed..b302388119 100644 --- a/lib/shadowio.c +++ b/lib/shadowio.c @@ -40,34 +40,34 @@ shadow_free(/*@only@*/void *ent) { struct spwd *sp = ent; - spw_free (sp); + spw_free(sp); } -static const char *shadow_getname (const void *ent) +static const char *shadow_getname(const void *ent) { const struct spwd *sp = ent; return sp->sp_namp; } -static void *shadow_parse (const char *line) +static void *shadow_parse(const char *line) { - return sgetspent (line); + return sgetspent(line); } -static int shadow_put (const void *ent, FILE * file) +static int shadow_put(const void *ent, FILE * file) { const struct spwd *sp = ent; if ( (NULL == sp) - || (valid_field (sp->sp_namp, ":\n") == -1) - || (valid_field (sp->sp_pwdp, ":\n") == -1) - || (strlen (sp->sp_namp) + strlen (sp->sp_pwdp) + + || (valid_field(sp->sp_namp, ":\n") == -1) + || (valid_field(sp->sp_pwdp, ":\n") == -1) + || (strlen(sp->sp_namp) + strlen(sp->sp_pwdp) + 1000 > PASSWD_ENTRY_MAX_LENGTH)) { return -1; } - return (putspent (sp, file) == -1) ? -1 : 0; + return (putspent(sp, file) == -1) ? -1 : 0; } static struct commonio_ops shadow_ops = { @@ -110,50 +110,50 @@ int spw_setdbname (const char *filename) return shadow_db.filename; } -bool spw_file_present (void) +bool spw_file_present(void) { - if (getdef_bool ("FORCE_SHADOW")) + if (getdef_bool("FORCE_SHADOW")) return true; - return commonio_present (&shadow_db); + return commonio_present(&shadow_db); } -int spw_lock (void) +int spw_lock(void) { #ifdef WITH_TCB int retval = 0; - if (!getdef_bool ("USE_TCB")) { + if (!getdef_bool("USE_TCB")) { #endif /* WITH_TCB */ - return commonio_lock (&shadow_db); + return commonio_lock(&shadow_db); #ifdef WITH_TCB } - if (shadowtcb_drop_priv () == SHADOWTCB_FAILURE) { + if (shadowtcb_drop_priv() == SHADOWTCB_FAILURE) { return 0; } - if (lckpwdf_tcb (shadow_db.filename) == 0) { + if (lckpwdf_tcb(shadow_db.filename) == 0) { shadow_db.locked = 1; retval = 1; } - if (shadowtcb_gain_priv () == SHADOWTCB_FAILURE) { + if (shadowtcb_gain_priv() == SHADOWTCB_FAILURE) { return 0; } return retval; #endif /* WITH_TCB */ } -int spw_open (int mode) +int spw_open(int mode) { int retval = 0; #ifdef WITH_TCB - bool use_tcb = getdef_bool ("USE_TCB"); + bool use_tcb = getdef_bool("USE_TCB"); - if (use_tcb && (shadowtcb_drop_priv () == SHADOWTCB_FAILURE)) { + if (use_tcb && (shadowtcb_drop_priv() == SHADOWTCB_FAILURE)) { return 0; } #endif /* WITH_TCB */ - retval = commonio_open (&shadow_db, mode); + retval = commonio_open(&shadow_db, mode); #ifdef WITH_TCB - if (use_tcb && (shadowtcb_gain_priv () == SHADOWTCB_FAILURE)) { + if (use_tcb && (shadowtcb_gain_priv() == SHADOWTCB_FAILURE)) { return 0; } #endif /* WITH_TCB */ @@ -182,60 +182,60 @@ int spw_rewind (void) /*@observer@*/ /*@null@*/const struct spwd *spw_next (void) { - return commonio_next (&shadow_db); + return commonio_next(&shadow_db); } -int spw_close (bool process_selinux) +int spw_close(bool process_selinux) { int retval = 0; #ifdef WITH_TCB - bool use_tcb = getdef_bool ("USE_TCB"); + bool use_tcb = getdef_bool("USE_TCB"); - if (use_tcb && (shadowtcb_drop_priv () == SHADOWTCB_FAILURE)) { + if (use_tcb && (shadowtcb_drop_priv() == SHADOWTCB_FAILURE)) { return 0; } #endif /* WITH_TCB */ - retval = commonio_close (&shadow_db, process_selinux); + retval = commonio_close(&shadow_db, process_selinux); #ifdef WITH_TCB - if (use_tcb && (shadowtcb_gain_priv () == SHADOWTCB_FAILURE)) { + if (use_tcb && (shadowtcb_gain_priv() == SHADOWTCB_FAILURE)) { return 0; } #endif /* WITH_TCB */ return retval; } -int spw_unlock (bool process_selinux) +int spw_unlock(bool process_selinux) { #ifdef WITH_TCB int retval = 0; - if (!getdef_bool ("USE_TCB")) { + if (!getdef_bool("USE_TCB")) { #endif /* WITH_TCB */ - return commonio_unlock (&shadow_db, process_selinux); + return commonio_unlock(&shadow_db, process_selinux); #ifdef WITH_TCB } - if (shadowtcb_drop_priv () == SHADOWTCB_FAILURE) { + if (shadowtcb_drop_priv() == SHADOWTCB_FAILURE) { return 0; } - if (ulckpwdf_tcb () == 0) { + if (ulckpwdf_tcb() == 0) { shadow_db.locked = 0; retval = 1; } - if (shadowtcb_gain_priv () == SHADOWTCB_FAILURE) { + if (shadowtcb_gain_priv() == SHADOWTCB_FAILURE) { return 0; } return retval; #endif /* WITH_TCB */ } -struct commonio_entry *__spw_get_head (void) +struct commonio_entry *__spw_get_head(void) { return shadow_db.head; } -void __spw_del_entry (const struct commonio_entry *ent) +void __spw_del_entry(const struct commonio_entry *ent) { - commonio_del_entry (&shadow_db, ent); + commonio_del_entry(&shadow_db, ent); } /* Sort with respect to passwd ordering. */ diff --git a/lib/shadowio.h b/lib/shadowio.h index be645d0e5e..e1536d3ee8 100644 --- a/lib/shadowio.h +++ b/lib/shadowio.h @@ -16,15 +16,15 @@ extern int spw_close (bool process_selinux); extern bool spw_file_present (void); extern /*@observer@*/ /*@null@*/const struct spwd *spw_locate (const char *name); -extern int spw_lock (void); -extern int spw_setdbname (const char *filename); +extern int spw_lock(void); +extern int spw_setdbname(const char *filename); extern /*@observer@*/const char *spw_dbname (void); extern /*@observer@*/ /*@null@*/const struct spwd *spw_next (void); -extern int spw_open (int mode); -extern int spw_remove (const char *name); -extern int spw_rewind (void); -extern int spw_unlock (bool process_selinux); -extern int spw_update (const struct spwd *sp); -extern int spw_sort (void); +extern int spw_open(int mode); +extern int spw_remove(const char *name); +extern int spw_rewind(void); +extern int spw_unlock(bool process_selinux); +extern int spw_update(const struct spwd *sp); +extern int spw_sort(void); #endif diff --git a/lib/shell.c b/lib/shell.c index 1e49df7b03..62f41d8964 100644 --- a/lib/shell.c +++ b/lib/shell.c @@ -57,15 +57,15 @@ 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 *) NULL, envp); + (void) execle(file, arg, (char *) NULL, envp); err = errno; - if (access (file, R_OK|X_OK) == 0) { + if (access(file, R_OK|X_OK) == 0) { /* * Assume this is a shell script (with no shebang). * Interpret it with /bin/sh */ - (void) execle (SHELL, "sh", "-", file, (char *) NULL, envp); + (void) execle(SHELL, "sh", "-", file, (char *) NULL, envp); err = errno; } @@ -76,7 +76,7 @@ int shell (const char *file, /*@null@*/const char *arg, char *const envp[]) */ stprintf_a(arg0, _("Cannot execute %s"), file); errno = err; - perror (arg0); + perror(arg0); return err; } diff --git a/lib/sssd.c b/lib/sssd.c index cc5d4a464d..34b64f11a8 100644 --- a/lib/sssd.c +++ b/lib/sssd.c @@ -52,7 +52,7 @@ sssd_flush_cache(int dbflags) spawnedArgs[1] = sss_cache_args; - rv = run_command (cmd, spawnedArgs, spawnedEnv, &status); + rv = run_command(cmd, spawnedArgs, spawnedEnv, &status); free(sss_cache_args); if (rv != 0) { /* run_command writes its own more detailed message. */ diff --git a/lib/sssd.h b/lib/sssd.h index e99ccb3cc3..a9fb4f35c6 100644 --- a/lib/sssd.h +++ b/lib/sssd.h @@ -10,7 +10,7 @@ * sssd_flush_cache - flush specified service buffer in sssd cache */ #ifdef USE_SSSD -extern int sssd_flush_cache (int dbflags); +extern int sssd_flush_cache(int dbflags); #else static inline int sssd_flush_cache(MAYBE_UNUSED int _1) diff --git a/lib/string/strcmp/strcaseprefix.h b/lib/string/strcmp/strcaseprefix.h index b001076b6b..268d5ff2b4 100644 --- a/lib/string/strcmp/strcaseprefix.h +++ b/lib/string/strcmp/strcaseprefix.h @@ -22,7 +22,7 @@ \ p_ = strcaseprefix_(s, prefix); \ \ - _Generic(s, \ + _Generic (s, \ const char *: p_, \ const void *: p_, \ char *: const_cast(char *, p_), \ diff --git a/lib/string/strcmp/strprefix.h b/lib/string/strcmp/strprefix.h index 3abffb5f4e..cc2719e688 100644 --- a/lib/string/strcmp/strprefix.h +++ b/lib/string/strcmp/strprefix.h @@ -22,7 +22,7 @@ \ p_ = strprefix_(s, prefix); \ \ - _Generic(s, \ + _Generic (s, \ const char *: p_, \ const void *: p_, \ char *: const_cast(char *, p_), \ diff --git a/lib/sub.c b/lib/sub.c index 14d220eb21..769e3bbc1e 100644 --- a/lib/sub.c +++ b/lib/sub.c @@ -27,7 +27,7 @@ * directory will be used as the root of a new filesystem which * the user is actually logged into. */ -void subsystem (const struct passwd *pw) +void subsystem(const struct passwd *pw) { static int depth = 0; @@ -35,10 +35,10 @@ void subsystem (const struct passwd *pw) * Prevent endless loop on misconfigured systems. */ if (++depth > MAX_DEPTH) { - printf (_("Maximum subsystem depth reached\n")); + printf(_("Maximum subsystem depth reached\n")); SYSLOG(LOG_WARN, MAX_SUBROOT2); - closelog (); - exit (EXIT_FAILURE); + closelog(); + exit(EXIT_FAILURE); } /* @@ -46,10 +46,10 @@ void subsystem (const struct passwd *pw) */ if (pw->pw_dir[0] != '/') { - printf (_("Invalid root directory '%s'\n"), pw->pw_dir); + printf(_("Invalid root directory '%s'\n"), pw->pw_dir); SYSLOG(LOG_WARN, BAD_SUBROOT2, pw->pw_dir, pw->pw_name); - closelog (); - exit (EXIT_FAILURE); + closelog(); + exit(EXIT_FAILURE); } /* @@ -57,13 +57,13 @@ void subsystem (const struct passwd *pw) * must be able to change into it. */ - if ( (chroot (pw->pw_dir) != 0) - || (chdir ("/") != 0)) { - (void) printf (_("Can't change root directory to '%s'\n"), + 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); - closelog (); - exit (EXIT_FAILURE); + closelog(); + exit(EXIT_FAILURE); } } diff --git a/lib/subordinateio.c b/lib/subordinateio.c index acd3f1ffdc..ef2e40fa43 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -92,7 +92,7 @@ subordinate_parse(const char *line) * Copy the string to a temporary buffer so the substrings can * be modified to be NULL terminated. */ - if (strlen(line) >= sizeof(rangebuf)) + if (strlen(line) >= sizeof (rangebuf)) return NULL; /* fail if too long */ strcpy (rangebuf, line); @@ -122,7 +122,7 @@ subordinate_parse(const char *line) * * Returns 0 on success, -1 on error. */ -static int subordinate_put (const void *ent, FILE * file) +static int subordinate_put(const void *ent, FILE * file) { const struct subordinate_range *range = ent; @@ -308,7 +308,7 @@ void free_subordinate_ranges(struct subordinate_range **ranges, int count) * equal) if the owning uid in p1 is lower than p2's. Return 1 if p1's * range or owning uid is great than p2's. */ -static int subordinate_range_cmp (const void *p1, const void *p2) +static int subordinate_range_cmp(const void *p1, const void *p2) { const struct commonio_entry *const *ce1; const struct commonio_entry *const *ce2; @@ -358,7 +358,7 @@ static unsigned long find_free_range(struct commonio_db *db, goto fail; /* Sort by range then by owner */ - commonio_sort (db, subordinate_range_cmp); + commonio_sort(db, subordinate_range_cmp); commonio_rewind(db); low = min; @@ -430,7 +430,7 @@ static int add_range(struct commonio_db *db, * Returns 0 on failure, 1 on success. Failure means that we needed to * create a new range to represent the new limits, and failed doing so. */ -static int remove_range (struct commonio_db *db, +static int remove_range(struct commonio_db *db, const char *owner, unsigned long start, unsigned long count) { @@ -471,7 +471,7 @@ static int remove_range (struct commonio_db *db, * range: [first, last] */ /* entry completely contained in the * range to remove */ - commonio_del_entry (db, ent); + commonio_del_entry(db, ent); } else { /* to be removed: [start, end] * range: [first, last] */ @@ -501,7 +501,7 @@ static int remove_range (struct commonio_db *db, tail.start = end + 1; tail.count = (last - tail.start) + 1; - if (commonio_append (db, &tail) == 0) { + if (commonio_append(db, &tail) == 0) { return 0; } @@ -569,7 +569,7 @@ static bool have_range(struct commonio_db *db, } end = start + count - 1; - range = find_range (db, owner, start); + range = find_range(db, owner, start); while (range) { unsigned long last; @@ -594,9 +594,9 @@ static bool have_range(struct commonio_db *db, return ret; } -int sub_uid_setdbname (const char *filename) +int sub_uid_setdbname(const char *filename) { - return commonio_setname (&subordinate_uid_db, filename); + return commonio_setname(&subordinate_uid_db, filename); } /*@observer@*/const char *sub_uid_dbname (void) @@ -645,13 +645,13 @@ bool have_sub_uids(const char *owner, uid_t start, unsigned long count) * Return 1 if the range is already present or on success. On error * return 0 and set errno appropriately. */ -int sub_uid_add (const char *owner, uid_t start, unsigned long count) +int sub_uid_add(const char *owner, uid_t start, unsigned long count) { if (get_subid_nss_handle()) { errno = EOPNOTSUPP; return 0; } - return add_range (&subordinate_uid_db, owner, start, count); + return add_range(&subordinate_uid_db, owner, start, count); } /* Return 1 on success. on failure, return 0 and set errno appropriately */ @@ -742,19 +742,19 @@ int sub_gid_setdbname (const char *filename) return subordinate_gid_db.filename; } -bool sub_gid_file_present (void) +bool sub_gid_file_present(void) { - return commonio_present (&subordinate_gid_db); + return commonio_present(&subordinate_gid_db); } -int sub_gid_lock (void) +int sub_gid_lock(void) { - return commonio_lock (&subordinate_gid_db); + return commonio_lock(&subordinate_gid_db); } -int sub_gid_open (int mode) +int sub_gid_open(int mode) { - return commonio_open (&subordinate_gid_db, mode); + return commonio_open(&subordinate_gid_db, mode); } bool have_sub_gids(const char *owner, gid_t start, unsigned long count) @@ -774,7 +774,7 @@ bool have_sub_gids(const char *owner, gid_t start, unsigned long count) bool local_sub_gid_assigned(const char *owner) { - return range_exists (&subordinate_gid_db, owner); + return range_exists(&subordinate_gid_db, owner); } /* @@ -783,13 +783,13 @@ bool local_sub_gid_assigned(const char *owner) * Return 1 if the range is already present or on success. On error * return 0 and set errno appropriately. */ -int sub_gid_add (const char *owner, gid_t start, unsigned long count) +int sub_gid_add(const char *owner, gid_t start, unsigned long count) { if (get_subid_nss_handle()) { errno = EOPNOTSUPP; return 0; } - return add_range (&subordinate_gid_db, owner, start, count); + return add_range(&subordinate_gid_db, owner, start, count); } /* Return 1 on success. on failure, return 0 and set errno appropriately */ diff --git a/lib/subordinateio.h b/lib/subordinateio.h index 38f9f28578..6fee0e675b 100644 --- a/lib/subordinateio.h +++ b/lib/subordinateio.h @@ -15,10 +15,10 @@ extern int sub_uid_close(bool process_selinux); extern bool have_sub_uids(const char *owner, uid_t start, unsigned long count); -extern bool sub_uid_file_present (void); +extern bool sub_uid_file_present(void); extern bool local_sub_uid_assigned(const char *owner); -extern int sub_uid_lock (void); -extern int sub_uid_setdbname (const char *filename); +extern int sub_uid_lock(void); +extern int sub_uid_setdbname(const char *filename); extern /*@observer@*/const char *sub_uid_dbname (void); extern int sub_uid_open (int mode); extern int sub_uid_unlock (bool process_selinux); @@ -39,10 +39,10 @@ extern bool local_sub_gid_assigned(const char *owner); extern int sub_gid_lock (void); extern int sub_gid_setdbname (const char *filename); extern /*@observer@*/const char *sub_gid_dbname (void); -extern int sub_gid_open (int mode); -extern int sub_gid_unlock (bool process_selinux); -extern int sub_gid_add (const char *owner, gid_t start, unsigned long count); -extern int sub_gid_remove (const char *owner, gid_t start, unsigned long count); +extern int sub_gid_open(int mode); +extern int sub_gid_unlock(bool process_selinux); +extern int sub_gid_add(const char *owner, gid_t start, unsigned long count); +extern int sub_gid_remove(const char *owner, gid_t start, unsigned long count); extern uid_t sub_gid_find_free_range(gid_t min, gid_t max, unsigned long count); extern bool want_subgid_file(void); diff --git a/lib/sulog.c b/lib/sulog.c index 787c62614e..4a644a0d57 100644 --- a/lib/sulog.c +++ b/lib/sulog.c @@ -22,7 +22,7 @@ /* * sulog - log a SU command execution result */ -void sulog (const char *tty, bool success, const char *oldname, const char *name) +void sulog(const char *tty, bool success, const char *oldname, const char *name) { const char *sulog_file; time_t now; @@ -37,16 +37,16 @@ void sulog (const char *tty, bool success, const char *oldname, const char *name SYSLOG(LOG_NOTICE, "FAILED su for %s by %s", name, oldname); } - sulog_file = getdef_str ("SULOG_FILE"); + sulog_file = getdef_str("SULOG_FILE"); if (NULL == sulog_file) { return; } - oldgid = getgid (); - oldmask = umask (077); + oldgid = getgid(); + oldmask = umask(077); /* Switch to group root to avoid creating the sulog file with * the wrong group ownership. */ - if ((oldgid != 0) && (setgid (0) != 0)) { + if ((oldgid != 0) && (setgid(0) != 0)) { SYSLOG(LOG_INFO, "su session not logged to %s", sulog_file); /* Continue, but do not switch back to oldgid later */ oldgid = 0; @@ -57,7 +57,7 @@ void sulog (const char *tty, bool success, const char *oldname, const char *name perror ("setgid"); SYSLOG(LOG_ERR, "can't switch back to group `%d' in sulog", oldgid); /* Do not return if the group permission were raised. */ - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } if (fp == NULL) { return; /* can't open or create logfile */ diff --git a/lib/tcbfuncs.c b/lib/tcbfuncs.c index 627bc63363..119835bfae 100644 --- a/lib/tcbfuncs.c +++ b/lib/tcbfuncs.c @@ -64,8 +64,8 @@ shadowtcb_status shadowtcb_gain_priv (void) * to exit soon. */ #define OUT_OF_MEMORY do { \ - fprintf (log_get_logfd(), _("%s: out of memory\n"), log_get_progname()); \ - (void) fflush (log_get_logfd()); \ + fprintf(log_get_logfd(), _("%s: out of memory\n"), log_get_progname()); \ + (void) fflush(log_get_logfd()); \ } while (false) /* Returns user's tcb directory path relative to TCB_DIR. */ @@ -73,7 +73,7 @@ static /*@null@*/ char *shadowtcb_path_rel (const char *name, uid_t uid) { char *ret; - if (!getdef_bool ("TCB_SYMLINKS") || uid < SHADOWTCB_HASH_BY) { + if (!getdef_bool("TCB_SYMLINKS") || uid < SHADOWTCB_HASH_BY) { ret = strdup(name); } else if (uid < SHADOWTCB_HASH_BY * SHADOWTCB_HASH_BY) { ret = aprintf(":%dK/%s", uid / SHADOWTCB_HASH_BY, name); @@ -144,17 +144,17 @@ static /*@null@*/ char *shadowtcb_path (const char *name, uid_t uid) { char *ret, *rel; - rel = shadowtcb_path_rel (name, uid); + rel = shadowtcb_path_rel(name, uid); if (NULL == rel) { return NULL; } ret = aprintf(TCB_DIR "/%s", rel); if (ret == NULL) { OUT_OF_MEMORY; - free (rel); + free(rel); return NULL; } - free (rel); + free(rel); return ret; } @@ -272,7 +272,7 @@ rmdir_leading(const char *relpath) if (rmdir(path) != 0) { if (errno != ENOTEMPTY) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: Cannot remove directory %s: %s\n"), log_get_progname(), path, strerrno()); ret = SHADOWTCB_FAILURE; @@ -289,7 +289,7 @@ rmdir_leading(const char *relpath) return SHADOWTCB_FAILURE; } -static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid) +static shadowtcb_status move_dir(const char *user_newname, uid_t user_newid) { char *olddir = NULL, *newdir = NULL; char *real_old_dir = NULL, *real_new_dir = NULL; @@ -305,19 +305,19 @@ static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid) if (olddir == NULL) { goto out_free_nomem; } - if (stat (olddir, &oldmode) != 0) { - fprintf (log_get_logfd(), + if (stat(olddir, &oldmode) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot stat %s: %s\n"), log_get_progname(), olddir, strerrno()); goto out_free; } old_uid = oldmode.st_uid; the_newid = (user_newid == -1) ? old_uid : user_newid; - real_old_dir = shadowtcb_path_existing (stored_tcb_user); + real_old_dir = shadowtcb_path_existing(stored_tcb_user); if (NULL == real_old_dir) { goto out_free; } - real_new_dir = shadowtcb_path (user_newname, the_newid); + real_new_dir = shadowtcb_path(user_newname, the_newid); if (NULL == real_new_dir) { goto out_free; } @@ -325,24 +325,24 @@ static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid) ret = SHADOWTCB_SUCCESS; goto out_free; } - real_old_dir_rel = shadowtcb_path_rel_existing (stored_tcb_user); + real_old_dir_rel = shadowtcb_path_rel_existing(stored_tcb_user); if (NULL == real_old_dir_rel) { goto out_free; } - if (mkdir_leading (user_newname, the_newid) == SHADOWTCB_FAILURE) { + if (mkdir_leading(user_newname, the_newid) == SHADOWTCB_FAILURE) { goto out_free; } - if (rename (real_old_dir, real_new_dir) != 0) { - fprintf (log_get_logfd(), + if (rename(real_old_dir, real_new_dir) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot rename %s to %s: %s\n"), log_get_progname(), real_old_dir, real_new_dir, strerrno()); goto out_free; } - if (rmdir_leading (real_old_dir_rel) == SHADOWTCB_FAILURE) { + if (rmdir_leading(real_old_dir_rel) == SHADOWTCB_FAILURE) { goto out_free; } - if ((unlink (olddir) != 0) && (errno != ENOENT)) { - fprintf (log_get_logfd(), + if ((unlink(olddir) != 0) && (errno != ENOENT)) { + fprintf(log_get_logfd(), _("%s: Cannot remove %s: %s\n"), log_get_progname(), olddir, strerrno()); goto out_free; @@ -351,13 +351,13 @@ static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid) if (newdir == NULL) { goto out_free_nomem; } - real_new_dir_rel = shadowtcb_path_rel (user_newname, the_newid); + real_new_dir_rel = shadowtcb_path_rel(user_newname, the_newid); if (NULL == real_new_dir_rel) { goto out_free; } if ( !streq(real_new_dir, newdir) - && (symlink (real_new_dir_rel, newdir) != 0)) { - fprintf (log_get_logfd(), + && (symlink(real_new_dir_rel, newdir) != 0)) { + fprintf(log_get_logfd(), _("%s: Cannot create symbolic link %s: %s\n"), log_get_progname(), real_new_dir_rel, strerrno()); goto out_free; @@ -367,27 +367,27 @@ static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid) out_free_nomem: OUT_OF_MEMORY; out_free: - free (olddir); - free (newdir); - free (real_old_dir); - free (real_new_dir); - free (real_old_dir_rel); - free (real_new_dir_rel); + free(olddir); + free(newdir); + free(real_old_dir); + free(real_new_dir); + free(real_old_dir_rel); + free(real_new_dir_rel); return ret; } -shadowtcb_status shadowtcb_set_user (const char* name) +shadowtcb_status shadowtcb_set_user(const char* name) { char *buf; shadowtcb_status retval; - if (!getdef_bool ("USE_TCB")) { + if (!getdef_bool("USE_TCB")) { return SHADOWTCB_SUCCESS; } - free (stored_tcb_user); + free(stored_tcb_user); - stored_tcb_user = strdup (name); + stored_tcb_user = strdup(name); if (NULL == stored_tcb_user) { OUT_OF_MEMORY; return SHADOWTCB_FAILURE; @@ -398,8 +398,8 @@ shadowtcb_status shadowtcb_set_user (const char* name) return SHADOWTCB_FAILURE; } - retval = (spw_setdbname (buf) != 0) ? SHADOWTCB_SUCCESS : SHADOWTCB_FAILURE; - free (buf); + retval = (spw_setdbname(buf) != 0) ? SHADOWTCB_SUCCESS : SHADOWTCB_FAILURE; + free(buf); return retval; } @@ -435,7 +435,7 @@ shadowtcb_status shadowtcb_move (/*@NULL@*/const char *user_newname, uid_t user_ char *tcbdir, *shadow; shadowtcb_status ret = SHADOWTCB_FAILURE; - if (!getdef_bool ("USE_TCB")) { + if (!getdef_bool("USE_TCB")) { return SHADOWTCB_SUCCESS; } if (NULL == stored_tcb_user) { @@ -444,7 +444,7 @@ shadowtcb_status shadowtcb_move (/*@NULL@*/const char *user_newname, uid_t user_ if (NULL == user_newname) { user_newname = stored_tcb_user; } - if (move_dir (user_newname, user_newid) == SHADOWTCB_FAILURE) { + if (move_dir(user_newname, user_newid) == SHADOWTCB_FAILURE) { return SHADOWTCB_FAILURE; } if (-1 == user_newid) { @@ -460,80 +460,80 @@ shadowtcb_status shadowtcb_move (/*@NULL@*/const char *user_newname, uid_t user_ OUT_OF_MEMORY; return SHADOWTCB_FAILURE; } - if (stat (tcbdir, &dirmode) != 0) { - fprintf (log_get_logfd(), + if (stat(tcbdir, &dirmode) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot stat %s: %s\n"), log_get_progname(), tcbdir, strerrno()); goto out_free; } - if (chown (tcbdir, 0, 0) != 0) { - fprintf (log_get_logfd(), + if (chown(tcbdir, 0, 0) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot change owners of %s: %s\n"), log_get_progname(), tcbdir, strerrno()); goto out_free; } - if (chmod (tcbdir, 0700) != 0) { - fprintf (log_get_logfd(), + if (chmod(tcbdir, 0700) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot change mode of %s: %s\n"), log_get_progname(), tcbdir, strerrno()); goto out_free; } - if (lstat (shadow, &filemode) != 0) { + if (lstat(shadow, &filemode) != 0) { if (errno != ENOENT) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: Cannot lstat %s: %s\n"), log_get_progname(), shadow, strerrno()); goto out_free; } - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: Warning, user %s has no tcb shadow file.\n"), log_get_progname(), user_newname); } else { - if (!S_ISREG (filemode.st_mode) || + if (!S_ISREG(filemode.st_mode) || filemode.st_nlink != 1) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: Emergency: %s's tcb shadow is not a " "regular file with st_nlink=1.\n" "The account is left locked.\n"), log_get_progname(), user_newname); goto out_free; } - if (chown (shadow, user_newid, filemode.st_gid) != 0) { - fprintf (log_get_logfd(), + if (chown(shadow, user_newid, filemode.st_gid) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot change owner of %s: %s\n"), log_get_progname(), shadow, strerrno()); goto out_free; } - if (chmod (shadow, filemode.st_mode & 07777) != 0) { - fprintf (log_get_logfd(), + if (chmod(shadow, filemode.st_mode & 07777) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot change mode of %s: %s\n"), log_get_progname(), shadow, strerrno()); goto out_free; } } - if (unlink_suffs (user_newname) == SHADOWTCB_FAILURE) { + if (unlink_suffs(user_newname) == SHADOWTCB_FAILURE) { goto out_free; } - if (chown (tcbdir, user_newid, dirmode.st_gid) != 0) { - fprintf (log_get_logfd(), + if (chown(tcbdir, user_newid, dirmode.st_gid) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot change owner of %s: %s\n"), log_get_progname(), tcbdir, strerrno()); goto out_free; } - if (chmod (tcbdir, dirmode.st_mode & 07777) != 0) { - fprintf (log_get_logfd(), + if (chmod(tcbdir, dirmode.st_mode & 07777) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot change mode of %s: %s\n"), log_get_progname(), tcbdir, strerrno()); goto out_free; } ret = SHADOWTCB_SUCCESS; out_free: - free (tcbdir); - free (shadow); + free(tcbdir); + free(shadow); return ret; } -shadowtcb_status shadowtcb_create (const char *name, uid_t uid) +shadowtcb_status shadowtcb_create(const char *name, uid_t uid) { char *dir, *shadow; struct stat tcbdir_stat; @@ -542,19 +542,19 @@ shadowtcb_status shadowtcb_create (const char *name, uid_t uid) int fd = -1; shadowtcb_status ret = SHADOWTCB_FAILURE; - if (!getdef_bool ("USE_TCB")) { + if (!getdef_bool("USE_TCB")) { return SHADOWTCB_SUCCESS; } - if (stat (TCB_DIR, &tcbdir_stat) != 0) { - fprintf (log_get_logfd(), + if (stat(TCB_DIR, &tcbdir_stat) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot stat %s: %s\n"), log_get_progname(), TCB_DIR, strerrno()); return SHADOWTCB_FAILURE; } shadowgid = tcbdir_stat.st_gid; authgid = shadowgid; - if (getdef_bool ("TCB_AUTH_GROUP")) { - gr = getgrnam ("auth"); + if (getdef_bool("TCB_AUTH_GROUP")) { + gr = getgrnam("auth"); if (NULL != gr) { authgid = gr->gr_gid; } @@ -570,52 +570,52 @@ shadowtcb_status shadowtcb_create (const char *name, uid_t uid) OUT_OF_MEMORY; return SHADOWTCB_FAILURE; } - if (mkdir (dir, 0700) != 0) { - fprintf (log_get_logfd(), + if (mkdir(dir, 0700) != 0) { + fprintf(log_get_logfd(), _("%s: mkdir: %s: %s\n"), log_get_progname(), dir, strerrno()); goto out_free; } - fd = open (shadow, O_RDWR | O_CREAT | O_TRUNC, 0600); + fd = open(shadow, O_RDWR | O_CREAT | O_TRUNC, 0600); if (fd < 0) { - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: Cannot open %s: %s\n"), log_get_progname(), shadow, strerrno()); goto out_free; } - if (fchown (fd, 0, authgid) != 0) { - fprintf (log_get_logfd(), + if (fchown(fd, 0, authgid) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot change owner of %s: %s\n"), log_get_progname(), shadow, strerrno()); goto out_free; } - if (fchmod (fd, (mode_t) ((authgid == shadowgid) ? 0600 : 0640)) != 0) { - fprintf (log_get_logfd(), + if (fchmod(fd, (mode_t) ((authgid == shadowgid) ? 0600 : 0640)) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot change mode of %s: %s\n"), log_get_progname(), shadow, strerrno()); goto out_free; } - if (chown (dir, 0, authgid) != 0) { - fprintf (log_get_logfd(), + if (chown(dir, 0, authgid) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot change owner of %s: %s\n"), log_get_progname(), dir, strerrno()); goto out_free; } - if (chmod (dir, (mode_t) ((authgid == shadowgid) ? 02700 : 02710)) != 0) { - fprintf (log_get_logfd(), + if (chmod(dir, (mode_t) ((authgid == shadowgid) ? 02700 : 02710)) != 0) { + fprintf(log_get_logfd(), _("%s: Cannot change mode of %s: %s\n"), log_get_progname(), dir, strerrno()); goto out_free; } - if ( (shadowtcb_set_user (name) == SHADOWTCB_FAILURE) - || (shadowtcb_move (NULL, uid) == SHADOWTCB_FAILURE)) { + if ( (shadowtcb_set_user(name) == SHADOWTCB_FAILURE) + || (shadowtcb_move(NULL, uid) == SHADOWTCB_FAILURE)) { goto out_free; } ret = SHADOWTCB_SUCCESS; out_free: if (fd != -1) close(fd); - free (dir); - free (shadow); + free(dir); + free(shadow); return ret; } diff --git a/lib/tcbfuncs.h b/lib/tcbfuncs.h index 6324bc1c71..eefc25ac9d 100644 --- a/lib/tcbfuncs.h +++ b/lib/tcbfuncs.h @@ -8,10 +8,10 @@ typedef enum { SHADOWTCB_SUCCESS = 1 } shadowtcb_status; -extern shadowtcb_status shadowtcb_drop_priv (void); -extern shadowtcb_status shadowtcb_gain_priv (void); -extern shadowtcb_status shadowtcb_set_user (const char *name); -extern shadowtcb_status shadowtcb_remove (const char *name); +extern shadowtcb_status shadowtcb_drop_priv(void); +extern shadowtcb_status shadowtcb_gain_priv(void); +extern shadowtcb_status shadowtcb_set_user(const char *name); +extern shadowtcb_status shadowtcb_remove(const char *name); extern shadowtcb_status shadowtcb_move (/*@null@*/const char *user_newname, uid_t user_newid); extern shadowtcb_status shadowtcb_create (const char *name, uid_t uid); diff --git a/lib/ttytype.c b/lib/ttytype.c index e2a9c98f7d..9e7ceebae3 100644 --- a/lib/ttytype.c +++ b/lib/ttytype.c @@ -27,7 +27,7 @@ /* * ttytype - set ttytype from port to terminal type mapping database */ -void ttytype (const char *line) +void ttytype(const char *line) { FILE *fp; char buf[BUFSIZ]; @@ -35,18 +35,18 @@ void ttytype (const char *line) char type[1024] = ""; char port[1024]; - if (getenv ("TERM") != NULL) { + if (getenv("TERM") != NULL) { return; } - typefile = getdef_str ("TTYTYPE_FILE"); + typefile = getdef_str("TTYTYPE_FILE"); if (NULL == typefile) { return; } - fp = fopen (typefile, "r"); + fp = fopen(typefile, "r"); if (NULL == fp) { if (errno != ENOENT) - perror (typefile); + perror(typefile); return; } while (fgets_a(buf, fp) != NULL) { @@ -56,15 +56,15 @@ void ttytype (const char *line) stpsep(buf, "\n"); - if ( (sscanf (buf, "%1023s %1023s", type, port) == 2) + if ( (sscanf(buf, "%1023s %1023s", type, port) == 2) && streq(line, port)) { break; } } if ((feof(fp) == 0) && (ferror(fp) == 0) && !streq(type, "")) { - addenv ("TERM", type); + addenv("TERM", type); } - (void) fclose (fp); + (void) fclose(fp); } diff --git a/lib/typetraits.h b/lib/typetraits.h index fb3d970d97..a6d74fe428 100644 --- a/lib/typetraits.h +++ b/lib/typetraits.h @@ -13,12 +13,12 @@ #define is_unsigned(x) \ ( \ - (typeof(x)) -1 > 1 \ + (typeof (x)) -1 > 1 \ ) #define is_signed(x) \ ( \ - (typeof(x)) -1 < 1 \ + (typeof (x)) -1 < 1 \ ) @@ -50,13 +50,13 @@ #define is_same_typeof(a, b) \ ( \ - is_same_type(typeof(a), typeof(b)) \ + is_same_type(typeof (a), typeof (b)) \ ) #define QChar_of(s) typeof \ ( \ - _Generic(s, \ + _Generic (s, \ const char *: (const char){0}, \ const void *: (const char){0}, \ char *: (char){0}, \ diff --git a/lib/ulimit.c b/lib/ulimit.c index 541f45fd26..df450dedbd 100644 --- a/lib/ulimit.c +++ b/lib/ulimit.c @@ -15,14 +15,14 @@ #include #include "prototypes.h" -int set_filesize_limit (int blocks) +int set_filesize_limit(int blocks) { int ret = -1; struct rlimit rlimit_fsize; rlimit_fsize.rlim_cur = 512L * blocks; rlimit_fsize.rlim_max = rlimit_fsize.rlim_cur; - ret = setrlimit (RLIMIT_FSIZE, &rlimit_fsize); + ret = setrlimit(RLIMIT_FSIZE, &rlimit_fsize); return ret; } diff --git a/lib/user_busy.c b/lib/user_busy.c index c2a1829f8e..9162affb7d 100644 --- a/lib/user_busy.c +++ b/lib/user_busy.c @@ -36,16 +36,16 @@ #ifdef __linux__ -static int check_status (const char *name, const char *sname, uid_t uid); -static int user_busy_processes (const char *name, uid_t uid); +static int check_status(const char *name, const char *sname, uid_t uid); +static int user_busy_processes(const char *name, uid_t uid); #else /* !__linux__ */ -static int user_busy_utmp (const char *name); +static int user_busy_utmp(const char *name); #endif /* !__linux__ */ /* * user_busy - check if a user is currently running processes */ -int user_busy (const char *name, uid_t uid) +int user_busy(const char *name, uid_t uid) { /* There are no standard ways to get the list of processes. * An option could be to run an external tool (ps). @@ -56,7 +56,7 @@ int user_busy (const char *name, uid_t uid) #else /* !__linux__ */ /* 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); + return user_busy_utmp(name); #endif /* !__linux__ */ } @@ -76,11 +76,11 @@ user_busy_utmp(const char *name) if (!strneq_a(utent->ut_user, name)) continue; - if (kill (utent->ut_pid, 0) != 0) { + if (kill(utent->ut_pid, 0) != 0) { continue; } - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: user %s is currently logged in\n"), log_get_progname(), name); return 1; @@ -94,7 +94,7 @@ user_busy_utmp(const char *name) #ifdef __linux__ #ifdef ENABLE_SUBIDS #define in_parentuid_range(uid) ((uid) >= parentuid && (uid) < parentuid + range) -static int different_namespace (const char *sname) +static int different_namespace(const char *sname) { /* 41: /proc/xxxxxxxxxx/task/xxxxxxxxxx/ns/user + \0 */ char path[41]; @@ -116,7 +116,7 @@ static int different_namespace (const char *sname) #endif /* ENABLE_SUBIDS */ -static int check_status (const char *name, const char *sname, uid_t uid) +static int check_status(const char *name, const char *sname, uid_t uid) { /* 40: /proc/xxxxxxxxxx/task/xxxxxxxxxx/status + \0 */ char status[40]; @@ -158,11 +158,11 @@ static int check_status (const char *name, const char *sname, uid_t uid) return 0; } } - (void) fclose (sfile); + (void) fclose(sfile); return 0; } -static int user_busy_processes (const char *name, uid_t uid) +static int user_busy_processes(const char *name, uid_t uid) { DIR *proc; DIR *task_dir; @@ -217,7 +217,7 @@ static int user_busy_processes (const char *name, uid_t uid) /* Check if the process is in our chroot */ stprintf_a(root_path, "/proc/%lu/root", (unsigned long) pid); - if (stat (root_path, &sbroot_process) != 0) { + if (stat(root_path, &sbroot_process) != 0) { continue; } if ( (sbroot.st_dev != sbroot_process.st_dev) @@ -225,19 +225,19 @@ static int user_busy_processes (const char *name, uid_t uid) continue; } - if (check_status (name, tmp_d_name, uid) != 0) { - (void) closedir (proc); + if (check_status(name, tmp_d_name, uid) != 0) { + (void) closedir(proc); #ifdef ENABLE_SUBIDS sub_uid_close(true); #endif - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: user %s is currently used by process %d\n"), log_get_progname(), name, pid); return 1; } stprintf_a(task_path, "/proc/%lu/task", (unsigned long) pid); - task_dir = opendir (task_path); + task_dir = opendir(task_path); if (task_dir != NULL) { while (NULL != (ent = readdir(task_dir))) { pid_t tid; @@ -247,19 +247,19 @@ static int user_busy_processes (const char *name, uid_t uid) if (tid == pid) { continue; } - if (check_status (name, task_path+6, uid) != 0) { - (void) closedir (proc); - (void) closedir (task_dir); + if (check_status(name, task_path+6, uid) != 0) { + (void) closedir(proc); + (void) closedir(task_dir); #ifdef ENABLE_SUBIDS sub_uid_close(true); #endif - fprintf (log_get_logfd(), + fprintf(log_get_logfd(), _("%s: user %s is currently used by process %d\n"), log_get_progname(), name, pid); return 1; } } - (void) closedir (task_dir); + (void) closedir(task_dir); } else { /* Ignore errors. This is just a best effort */ } diff --git a/lib/utmp.c b/lib/utmp.c index dc9870a7cf..4e16014600 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -60,12 +60,12 @@ is_my_tty(const char tty[UTX_LINESIZE]) stpcpy(full_tty, ""); if (tty[0] != '/') - strcpy (full_tty, "/dev/"); + strcpy(full_tty, "/dev/"); strncat(full_tty, tty, UTX_LINESIZE); if (ttyname_ra(STDIN_FILENO, my_tty) != 0) { - (void) puts (_("Unable to determine your tty name.")); - exit (EXIT_FAILURE); + (void) puts(_("Unable to determine your tty name.")); + exit(EXIT_FAILURE); } return streq(full_tty, my_tty); @@ -89,7 +89,7 @@ failtmp(const char *username, const struct utmpx *failent) * in login.defs, don't do this. */ - ftmp = getdef_str ("FTMP_FILE"); + ftmp = getdef_str("FTMP_FILE"); if (NULL == ftmp) { return; } @@ -99,7 +99,7 @@ failtmp(const char *username, const struct utmpx *failent) * feature to be used. */ - fd = open (ftmp, O_WRONLY | O_APPEND); + fd = open(ftmp, O_WRONLY | O_APPEND); if (-1 == fd) { if (errno != ENOENT) { SYSLOG(LOG_WARN, @@ -113,11 +113,11 @@ failtmp(const char *username, const struct utmpx *failent) * Append the new failure record and close the log file. */ - if (write_full(fd, failent, sizeof(*failent)) == -1) { + if (write_full(fd, failent, sizeof (*failent)) == -1) { goto err_write; } - if (close (fd) != 0 && errno != EINTR) { + if (close(fd) != 0 && errno != EINTR) { goto err_close; } @@ -126,7 +126,7 @@ failtmp(const char *username, const struct utmpx *failent) err_write: { int saved_errno = errno; - (void) close (fd); + (void) close(fd); errno = saved_errno; } err_close: @@ -228,10 +228,10 @@ updwtmpx(const char *filename, const struct utmpx *ut) { int fd; - fd = open (filename, O_APPEND | O_WRONLY, 0); + fd = open(filename, O_APPEND | O_WRONLY, 0); if (fd >= 0) { - write_full(fd, ut, sizeof(*ut)); - close (fd); + write_full(fd, ut, sizeof (*ut)); + close(fd); } } #endif @@ -264,8 +264,8 @@ prepare_utmp(const char *name, const char *line, const char *host, struct utmpx *utent; struct timeval tv; - assert (NULL != name); - assert (NULL != line); + assert(NULL != name); + assert(NULL != line); @@ -301,10 +301,10 @@ prepare_utmp(const char *name, const char *line, const char *host, #endif #if defined(HAVE_STRUCT_UTMPX_UT_SYSLEN) utent->ut_syslen = MIN(strlen(hostname), - sizeof(utent->ut_host)); + sizeof (utent->ut_host)); #endif #if defined(HAVE_STRUCT_UTMPX_UT_ADDR) || defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6) - if (getaddrinfo (hostname, NULL, NULL, &info) == 0) { + if (getaddrinfo(hostname, NULL, NULL, &info) == 0) { /* getaddrinfo might not be reliable. * Just try to log what may be useful. */ @@ -319,16 +319,16 @@ prepare_utmp(const char *name, const char *line, const char *host, } else if (info->ai_family == AF_INET6) { struct sockaddr_in6 *sa = (struct sockaddr_in6 *) info->ai_addr; - memcpy (utent->ut_addr_v6, + memcpy(utent->ut_addr_v6, &(sa->sin6_addr), - MIN(sizeof(utent->ut_addr_v6), - sizeof(sa->sin6_addr))); + MIN(sizeof (utent->ut_addr_v6), + sizeof (sa->sin6_addr))); # endif } - freeaddrinfo (info); + freeaddrinfo(info); } #endif - free (hostname); + free(hostname); } /* ut_exit is only for DEAD_PROCESS */ utent->ut_session = getsid (0); @@ -357,7 +357,7 @@ setutmp(struct utmpx *ut) { int err = 0; - assert (NULL != ut); + assert(NULL != ut); setutxent(); if (pututxline(ut) == NULL) { @@ -398,13 +398,13 @@ record_failure(const char *failent_user, const char *tty, const char *hostname, { struct utmpx *utent, *failent; - if (getdef_str ("FTMP_FILE") != NULL) { + if (getdef_str("FTMP_FILE") != NULL) { utent = get_current_utmp(main_pid); failent = prepare_utmp(failent_user, tty, hostname, utent, main_pid); - failtmp (failent_user, failent); - free (utent); - free (failent); + failtmp(failent_user, failent); + free(utent); + free(failent); } } diff --git a/lib/valid.c b/lib/valid.c index 919a99bc33..b5427d8e7e 100644 --- a/lib/valid.c +++ b/lib/valid.c @@ -30,7 +30,7 @@ * is used to indicate that a dummy salt must be used to encrypt the * password anyway. */ -bool valid (const char *password, const struct passwd *ent) +bool valid(const char *password, const struct passwd *ent) { const char *encrypted; /*@observer@*/const char *salt; @@ -67,7 +67,7 @@ bool valid (const char *password, const struct passwd *ent) * looking at execution time. */ - encrypted = pw_encrypt (password, salt); + encrypted = pw_encrypt(password, salt); /* * One last time we must deal with there being no password file diff --git a/lib/xgetXXbyYY.c b/lib/xgetXXbyYY.c index 5890212072..012f66095d 100644 --- a/lib/xgetXXbyYY.c +++ b/lib/xgetXXbyYY.c @@ -113,8 +113,8 @@ #endif oom: - fprintf (log_get_logfd(), _("%s: out of memory\n"), + fprintf(log_get_logfd(), _("%s: out of memory\n"), "x" STRINGIZE(FUNCTION_NAME)); - exit (13); + exit(13); } diff --git a/src/chage.c b/src/chage.c index 8e27c5fd59..bcdfdf86b3 100644 --- a/src/chage.c +++ b/src/chage.c @@ -79,27 +79,27 @@ static long inactdays; static long expdate; /* local function prototypes */ -NORETURN static void usage (int status); -static int new_fields (void); -static void print_day_as_date (long day); -static void list_fields (void); -static void process_flags (int argc, char **argv, struct option_flags *flags); -static void check_flags (int argc, int opt_index); +NORETURN static void usage(int status); +static int new_fields(void); +static void print_day_as_date(long day); +static void list_fields(void); +static void process_flags(int argc, char **argv, struct option_flags *flags); +static void check_flags(int argc, int opt_index); static void check_perms(const struct option_flags *flags); static void open_files(bool readonly, const struct option_flags *flags); static void close_files(const struct option_flags *flags); -NORETURN static void fail_exit (int code, bool process_selinux); +NORETURN static void fail_exit(int code, bool process_selinux); /* * fail_exit - do some cleanup and exit with the given error code */ NORETURN static void -fail_exit (int code, bool process_selinux) +fail_exit(int code, bool process_selinux) { if (spw_locked) { - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); /* continue */ } @@ -111,16 +111,16 @@ fail_exit (int code, bool process_selinux) /* continue */ } } - closelog (); + closelog(); #ifdef WITH_AUDIT if (E_SUCCESS != code) { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "change-age", user_name, user_uid, SHADOW_AUDIT_FAILURE); } #endif - exit (code); + exit(code); } /* @@ -128,30 +128,30 @@ fail_exit (int code, bool process_selinux) */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] LOGIN\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -d, --lastday LAST_DAY set date of last password change to LAST_DAY\n"), usageout); - (void) fputs (_(" -E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -i, --iso8601 use YYYY-MM-DD when printing dates\n"), usageout); - (void) fputs (_(" -I, --inactive INACTIVE set password inactive after expiration\n" + (void) fputs(_(" -d, --lastday LAST_DAY set date of last password change to LAST_DAY\n"), usageout); + (void) fputs(_(" -E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -i, --iso8601 use YYYY-MM-DD when printing dates\n"), usageout); + (void) fputs(_(" -I, --inactive INACTIVE set password inactive after expiration\n" " to INACTIVE\n"), usageout); - (void) fputs (_(" -l, --list show account aging information\n"), usageout); - (void) fputs (_(" -m, --mindays MIN_DAYS set minimum number of days before password\n" + (void) fputs(_(" -l, --list show account aging information\n"), usageout); + (void) fputs(_(" -m, --mindays MIN_DAYS set minimum number of days before password\n" " change to MIN_DAYS\n"), usageout); - (void) fputs (_(" -M, --maxdays MAX_DAYS set maximum number of days before password\n" + (void) fputs(_(" -M, --maxdays MAX_DAYS set maximum number of days before password\n" " change to MAX_DAYS\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout); - (void) fputs (_(" -W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS\n"), usageout); - (void) fputs ("\n", usageout); - exit (status); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout); + (void) fputs(_(" -W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS\n"), usageout); + (void) fputs("\n", usageout); + exit(status); } /* @@ -163,20 +163,20 @@ usage (int status) * any other negative value is an error. very large positive values will * be handled elsewhere. */ -static int new_fields (void) +static int new_fields(void) { char buf[200]; - (void) puts (_("Enter the new value, or press ENTER for the default")); - (void) puts (""); + (void) puts(_("Enter the new value, or press ENTER for the default")); + (void) puts(""); stprintf_a(buf, "%ld", mindays); - change_field(buf, sizeof(buf), _("Minimum Password Age")); + change_field(buf, sizeof (buf), _("Minimum Password Age")); if (a2sl(&mindays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; stprintf_a(buf, "%ld", maxdays); - change_field(buf, sizeof(buf), _("Maximum Password Age")); + change_field(buf, sizeof (buf), _("Maximum Password Age")); if (a2sl(&maxdays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; @@ -185,24 +185,24 @@ static int new_fields (void) else day_to_str_a(buf, lstchgdate); - change_field(buf, sizeof(buf), _("Last Password Change (YYYY-MM-DD)")); + change_field(buf, sizeof (buf), _("Last Password Change(YYYY-MM-DD)")); if (streq(buf, "-1")) { lstchgdate = -1; } else { - lstchgdate = strtoday (buf); + lstchgdate = strtoday(buf); if (lstchgdate <= -1) { return 0; } } stprintf_a(buf, "%ld", warndays); - change_field(buf, sizeof(buf), _("Password Expiration Warning")); + change_field(buf, sizeof (buf), _("Password Expiration Warning")); if (a2sl(&warndays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; stprintf_a(buf, "%ld", inactdays); - change_field(buf, sizeof(buf), _("Password Inactive")); + change_field(buf, sizeof (buf), _("Password Inactive")); if (a2sl(&inactdays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; @@ -211,13 +211,13 @@ static int new_fields (void) else day_to_str_a(buf, expdate); - change_field(buf, sizeof(buf), - _("Account Expiration Date (YYYY-MM-DD)")); + change_field(buf, sizeof (buf), + _("Account Expiration Date(YYYY-MM-DD)")); if (streq(buf, "-1")) { expdate = -1; } else { - expdate = strtoday (buf); + expdate = strtoday(buf); if (expdate <= -1) { return 0; } @@ -253,7 +253,7 @@ print_day_as_date(long day) return; } - (void) puts (buf); + (void) puts(buf); } @@ -264,15 +264,15 @@ print_day_as_date(long day) * values will be displayed as a calendar date, or the word "never" if * the date is 1/1/70, which is day number 0. */ -static void list_fields (void) +static void list_fields(void) { /* * The "last change" date is either "never" or the date the password * was last modified. The date is the number of days since 1/1/1970. */ - (void) fputs (_("Last password change\t\t\t\t\t: "), stdout); + (void) fputs(_("Last password change\t\t\t\t\t: "), stdout); if (lstchgdate == 0) { - (void) puts (_("password must be changed")); + (void) puts(_("password must be changed")); } else { print_day_as_date(lstchgdate); } @@ -281,14 +281,14 @@ static void list_fields (void) * The password expiration date is determined from the last change * date plus the number of days the password is valid for. */ - (void) fputs (_("Password expires\t\t\t\t\t: "), stdout); + (void) fputs(_("Password expires\t\t\t\t\t: "), stdout); if (lstchgdate == 0) { - (void) puts (_("password must be changed")); + (void) puts(_("password must be changed")); } else if ( (lstchgdate < 0) || (maxdays < 0) || (LONG_MAX - lstchgdate < maxdays)) { - (void) puts (_("never")); + (void) puts(_("never")); } else { print_day_as_date(lstchgdate + maxdays); } @@ -299,16 +299,16 @@ static void list_fields (void) * number of inactive days is added. The resulting date is when the * active will be disabled. */ - (void) fputs (_("Password inactive\t\t\t\t\t: "), stdout); + (void) fputs(_("Password inactive\t\t\t\t\t: "), stdout); if (lstchgdate == 0) { - (void) puts (_("password must be changed")); + (void) puts(_("password must be changed")); } else if ( (lstchgdate < 0) || (inactdays < 0) || (maxdays < 0) || (LONG_MAX - inactdays < maxdays) || (LONG_MAX - lstchgdate < maxdays + inactdays)) { - (void) puts (_("never")); + (void) puts(_("never")); } else { print_day_as_date(lstchgdate + maxdays + inactdays); } @@ -317,7 +317,7 @@ static void list_fields (void) * The account will expire on the given date regardless of the * password expiring or not. */ - (void) fputs (_("Account expires\t\t\t\t\t\t: "), stdout); + (void) fputs(_("Account expires\t\t\t\t\t\t: "), stdout); print_day_as_date(expdate); /* @@ -327,11 +327,11 @@ static void list_fields (void) * expires that the user is told, and the number of days after the * password expires that the account becomes unusable. */ - printf (_("Minimum number of days between password change\t\t: %ld\n"), + printf(_("Minimum number of days between password change\t\t: %ld\n"), mindays); - printf (_("Maximum number of days between password change\t\t: %ld\n"), + printf(_("Maximum number of days between password change\t\t: %ld\n"), maxdays); - printf (_("Number of days of warning before password expires\t: %ld\n"), + printf(_("Number of days of warning before password expires\t: %ld\n"), warndays); } @@ -340,7 +340,7 @@ static void list_fields (void) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { /* * Parse the command line options. @@ -361,31 +361,31 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "d:E:hiI:lm:M:R:P:W:", + while ((c = getopt_long(argc, argv, "d:E:hiI:lm:M:R:P:W:", long_options, NULL)) != -1) { switch (c) { case 'd': dflg = true; - lstchgdate = strtoday (optarg); + lstchgdate = strtoday(optarg); if (lstchgdate < -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid date '%s'\n"), Prog, optarg); - usage (E_USAGE); + usage(E_USAGE); } break; case 'E': Eflg = true; - expdate = strtoday (optarg); + expdate = strtoday(optarg); if (expdate < -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid date '%s'\n"), Prog, optarg); - usage (E_USAGE); + usage(E_USAGE); } break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'i': iflg = true; @@ -448,7 +448,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * * It will not return if an error is encountered. */ -static void check_flags (int argc, int opt_index) +static void check_flags(int argc, int opt_index) { /* * Make certain the flags do not conflict and that there is a user @@ -456,14 +456,14 @@ static void check_flags (int argc, int opt_index) */ if (argc != opt_index + 1) { - usage (E_USAGE); + usage(E_USAGE); } if (lflg && (mflg || Mflg || dflg || Wflg || Iflg || Eflg)) { - fprintf (stderr, + fprintf(stderr, _("%s: do not include \"l\" with other flags\n"), Prog); - usage (E_USAGE); + usage(E_USAGE); } } @@ -489,8 +489,8 @@ static void check_perms(const struct option_flags *flags) */ if (!amroot && !lflg) { - fprintf (stderr, _("%s: Permission denied.\n"), Prog); - fail_exit (E_NOPERM, process_selinux); + fprintf(stderr, _("%s: Permission denied.\n"), Prog); + fail_exit(E_NOPERM, process_selinux); } } @@ -512,18 +512,18 @@ static void open_files(bool readonly, const struct option_flags *flags) * file entry for the requested user. */ if (!readonly) { - if (pw_lock () == 0) { - fprintf (stderr, + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - fail_exit (E_NOPERM, process_selinux); + Prog, pw_dbname()); + fail_exit(E_NOPERM, process_selinux); } pw_locked = true; } - if (pw_open (readonly ? O_RDONLY: O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ()); + if (pw_open(readonly ? O_RDONLY: O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, pw_dbname()); SYSLOG(LOG_WARN, "cannot open %s", pw_dbname()); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } /* @@ -533,19 +533,19 @@ static void open_files(bool readonly, const struct option_flags *flags) * for this user if one does not exist already. */ if (!readonly) { - if (spw_lock () == 0) { - fprintf (stderr, + if (spw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, spw_dbname ()); - fail_exit (E_NOPERM, process_selinux); + Prog, spw_dbname()); + fail_exit(E_NOPERM, process_selinux); } spw_locked = true; } - if (spw_open (readonly ? O_RDONLY: O_CREAT | O_RDWR) == 0) { - fprintf (stderr, - _("%s: cannot open %s\n"), Prog, spw_dbname ()); + if (spw_open(readonly ? O_RDONLY: O_CREAT | O_RDWR) == 0) { + fprintf(stderr, + _("%s: cannot open %s\n"), Prog, spw_dbname()); SYSLOG(LOG_WARN, "cannot open %s", spw_dbname()); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } } @@ -562,24 +562,24 @@ static void close_files(const struct option_flags *flags) * Now close the shadow password file, which will cause all of the * entries to be re-written. */ - if (spw_close (process_selinux) == 0) { - fprintf (stderr, - _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ()); + if (spw_close(process_selinux) == 0) { + fprintf(stderr, + _("%s: failure while writing changes to %s\n"), Prog, spw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", spw_dbname()); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } /* * Close the password file. If any entries were modified, the file * will be re-written. */ - if (pw_close (process_selinux) == 0) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); + if (pw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", pw_dbname()); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); /* continue */ } @@ -611,7 +611,7 @@ static void update_age (/*@null@*/const struct spwd *sp, if (NULL == sp) { struct passwd pwent = *pw; - memzero(&spwent, sizeof(spwent)); + memzero(&spwent, sizeof (spwent)); spwent.sp_namp = pwent.pw_name; spwent.sp_pwdp = pwent.pw_passwd; spwent.sp_flag = SHADOW_SP_FLAG_UNSET; @@ -640,10 +640,10 @@ static void update_age (/*@null@*/const struct spwd *sp, spwent.sp_inact = inactdays; spwent.sp_expire = expdate; - if (spw_update (&spwent) == 0) { - fprintf (stderr, - _("%s: failed to prepare the new %s entry '%s'\n"), Prog, spw_dbname (), spwent.sp_namp); - fail_exit (E_NOPERM, process_selinux); + if (spw_update(&spwent) == 0) { + fprintf(stderr, + _("%s: failed to prepare the new %s entry '%s'\n"), Prog, spw_dbname(), spwent.sp_namp); + fail_exit(E_NOPERM, process_selinux); } } @@ -723,7 +723,7 @@ static void get_defaults (/*@null@*/const struct spwd *sp) * either seconds or days. */ -int main (int argc, char **argv) +int main(int argc, char **argv) { const struct spwd *sp; uid_t ruid; @@ -732,48 +732,48 @@ int main (int argc, char **argv) struct option_flags flags = {.chroot = false, .prefix = false}; bool process_selinux; - sanitize_env (); - check_fds (); + sanitize_env(); + check_fds(); log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); - prefix = process_prefix_flag ("-P", argc, argv); + process_root_flag("-R", argc, argv); + prefix = process_prefix_flag("-P", argc, argv); #ifdef WITH_AUDIT - audit_help_open (); + audit_help_open(); #endif - OPENLOG (Prog); + OPENLOG(Prog); - ruid = getuid (); - rgid = getgid (); + ruid = getuid(); + rgid = getgid(); amroot = (ruid == 0); #ifdef WITH_SELINUX if (amroot) { - amroot = (check_selinux_permit ("rootok") == 0); + amroot = (check_selinux_permit("rootok") == 0); } #endif - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); process_selinux = !flags.chroot && !flags.prefix; - check_perms (&flags); + check_perms(&flags); - if (!spw_file_present ()) { - fprintf (stderr, + if (!spw_file_present()) { + fprintf(stderr, _("%s: the shadow password file is not present\n"), Prog); SYSLOG(LOG_WARN, "can't find the shadow password file"); - closelog (); - exit (E_SHADOW_NOTFOUND); + closelog(); + exit(E_SHADOW_NOTFOUND); } - open_files (lflg, &flags); + open_files(lflg, &flags); /* Drop privileges */ if (lflg && ( (setregid (rgid, rgid) != 0) || (setreuid (ruid, ruid) != 0))) { @@ -807,8 +807,8 @@ int main (int argc, char **argv) */ if (lflg) { if (!amroot && (ruid != user_uid)) { - fprintf (stderr, _("%s: Permission denied.\n"), Prog); - fail_exit (E_NOPERM, process_selinux); + fprintf(stderr, _("%s: Permission denied.\n"), Prog); + fail_exit(E_NOPERM, process_selinux); } /* Displaying fields is not of interest to audit */ list_fields (); @@ -820,16 +820,16 @@ int main (int argc, char **argv) * user interactively change them. */ if (!mflg && !Mflg && !dflg && !Wflg && !Iflg && !Eflg) { - printf (_("Changing the aging information for %s\n"), + printf(_("Changing the aging information for %s\n"), user_name); - if (new_fields () == 0) { - fprintf (stderr, _("%s: error changing fields\n"), + if (new_fields() == 0) { + fprintf(stderr, _("%s: error changing fields\n"), Prog); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } #ifdef WITH_AUDIT else { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "change-all-aging-information", user_name, user_uid, SHADOW_AUDIT_SUCCESS); } @@ -837,43 +837,43 @@ int main (int argc, char **argv) } else { #ifdef WITH_AUDIT if (Mflg) { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "change-max-age", user_name, user_uid, SHADOW_AUDIT_SUCCESS); } if (mflg) { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "change-min-age", user_name, user_uid, 1); } if (dflg) { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "change-last-change-date", user_name, user_uid, 1); } if (Wflg) { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "change-passwd-warning", user_name, user_uid, 1); } if (Iflg) { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "change-inactive-days", user_name, user_uid, 1); } if (Eflg) { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "change-passwd-expiration", user_name, user_uid, 1); } #endif } - update_age (sp, pw, process_selinux); + update_age(sp, pw, process_selinux); - close_files (&flags); + close_files(&flags); SYSLOG(LOG_INFO, "changed password expiry for %s", user_name); - closelog (); - exit (E_SUCCESS); + closelog(); + exit(E_SUCCESS); } diff --git a/src/chfn.c b/src/chfn.c index 28117655f0..e1bf7dcf7b 100644 --- a/src/chfn.c +++ b/src/chfn.c @@ -79,11 +79,11 @@ static void get_old_fields (const char *gecos); /* * fail_exit - exit with an error and do some cleanup */ -static void fail_exit (int code, bool process_selinux) +static void fail_exit(int code, bool process_selinux) { if (pw_locked) { - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -100,23 +100,23 @@ static void fail_exit (int code, bool process_selinux) */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] [LOGIN]\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -f, --full-name FULL_NAME change user's full name\n"), usageout); - (void) fputs (_(" -h, --home-phone HOME_PHONE change user's home phone number\n"), usageout); - (void) fputs (_(" -o, --other OTHER_INFO change user's other GECOS information\n"), usageout); - (void) fputs (_(" -r, --room ROOM_NUMBER change user's room number\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -u, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -w, --work-phone WORK_PHONE change user's office phone number\n"), usageout); - (void) fputs ("\n", usageout); - exit (status); + (void) fputs(_(" -f, --full-name FULL_NAME change user's full name\n"), usageout); + (void) fputs(_(" -h, --home-phone HOME_PHONE change user's home phone number\n"), usageout); + (void) fputs(_(" -o, --other OTHER_INFO change user's other GECOS information\n"), usageout); + (void) fputs(_(" -r, --room ROOM_NUMBER change user's room number\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -u, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -w, --work-phone WORK_PHONE change user's office phone number\n"), usageout); + (void) fputs("\n", usageout); + exit(status); } /* @@ -129,7 +129,7 @@ usage (int status) * * Return true if the user can change the field and false otherwise. */ -static bool may_change_field (int field) +static bool may_change_field(int field) { const char *cp; @@ -154,7 +154,7 @@ static bool may_change_field (int field) return true; } - cp = getdef_str ("CHFN_RESTRICT"); + cp = getdef_str("CHFN_RESTRICT"); if (NULL == cp) { cp = ""; } else if (streq(cp, "yes")) { @@ -175,36 +175,36 @@ static bool may_change_field (int field) * prompt the user for each of the four fields and fill in the fields from * the user's response, or leave alone if nothing was entered. */ -static void new_fields (void) +static void new_fields(void) { - puts (_("Enter the new value, or press ENTER for the default")); + puts(_("Enter the new value, or press ENTER for the default")); - if (may_change_field ('f')) { - change_field(fullnm, sizeof(fullnm), _("Full Name")); + if (may_change_field('f')) { + change_field(fullnm, sizeof (fullnm), _("Full Name")); } else { - printf (_("\t%s: %s\n"), _("Full Name"), fullnm); + printf(_("\t%s: %s\n"), _("Full Name"), fullnm); } - if (may_change_field ('r')) { - change_field(roomno, sizeof(roomno), _("Room Number")); + if (may_change_field('r')) { + change_field(roomno, sizeof (roomno), _("Room Number")); } else { - printf (_("\t%s: %s\n"), _("Room Number"), roomno); + printf(_("\t%s: %s\n"), _("Room Number"), roomno); } - if (may_change_field ('w')) { - change_field(workph, sizeof(workph), _("Work Phone")); + if (may_change_field('w')) { + change_field(workph, sizeof (workph), _("Work Phone")); } else { - printf (_("\t%s: %s\n"), _("Work Phone"), workph); + printf(_("\t%s: %s\n"), _("Work Phone"), workph); } - if (may_change_field ('h')) { - change_field(homeph, sizeof(homeph), _("Home Phone")); + if (may_change_field('h')) { + change_field(homeph, sizeof (homeph), _("Home Phone")); } else { - printf (_("\t%s: %s\n"), _("Home Phone"), homeph); + printf(_("\t%s: %s\n"), _("Home Phone"), homeph); } if (amroot) { - change_field(slop, sizeof(slop), _("Other")); + change_field(slop, sizeof (slop), _("Other")); } } @@ -213,7 +213,7 @@ static void new_fields (void) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { int c; /* flag currently being processed */ static struct option long_options[] = { @@ -234,46 +234,46 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * environment and must agree with the real UID. Also, the UID will * be checked for any commands which are restricted to root only. */ - while ((c = getopt_long (argc, argv, "f:h:o:r:R:uw:", + while ((c = getopt_long(argc, argv, "f:h:o:r:R:uw:", long_options, NULL)) != -1) { switch (c) { case 'f': - if (!may_change_field ('f')) { - fprintf (stderr, + if (!may_change_field('f')) { + fprintf(stderr, _("%s: Permission denied.\n"), Prog); - exit (E_NOPERM); + exit(E_NOPERM); } fflg = true; strtcpy_a(fullnm, optarg); break; case 'h': - if (!may_change_field ('h')) { - fprintf (stderr, + if (!may_change_field('h')) { + fprintf(stderr, _("%s: Permission denied.\n"), Prog); - exit (E_NOPERM); + exit(E_NOPERM); } hflg = true; strtcpy_a(homeph, optarg); break; case 'o': if (!amroot) { - fprintf (stderr, + fprintf(stderr, _("%s: Permission denied.\n"), Prog); - exit (E_NOPERM); + exit(E_NOPERM); } oflg = true; - if (strlen (optarg) > (unsigned int) 80) { - fprintf (stderr, + if (strlen(optarg) > (unsigned int) 80) { + fprintf(stderr, _("%s: fields too long\n"), Prog); - exit (E_NOPERM); + exit(E_NOPERM); } strtcpy_a(slop, optarg); break; case 'r': - if (!may_change_field ('r')) { - fprintf (stderr, + if (!may_change_field('r')) { + fprintf(stderr, _("%s: Permission denied.\n"), Prog); - exit (E_NOPERM); + exit(E_NOPERM); } rflg = true; strtcpy_a(roomno, optarg); @@ -285,16 +285,16 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) usage (E_SUCCESS); /*@notreached@*/break; case 'w': - if (!may_change_field ('w')) { - fprintf (stderr, + if (!may_change_field('w')) { + fprintf(stderr, _("%s: Permission denied.\n"), Prog); - exit (E_NOPERM); + exit(E_NOPERM); } wflg = true; strtcpy_a(workph, optarg); break; default: - usage (E_USAGE); + usage(E_USAGE); } } } @@ -309,7 +309,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * * It will not return if the user is not allowed. */ -static void check_perms (const struct passwd *pw) +static void check_perms(const struct passwd *pw) { #ifdef USE_PAM pam_handle_t *pamh = NULL; @@ -321,21 +321,21 @@ static void check_perms (const struct passwd *pw) * Non-privileged users are only allowed to change the gecos field * if the UID of the user matches the current real UID. */ - if (!amroot && pw->pw_uid != getuid ()) { - fprintf (stderr, _("%s: Permission denied.\n"), Prog); - closelog (); - exit (E_NOPERM); + if (!amroot && pw->pw_uid != getuid()) { + fprintf(stderr, _("%s: Permission denied.\n"), Prog); + closelog(); + exit(E_NOPERM); } #ifdef WITH_SELINUX /* * If the UID of the user does not match the current real UID, * check if the change is allowed by SELinux policy. */ - if ((pw->pw_uid != getuid ()) - && (check_selinux_permit (Prog) != 0)) { - fprintf (stderr, _("%s: Permission denied.\n"), Prog); - closelog (); - exit (E_NOPERM); + if ((pw->pw_uid != getuid()) + && (check_selinux_permit(Prog) != 0)) { + fprintf(stderr, _("%s: Permission denied.\n"), Prog); + closelog(); + exit(E_NOPERM); } #endif @@ -346,7 +346,7 @@ static void check_perms (const struct passwd *pw) * any changes can be made. Idea from util-linux chfn/chsh. * --marekm */ - if (!amroot && getdef_bool ("CHFN_AUTH")) { + if (!amroot && getdef_bool("CHFN_AUTH")) { passwd_check(pw->pw_name, pw->pw_passwd); } @@ -401,28 +401,28 @@ static void update_gecos(const char *user, char *gecos, const struct option_flag * against unexpected signals. Any keyboard signals are set to be * ignored. */ - if (setuid (0) != 0) { - fputs (_("Cannot change ID to root.\n"), stderr); + if (setuid(0) != 0) { + fputs(_("Cannot change ID to root.\n"), stderr); SYSLOG(LOG_ERR, "can't setuid(0)"); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } - pwd_init (); + pwd_init(); /* * The passwd entry is now ready to be committed back to the * password file. Get a lock on the file and open it. */ - if (pw_lock () == 0) { - fprintf (stderr, + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - fail_exit (E_NOPERM, process_selinux); + Prog, pw_dbname()); + fail_exit(E_NOPERM, process_selinux); } pw_locked = true; - if (pw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, - _("%s: cannot open %s\n"), Prog, pw_dbname ()); - fail_exit (E_NOPERM, process_selinux); + if (pw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, + _("%s: cannot open %s\n"), Prog, pw_dbname()); + fail_exit(E_NOPERM, process_selinux); } /* @@ -431,12 +431,12 @@ static void update_gecos(const char *user, char *gecos, const struct option_flag * the shadow password if (despite the warnings) someone enables * AUTOSHADOW (or SHADOW_COMPAT in libc). --marekm */ - pw = pw_locate (user); + pw = pw_locate(user); if (NULL == pw) { - fprintf (stderr, + fprintf(stderr, _("%s: user '%s' does not exist in %s\n"), - Prog, user, pw_dbname ()); - fail_exit (E_NOPERM, process_selinux); + Prog, user, pw_dbname()); + fail_exit(E_NOPERM, process_selinux); } /* @@ -450,23 +450,23 @@ static void update_gecos(const char *user, char *gecos, const struct option_flag * Update the passwd file entry. If there is a DBM file, update that * entry as well. */ - if (pw_update (&pwent) == 0) { - fprintf (stderr, + if (pw_update(&pwent) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, pw_dbname (), pwent.pw_name); - fail_exit (E_NOPERM, process_selinux); + Prog, pw_dbname(), pwent.pw_name); + fail_exit(E_NOPERM, process_selinux); } /* * Changes have all been made, so commit them and unlock the file. */ - if (pw_close (process_selinux) == 0) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); + if (pw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", pw_dbname()); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -477,7 +477,7 @@ static void update_gecos(const char *user, char *gecos, const struct option_flag * get_old_fields - parse the old gecos and use the old value for the fields * which are not set on the command line */ -static void get_old_fields (const char *gecos) +static void get_old_fields(const char *gecos) { char *p; char old_gecos[BUFSIZ]; @@ -512,42 +512,42 @@ static void get_old_fields (const char *gecos) * * It will not return if a field is not valid. */ -static void check_fields (bool process_selinux) +static void check_fields(bool process_selinux) { int err; - err = valid_field (fullnm, ":,=\n"); + err = valid_field(fullnm, ":,=\n"); if (err > 0) { - fprintf (stderr, _("%s: name with non-ASCII characters: '%s'\n"), Prog, fullnm); + fprintf(stderr, _("%s: name with non-ASCII characters: '%s'\n"), Prog, fullnm); } else if (err < 0) { - fprintf (stderr, _("%s: invalid name: '%s'\n"), Prog, fullnm); - fail_exit (E_NOPERM, process_selinux); + fprintf(stderr, _("%s: invalid name: '%s'\n"), Prog, fullnm); + fail_exit(E_NOPERM, process_selinux); } - err = valid_field (roomno, ":,=\n"); + err = valid_field(roomno, ":,=\n"); if (err > 0) { - fprintf (stderr, _("%s: room number with non-ASCII characters: '%s'\n"), Prog, roomno); + fprintf(stderr, _("%s: room number with non-ASCII characters: '%s'\n"), Prog, roomno); } else if (err < 0) { - fprintf (stderr, _("%s: invalid room number: '%s'\n"), + fprintf(stderr, _("%s: invalid room number: '%s'\n"), Prog, roomno); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } - if (valid_field (workph, ":,=\n") != 0) { - fprintf (stderr, _("%s: invalid work phone: '%s'\n"), + if (valid_field(workph, ":,=\n") != 0) { + fprintf(stderr, _("%s: invalid work phone: '%s'\n"), Prog, workph); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } - if (valid_field (homeph, ":,=\n") != 0) { - fprintf (stderr, _("%s: invalid home phone: '%s'\n"), + if (valid_field(homeph, ":,=\n") != 0) { + fprintf(stderr, _("%s: invalid home phone: '%s'\n"), Prog, homeph); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } - err = valid_field (slop, ":\n"); + err = valid_field(slop, ":\n"); if (err > 0) { - fprintf (stderr, _("%s: '%s' contains non-ASCII characters\n"), Prog, slop); + fprintf(stderr, _("%s: '%s' contains non-ASCII characters\n"), Prog, slop); } else if (err < 0) { - fprintf (stderr, + fprintf(stderr, _("%s: '%s' contains illegal characters\n"), Prog, slop); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } } @@ -567,7 +567,7 @@ static void check_fields (bool process_selinux) * * (*) requires root permission to execute. */ -int main (int argc, char **argv) +int main(int argc, char **argv) { char new_gecos[80]; char *user, *p, *e; @@ -575,25 +575,25 @@ int main (int argc, char **argv) struct option_flags flags = {.chroot = false}; bool process_selinux; - sanitize_env (); - check_fds (); + sanitize_env(); + check_fds(); log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); /* * This command behaves different for root and non-root * users. */ - amroot = (getuid () == 0); + amroot = (getuid() == 0); - OPENLOG (Prog); + OPENLOG(Prog); /* parse the command line options */ process_flags (argc, argv, &flags); @@ -604,51 +604,51 @@ int main (int argc, char **argv) * name, or the name getlogin() returns. */ if (optind < argc) { - if (!is_valid_user_name (argv[optind])) { - fprintf (stderr, _("%s: Provided user name is not a valid name\n"), Prog); - fail_exit (E_NOPERM, process_selinux); + if (!is_valid_user_name(argv[optind])) { + fprintf(stderr, _("%s: Provided user name is not a valid name\n"), Prog); + fail_exit(E_NOPERM, process_selinux); } user = argv[optind]; - pw = xgetpwnam (user); + pw = xgetpwnam(user); if (NULL == pw) { - fprintf (stderr, _("%s: user '%s' does not exist\n"), Prog, + fprintf(stderr, _("%s: user '%s' does not exist\n"), Prog, user); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } } else { - pw = get_my_pwent (); + pw = get_my_pwent(); if (NULL == pw) { - fprintf (stderr, + fprintf(stderr, _("%s: Cannot determine your user name.\n"), Prog); - SYSLOG(LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", + SYSLOG(LOG_WARN, "Cannot determine the user name of the caller(UID %lu)", (unsigned long) getuid()); - fail_exit (E_NOPERM, process_selinux); + fail_exit(E_NOPERM, process_selinux); } - user = xstrdup (pw->pw_name); + user = xstrdup(pw->pw_name); } /* Check that the caller is allowed to change the gecos of the * specified user */ - check_perms (pw); + check_perms(pw); /* If some fields were not set on the command line, load the value from * the old gecos fields. */ - get_old_fields (pw->pw_gecos); + get_old_fields(pw->pw_gecos); /* * If none of the fields were changed from the command line, let the * user interactively change them. */ if (!fflg && !rflg && !wflg && !hflg && !oflg) { - printf (_("Changing the user information for %s\n"), user); - new_fields (); + printf(_("Changing the user information for %s\n"), user); + new_fields(); } /* * Check all of the fields for valid information */ - check_fields (process_selinux); + check_fields(process_selinux); /* Build the new GECOS field by plastering all the pieces together. */ p = new_gecos; @@ -666,14 +666,14 @@ int main (int argc, char **argv) } /* Rewrite the user's gecos in the passwd file */ - update_gecos (user, new_gecos, &flags); + update_gecos(user, new_gecos, &flags); SYSLOG(LOG_INFO, "changed user '%s' information", user); - nscd_flush_cache ("passwd"); - sssd_flush_cache (SSSD_DB_PASSWD); + nscd_flush_cache("passwd"); + sssd_flush_cache(SSSD_DB_PASSWD); - closelog (); - exit (E_SUCCESS); + closelog(); + exit(E_SUCCESS); } diff --git a/src/chgpasswd.c b/src/chgpasswd.c index e77ecc6ac7..5469b86609 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -67,21 +67,21 @@ static bool sgr_locked = false; static bool gr_locked = false; /* local function prototypes */ -NORETURN static void fail_exit (int code, bool process_selinux); -NORETURN static void usage (int status); -static void process_flags (int argc, char **argv, struct option_flags *flags); -static void check_flags (void); -static void open_files (bool process_selinux); +NORETURN static void fail_exit(int code, bool process_selinux); +NORETURN static void usage(int status); +static void process_flags(int argc, char **argv, struct option_flags *flags); +static void check_flags(void); +static void open_files(bool process_selinux); static void close_files(const struct option_flags *flags); /* * fail_exit - exit with a failure code after unlocking the files */ -static void fail_exit (int code, bool process_selinux) +static void fail_exit(int code, bool process_selinux) { if (gr_locked) { - if (gr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + if (gr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", gr_dbname()); /* continue */ } @@ -97,7 +97,7 @@ static void fail_exit (int code, bool process_selinux) } #endif - exit (code); + exit(code); } /* @@ -105,16 +105,16 @@ static void fail_exit (int code, bool process_selinux) */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options]\n" "\n" "Options:\n"), Prog); - (void) fprintf (usageout, - _(" -c, --crypt-method METHOD the crypt method (one of %s)\n"), + (void) fprintf(usageout, + _(" -c, --crypt-method METHOD the crypt method(one of %s)\n"), "NONE DES MD5" " SHA256 SHA512" #if defined(USE_BCRYPT) @@ -124,15 +124,15 @@ usage (int status) " YESCRYPT" #endif ); - (void) fputs (_(" -e, --encrypted supplied passwords are encrypted\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -s, --sha-rounds number of rounds for the SHA, BCRYPT\n" + (void) fputs(_(" -e, --encrypted supplied passwords are encrypted\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -s, --sha-rounds number of rounds for the SHA, BCRYPT\n" " or YESCRYPT crypt algorithms\n"), usageout); - (void) fputs ("\n", usageout); + (void) fputs("\n", usageout); - exit (status); + exit(status); } /* @@ -140,7 +140,7 @@ usage (int status) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { int c; int bad_s; @@ -162,7 +162,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) eflg = true; break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ flags->chroot = true; @@ -172,10 +172,10 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) bad_s = 0; if (!crypt_method) { - fprintf (stderr, + fprintf(stderr, _("%s: no crypt method defined\n"), Prog); - usage (E_USAGE); + usage(E_USAGE); } if ( ( (streq(crypt_method, "SHA256") || streq(crypt_method, "SHA512")) && (-1 == str2sl(&sha_rounds, optarg)))) { @@ -194,20 +194,20 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) } #endif /* USE_YESCRYPT */ if (bad_s != 0) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); - usage (E_USAGE); + usage(E_USAGE); } break; default: - usage (E_USAGE); + usage(E_USAGE); /*@notreached@*/break; } } /* validate options */ - check_flags (); + check_flags(); } /* @@ -215,20 +215,20 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * * It will not return if an error is encountered. */ -static void check_flags (void) +static void check_flags(void) { if (sflg && !cflg) { - fprintf (stderr, + fprintf(stderr, _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-s", "-c"); - usage (E_USAGE); + usage(E_USAGE); } if (eflg && cflg) { - fprintf (stderr, + fprintf(stderr, _("%s: the -c and -e flags are exclusive\n"), Prog); - usage (E_USAGE); + usage(E_USAGE); } if (cflg) { @@ -244,10 +244,10 @@ static void check_flags (void) && !streq(crypt_method, "YESCRYPT") #endif /* USE_YESCRYPT */ ) { - fprintf (stderr, + fprintf(stderr, _("%s: unsupported crypt method: %s\n"), Prog, crypt_method); - usage (E_USAGE); + usage(E_USAGE); } } } @@ -255,23 +255,23 @@ static void check_flags (void) /* * open_files - lock and open the group databases */ -static void open_files (bool process_selinux) +static void open_files(bool process_selinux) { /* * Lock the group file and open it for reading and writing. This will * bring all of the entries into memory where they may be updated. */ - if (gr_lock () == 0) { - fprintf (stderr, + if (gr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, gr_dbname ()); - fail_exit (1, process_selinux); + Prog, gr_dbname()); + fail_exit(1, process_selinux); } gr_locked = true; - if (gr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, - _("%s: cannot open %s\n"), Prog, gr_dbname ()); - fail_exit (1, process_selinux); + if (gr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, + _("%s: cannot open %s\n"), Prog, gr_dbname()); + fail_exit(1, process_selinux); } #ifdef SHADOWGRP @@ -303,15 +303,15 @@ static void close_files(const struct option_flags *flags) process_selinux = !flags->chroot; #ifdef SHADOWGRP if (is_shadow_grp) { - if (sgr_close (process_selinux) == 0) { - fprintf (stderr, + if (sgr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, sgr_dbname ()); + Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", sgr_dbname()); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } - if (sgr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + if (sgr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sgr_dbname()); /* continue */ } @@ -334,7 +334,7 @@ static void close_files(const struct option_flags *flags) gr_locked = false; } -int main (int argc, char **argv) +int main(int argc, char **argv) { char buf[BUFSIZ]; char *name; @@ -356,28 +356,28 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); #ifdef WITH_SELINUX - if (check_selinux_permit ("passwd") != 0) { + if (check_selinux_permit("passwd") != 0) { return (E_NOPERM); } #endif /* WITH_SELINUX */ - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); process_selinux = !flags.chroot; - OPENLOG (Prog); + OPENLOG(Prog); #ifdef SHADOWGRP - is_shadow_grp = sgr_file_present (); + is_shadow_grp = sgr_file_present(); #endif - open_files (process_selinux); + open_files(process_selinux); /* * Read each line, separating the group name from the password. The @@ -387,7 +387,7 @@ int main (int argc, char **argv) while (fgets_a(buf, stdin) != NULL) { line++; if (stpsep(buf, "\n") == NULL) { - fprintf (stderr, _("%s: line %jd: line too long\n"), + fprintf(stderr, _("%s: line %jd: line too long\n"), Prog, line); errors = true; continue; @@ -405,7 +405,7 @@ int main (int argc, char **argv) name = buf; cp = stpsep(name, ":"); if (cp == NULL) { - fprintf (stderr, + fprintf(stderr, _("%s: line %jd: missing new password\n"), Prog, line); errors = true; @@ -433,13 +433,13 @@ int main (int argc, char **argv) } #endif /* USE_YESCRYPT */ } - salt = crypt_make_salt (crypt_method, arg); - cp = pw_encrypt (newpwd, salt); + salt = crypt_make_salt(crypt_method, arg); + cp = pw_encrypt(newpwd, salt); if (NULL == cp) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to crypt password with salt '%s': %s\n"), Prog, salt, strerrno()); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } } @@ -447,9 +447,9 @@ int main (int argc, char **argv) * Get the group file entry for this group. The group must * already exist. */ - gr = gr_locate (name); + gr = gr_locate(name); if (NULL == gr) { - fprintf (stderr, + fprintf(stderr, _("%s: line %jd: group '%s' does not exist\n"), Prog, line, name); errors = true; @@ -463,7 +463,7 @@ int main (int argc, char **argv) * a group and a gshadow password, it's preferable * to update both. */ - sg = sgr_locate (name); + sg = sgr_locate(name); if ( (NULL == sg) && streq(gr->gr_passwd, SHADOW_PASSWD_STRING)) @@ -508,10 +508,10 @@ int main (int argc, char **argv) */ #ifdef SHADOWGRP if (NULL != sg) { - if (sgr_update (&newsg) == 0) { - fprintf (stderr, + if (sgr_update(&newsg) == 0) { + fprintf(stderr, _("%s: line %jd: failed to prepare the new %s entry '%s'\n"), - Prog, line, sgr_dbname (), newsg.sg_namp); + Prog, line, sgr_dbname(), newsg.sg_namp); errors = true; continue; } @@ -520,10 +520,10 @@ int main (int argc, char **argv) || !streq(gr->gr_passwd, SHADOW_PASSWD_STRING)) #endif { - if (gr_update (&newgr) == 0) { - fprintf (stderr, + if (gr_update(&newgr) == 0) { + fprintf(stderr, _("%s: line %jd: failed to prepare the new %s entry '%s'\n"), - Prog, line, gr_dbname (), newgr.gr_name); + Prog, line, gr_dbname(), newgr.gr_name); errors = true; continue; } @@ -538,15 +538,15 @@ int main (int argc, char **argv) * afterwards. */ if (errors) { - fprintf (stderr, + fprintf(stderr, _("%s: error detected, changes ignored\n"), Prog); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } - close_files (&flags); + close_files(&flags); - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_GROUP); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_GROUP); return (0); } diff --git a/src/chpasswd.c b/src/chpasswd.c index fa0b19d15f..eab780652b 100644 --- a/src/chpasswd.c +++ b/src/chpasswd.c @@ -71,21 +71,21 @@ static bool pw_locked = false; static bool spw_locked = false; /* local function prototypes */ -NORETURN static void fail_exit (int code, bool process_selinux); -NORETURN static void usage (int status); -static void process_flags (int argc, char **argv, struct option_flags *flags); -static void check_flags (void); +NORETURN static void fail_exit(int code, bool process_selinux); +NORETURN static void usage(int status); +static void process_flags(int argc, char **argv, struct option_flags *flags); +static void check_flags(void); static void open_files(const struct option_flags *flags); static void close_files(const struct option_flags *flags); /* * fail_exit - exit with a failure code after unlocking the files */ -static void fail_exit (int code, bool process_selinux) +static void fail_exit(int code, bool process_selinux) { if (pw_locked) { - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -99,7 +99,7 @@ static void fail_exit (int code, bool process_selinux) } } - exit (code); + exit(code); } /* @@ -107,16 +107,16 @@ static void fail_exit (int code, bool process_selinux) */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options]\n" "\n" "Options:\n"), Prog); - (void) fprintf (usageout, - _(" -c, --crypt-method METHOD the crypt method (one of %s)\n"), + (void) fprintf(usageout, + _(" -c, --crypt-method METHOD the crypt method(one of %s)\n"), "NONE DES MD5" " SHA256 SHA512" #if defined(USE_BCRYPT) @@ -126,16 +126,16 @@ usage (int status) " YESCRYPT" #endif ); - (void) fputs (_(" -e, --encrypted supplied passwords are encrypted\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout); - (void) fputs (_(" -s, --sha-rounds number of rounds for the SHA, BCRYPT\n" + (void) fputs(_(" -e, --encrypted supplied passwords are encrypted\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout); + (void) fputs(_(" -s, --sha-rounds number of rounds for the SHA, BCRYPT\n" " or YESCRYPT crypt algorithms\n"), usageout); - (void) fputs ("\n", usageout); + (void) fputs("\n", usageout); - exit (status); + exit(status); } /* @@ -143,7 +143,7 @@ usage (int status) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { int c; int bad_s; @@ -167,7 +167,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) eflg = true; break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ flags->chroot = true; @@ -216,20 +216,20 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * * It will not return if an error is encountered. */ -static void check_flags (void) +static void check_flags(void) { if (sflg && !cflg) { - fprintf (stderr, + fprintf(stderr, _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-s", "-c"); - usage (E_USAGE); + usage(E_USAGE); } if (eflg && cflg) { - fprintf (stderr, + fprintf(stderr, _("%s: the -c and -e flags are exclusive\n"), Prog); - usage (E_USAGE); + usage(E_USAGE); } if (cflg) { @@ -245,10 +245,10 @@ static void check_flags (void) &&(!IS_CRYPT_METHOD("YESCRYPT")) #endif /* USE_YESCRYPT */ ) { - fprintf (stderr, + fprintf(stderr, _("%s: unsupported crypt method: %s\n"), Prog, crypt_method); - usage (E_USAGE); + usage(E_USAGE); } } } @@ -266,17 +266,17 @@ static void open_files(const struct option_flags *flags) * Lock the password file and open it for reading and writing. This * will bring all of the entries into memory where they may be updated. */ - if (pw_lock () == 0) { - fprintf (stderr, + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - fail_exit (1, process_selinux); + Prog, pw_dbname()); + fail_exit(1, process_selinux); } pw_locked = true; - if (pw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, - _("%s: cannot open %s\n"), Prog, pw_dbname ()); - fail_exit (1, process_selinux); + if (pw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, + _("%s: cannot open %s\n"), Prog, pw_dbname()); + fail_exit(1, process_selinux); } /* Do the same for the shadowed database, if it exist */ @@ -307,15 +307,15 @@ static void close_files(const struct option_flags *flags) process_selinux = !flags->chroot && !flags->prefix; if (is_shadow_pwd) { - if (spw_close (process_selinux) == 0) { - fprintf (stderr, + if (spw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", spw_dbname()); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); /* continue */ } @@ -360,10 +360,10 @@ static const char *get_salt(void) } #endif /* USE_YESCRYPT */ } - return crypt_make_salt (crypt_method, arg); + return crypt_make_salt(crypt_method, arg); } -int main (int argc, char **argv) +int main(int argc, char **argv) { char buf[BUFSIZ]; char *name; @@ -382,22 +382,22 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); #ifdef WITH_SELINUX - if (check_selinux_permit ("passwd") != 0) { + if (check_selinux_permit("passwd") != 0) { return (E_NOPERM); } #endif /* WITH_SELINUX */ - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); process_selinux = !flags.chroot && !flags.prefix; salt = get_salt(); - process_root_flag ("-R", argc, argv); - prefix = process_prefix_flag ("-P", argc, argv); + process_root_flag("-R", argc, argv); + prefix = process_prefix_flag("-P", argc, argv); #ifdef USE_PAM if (eflg || cflg || prefix[0]) { @@ -405,15 +405,15 @@ int main (int argc, char **argv) } #endif /* USE_PAM */ - OPENLOG (Prog); + OPENLOG(Prog); #ifdef USE_PAM if (!use_pam) #endif /* USE_PAM */ { - is_shadow_pwd = spw_file_present (); + is_shadow_pwd = spw_file_present(); - open_files (&flags); + open_files(&flags); } /* @@ -429,14 +429,14 @@ int main (int argc, char **argv) line++; if (stpsep(buf, "\n") == NULL) { - if (feof (stdin) == 0) { + if (feof(stdin) == 0) { // Drop all remaining characters on this line. while (fgets_a(buf, stdin) != NULL) { if (strchr(buf, '\n')) break; } - fprintf (stderr, + fprintf(stderr, _("%s: line %jd: line too long\n"), Prog, line); errors = true; @@ -456,7 +456,7 @@ int main (int argc, char **argv) name = buf; cp = stpsep(name, ":"); if (cp == NULL) { - fprintf (stderr, + fprintf(stderr, _("%s: line %jd: missing new password\n"), Prog, line); errors = true; @@ -466,8 +466,8 @@ int main (int argc, char **argv) #ifdef USE_PAM if (use_pam) { - if (do_pam_passwd_non_interactive (Prog, name, newpwd) != 0) { - fprintf (stderr, + if (do_pam_passwd_non_interactive(Prog, name, newpwd) != 0) { + fprintf(stderr, _("%s: (line %jd, user %s) password not changed\n"), Prog, line, name); errors = true; @@ -483,7 +483,7 @@ int main (int argc, char **argv) if (eflg) { if (!is_valid_hash(newpwd)) { - fprintf (stderr, + fprintf(stderr, _("%s: (line %jd, user %s) invalid password hash\n"), Prog, line, name); errors = true; @@ -496,12 +496,12 @@ int main (int argc, char **argv) struct passwd newpw; if (salt) { - cp = pw_encrypt (newpwd, salt); + cp = pw_encrypt(newpwd, salt); if (NULL == cp) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to crypt password with salt '%s': %s\n"), Prog, salt, strerrno()); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } } @@ -509,9 +509,9 @@ int main (int argc, char **argv) * Get the password file entry for this user. The user must * already exist. */ - pw = pw_locate (name); + pw = pw_locate(name); if (NULL == pw) { - fprintf (stderr, + fprintf(stderr, _("%s: line %jd: user '%s' does not exist\n"), Prog, line, name); errors = true; @@ -524,7 +524,7 @@ int main (int argc, char **argv) * a passwd and a shadow password, it's preferable * to update both. */ - sp = spw_locate (name); + sp = spw_locate(name); if ( (NULL == sp) && streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) @@ -536,9 +536,9 @@ int main (int argc, char **argv) newsp.sp_namp = name; /* newsp.sp_pwdp = NULL; will be set later */ /* newsp.sp_lstchg= 0; will be set later */ - newsp.sp_min = getdef_num ("PASS_MIN_DAYS", -1); - newsp.sp_max = getdef_num ("PASS_MAX_DAYS", -1); - newsp.sp_warn = getdef_num ("PASS_WARN_AGE", -1); + newsp.sp_min = getdef_num("PASS_MIN_DAYS", -1); + newsp.sp_max = getdef_num("PASS_MAX_DAYS", -1); + newsp.sp_warn = getdef_num("PASS_WARN_AGE", -1); newsp.sp_inact = -1; newsp.sp_expire= -1; newsp.sp_flag = SHADOW_SP_FLAG_UNSET; @@ -556,7 +556,7 @@ int main (int argc, char **argv) if (NULL != sp) { newsp = *sp; newsp.sp_pwdp = cp; - newsp.sp_lstchg = gettime () / DAY; + newsp.sp_lstchg = gettime() / DAY; if (0 == newsp.sp_lstchg) { /* Better disable aging than requiring a * password change */ @@ -576,20 +576,20 @@ int main (int argc, char **argv) * other entries have been updated as well. */ if (NULL != sp) { - if (spw_update (&newsp) == 0) { - fprintf (stderr, + if (spw_update(&newsp) == 0) { + fprintf(stderr, _("%s: line %jd: failed to prepare the new %s entry '%s'\n"), - Prog, line, spw_dbname (), newsp.sp_namp); + Prog, line, spw_dbname(), newsp.sp_namp); errors = true; continue; } } if ( (NULL == sp) || !streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) { - if (pw_update (&newpw) == 0) { - fprintf (stderr, + if (pw_update(&newpw) == 0) { + fprintf(stderr, _("%s: line %jd: failed to prepare the new %s entry '%s'\n"), - Prog, line, pw_dbname (), newpw.pw_name); + Prog, line, pw_dbname(), newpw.pw_name); errors = true; continue; } @@ -612,11 +612,11 @@ int main (int argc, char **argv) if (!use_pam) #endif /* USE_PAM */ { - fprintf (stderr, + fprintf(stderr, _("%s: error detected, changes ignored\n"), Prog); } - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } #ifdef USE_PAM diff --git a/src/chsh.c b/src/chsh.c index fafa9759d6..f468d5d682 100644 --- a/src/chsh.c +++ b/src/chsh.c @@ -79,11 +79,11 @@ static void update_shell (const char *user, char *loginsh, */ NORETURN static void -fail_exit (int code, bool process_selinux) +fail_exit(int code, bool process_selinux) { if (pw_locked) { - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -99,19 +99,19 @@ fail_exit (int code, bool process_selinux) */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] [LOGIN]\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -s, --shell SHELL new login shell for the user account\n"), usageout); - (void) fputs ("\n", usageout); - exit (status); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -s, --shell SHELL new login shell for the user account\n"), usageout); + (void) fputs("\n", usageout); + exit(status); } /* @@ -120,24 +120,24 @@ usage (int status) * prompt the user for the login shell and change it according to the * response, or leave it alone if nothing was entered. */ -static void new_fields (void) +static void new_fields(void) { - puts (_("Enter the new value, or press ENTER for the default")); - change_field(loginsh, sizeof(loginsh), _("Login Shell")); + puts(_("Enter the new value, or press ENTER for the default")); + change_field(loginsh, sizeof (loginsh), _("Login Shell")); } /* * is_restricted_shell - return true if the shell is restricted * */ -static bool is_restricted_shell (const char *sh, bool process_selinux) +static bool is_restricted_shell(const char *sh, bool process_selinux) { /* * Shells not listed in /etc/shells are considered to be restricted. * Changed this to avoid confusion with "rc" (the plan9 shell - not * restricted despite the name starting with 'r'). --marekm */ - return !shell_is_listed (sh, process_selinux); + return !shell_is_listed(sh, process_selinux); } /* @@ -152,7 +152,7 @@ static bool is_restricted_shell (const char *sh, bool process_selinux) */ #ifdef HAVE_VENDORDIR -static bool shell_is_listed (const char *sh, bool process_selinux) +static bool shell_is_listed(const char *sh, bool process_selinux) { bool found = false; @@ -169,19 +169,19 @@ static bool shell_is_listed (const char *sh, bool process_selinux) "", /* key only */ "#" /* comment */); if (error) { - fprintf (stderr, + fprintf(stderr, _("Cannot parse shell files: %s"), econf_errString(error)); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } error = econf_getKeys(key_file, NULL, &size, &keys); if (error) { - fprintf (stderr, + fprintf(stderr, _("Cannot evaluate entries in shell files: %s"), econf_errString(error)); - econf_free (key_file); - fail_exit (1, process_selinux); + econf_free(key_file); + fail_exit(1, process_selinux); } for (size_t i = 0; i < size; i++) { @@ -190,27 +190,27 @@ static bool shell_is_listed (const char *sh, bool process_selinux) break; } } - econf_free (keys); - econf_free (key_file); + econf_free(keys); + econf_free(key_file); return found; } #else /* without HAVE_VENDORDIR */ -static bool shell_is_listed (const char *sh, MAYBE_UNUSED bool _1) +static bool shell_is_listed(const char *sh, MAYBE_UNUSED bool _1) { bool found = false; char *cp; - setusershell (); - while ((cp = getusershell ())) { + setusershell(); + while ((cp = getusershell())) { if (streq(cp, sh)) { found = true; break; } } - endusershell (); + endusershell(); return found; } @@ -221,7 +221,7 @@ static bool shell_is_listed (const char *sh, MAYBE_UNUSED bool _1) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { int c; static struct option long_options[] = { @@ -231,11 +231,11 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "hR:s:", + while ((c = getopt_long(argc, argv, "hR:s:", long_options, NULL)) != -1) { switch (c) { case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ flags->chroot = true; @@ -245,7 +245,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) strtcpy_a(loginsh, optarg); break; default: - usage (E_USAGE); + usage(E_USAGE); } } @@ -254,7 +254,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * be the user's name. */ if (argc > (optind + 1)) { - usage (E_USAGE); + usage(E_USAGE); } } @@ -283,37 +283,37 @@ static void check_perms(const struct passwd *pw, const struct option_flags *flag * Non-privileged users are only allowed to change the shell if the * UID of the user matches the current real UID. */ - if (!amroot && pw->pw_uid != getuid ()) { + if (!amroot && pw->pw_uid != getuid()) { SYSLOG(LOG_WARN, "can't change shell for '%s'", pw->pw_name); - fprintf (stderr, + fprintf(stderr, _("You may not change the shell for '%s'.\n"), pw->pw_name); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } /* * Non-privileged users are only allowed to change the shell if it * is not a restricted one. */ - if (!amroot && is_restricted_shell (pw->pw_shell, process_selinux)) { + if (!amroot && is_restricted_shell(pw->pw_shell, process_selinux)) { SYSLOG(LOG_WARN, "can't change shell for '%s'", pw->pw_name); - fprintf (stderr, + fprintf(stderr, _("You may not change the shell for '%s'.\n"), pw->pw_name); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } #ifdef WITH_SELINUX /* * If the UID of the user does not match the current real UID, * check if the change is allowed by SELinux policy. */ - if ((pw->pw_uid != getuid ()) + if ((pw->pw_uid != getuid()) && (check_selinux_permit(Prog) != 0)) { SYSLOG(LOG_WARN, "can't change shell for '%s'", pw->pw_name); - fprintf (stderr, + fprintf(stderr, _("You may not change the shell for '%s'.\n"), pw->pw_name); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } #endif @@ -324,7 +324,7 @@ static void check_perms(const struct passwd *pw, const struct option_flags *flag * before any changes can be made. Idea from util-linux * chfn/chsh. --marekm */ - if (!amroot && getdef_bool ("CHSH_AUTH")) { + if (!amroot && getdef_bool("CHSH_AUTH")) { passwd_check(pw->pw_name, pw->pw_passwd); } @@ -367,7 +367,7 @@ static void check_perms(const struct passwd *pw, const struct option_flags *flag * * It will not return in case of error. */ -static void update_shell (const char *user, char *newshell, const struct option_flags *flags) +static void update_shell(const char *user, char *newshell, const struct option_flags *flags) { const struct passwd *pw; /* Password entry from /etc/passwd */ struct passwd pwent; /* New password entry */ @@ -381,27 +381,27 @@ static void update_shell (const char *user, char *newshell, const struct option_ * to root to protect against unexpected signals. Any * keyboard signals are set to be ignored. */ - if (setuid (0) != 0) { + if (setuid(0) != 0) { SYSLOG(LOG_ERR, "can't setuid(0)"); - fputs (_("Cannot change ID to root.\n"), stderr); - fail_exit (1, process_selinux); + fputs(_("Cannot change ID to root.\n"), stderr); + fail_exit(1, process_selinux); } - pwd_init (); + pwd_init(); /* * The passwd entry is now ready to be committed back to * the password file. Get a lock on the file and open it. */ - if (pw_lock () == 0) { - fprintf (stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - fail_exit (1, process_selinux); + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), + Prog, pw_dbname()); + fail_exit(1, process_selinux); } pw_locked = true; - if (pw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ()); + if (pw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, pw_dbname()); SYSLOG(LOG_WARN, "cannot open %s", pw_dbname()); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } /* @@ -410,12 +410,12 @@ static void update_shell (const char *user, char *newshell, const struct option_ * contain the shadow password if (despite the warnings) someone * enables AUTOSHADOW (or SHADOW_COMPAT in libc). --marekm */ - pw = pw_locate (user); + pw = pw_locate(user); if (NULL == pw) { - fprintf (stderr, + fprintf(stderr, _("%s: user '%s' does not exist in %s\n"), - Prog, user, pw_dbname ()); - fail_exit (1, process_selinux); + Prog, user, pw_dbname()); + fail_exit(1, process_selinux); } /* @@ -429,23 +429,23 @@ static void update_shell (const char *user, char *newshell, const struct option_ * Update the passwd file entry. If there is a DBM file, update * that entry as well. */ - if (pw_update (&pwent) == 0) { - fprintf (stderr, + if (pw_update(&pwent) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, pw_dbname (), pwent.pw_name); - fail_exit (1, process_selinux); + Prog, pw_dbname(), pwent.pw_name); + fail_exit(1, process_selinux); } /* * Changes have all been made, so commit them and unlock the file. */ - if (pw_close (process_selinux) == 0) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); + if (pw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", pw_dbname()); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -458,31 +458,31 @@ static void update_shell (const char *user, char *newshell, const struct option_ * The only supported option is -s which permits the the login shell to * be set from the command line. */ -int main (int argc, char **argv) +int main(int argc, char **argv) { char *user; /* User name */ const struct passwd *pw; /* Password entry from /etc/passwd */ struct option_flags flags = {.chroot = false}; bool process_selinux; - sanitize_env (); - check_fds (); + sanitize_env(); + check_fds(); log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); /* * This command behaves different for root and non-root users. */ - amroot = (getuid () == 0); + amroot = (getuid() == 0); - OPENLOG (Prog); + OPENLOG(Prog); /* parse the command line options */ process_flags (argc, argv, &flags); @@ -493,31 +493,31 @@ int main (int argc, char **argv) * name, or the name getlogin() returns. */ if (optind < argc) { - if (!is_valid_user_name (argv[optind])) { - fprintf (stderr, _("%s: Provided user name is not a valid name\n"), Prog); - fail_exit (1, process_selinux); + if (!is_valid_user_name(argv[optind])) { + fprintf(stderr, _("%s: Provided user name is not a valid name\n"), Prog); + fail_exit(1, process_selinux); } user = argv[optind]; - pw = xgetpwnam (user); + pw = xgetpwnam(user); if (NULL == pw) { - fprintf (stderr, + fprintf(stderr, _("%s: user '%s' does not exist\n"), Prog, user); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } } else { - pw = get_my_pwent (); + pw = get_my_pwent(); if (NULL == pw) { - fprintf (stderr, + fprintf(stderr, _("%s: Cannot determine your user name.\n"), Prog); - SYSLOG(LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", + SYSLOG(LOG_WARN, "Cannot determine the user name of the caller(UID %lu)", (unsigned long) getuid()); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } - user = xstrdup (pw->pw_name); + user = xstrdup(pw->pw_name); } - check_perms (pw, &flags); + check_perms(pw, &flags); /* * Now get the login shell. Either get it from the password @@ -532,8 +532,8 @@ int main (int argc, char **argv) * interactively change it. */ if (!sflg) { - printf (_("Changing the login shell for %s\n"), user); - new_fields (); + printf(_("Changing the login shell for %s\n"), user); + new_fields(); } /* @@ -542,41 +542,41 @@ int main (int argc, char **argv) * users are restricted to using the shells in /etc/shells. * The shell must be executable by the user. */ - if (valid_field (loginsh, ":,=\n") != 0) { - fprintf (stderr, _("%s: Invalid entry: %s\n"), Prog, loginsh); - fail_exit (1, process_selinux); + if (valid_field(loginsh, ":,=\n") != 0) { + fprintf(stderr, _("%s: Invalid entry: %s\n"), Prog, loginsh); + fail_exit(1, process_selinux); } if (!streq(loginsh, "") && (loginsh[0] != '/' - || is_restricted_shell (loginsh, process_selinux) - || (access (loginsh, X_OK) != 0))) + || is_restricted_shell(loginsh, process_selinux) + || (access(loginsh, X_OK) != 0))) { if (amroot) { - fprintf (stderr, _("%s: Warning: %s is an invalid shell\n"), Prog, loginsh); + fprintf(stderr, _("%s: Warning: %s is an invalid shell\n"), Prog, loginsh); } else { - fprintf (stderr, _("%s: %s is an invalid shell\n"), Prog, loginsh); - fail_exit (1, process_selinux); + fprintf(stderr, _("%s: %s is an invalid shell\n"), Prog, loginsh); + fail_exit(1, process_selinux); } } /* Even for root, warn if an invalid shell is specified. */ if (!streq(loginsh, "")) { /* But not if an empty string is given, documented as meaning the default shell */ - if (access (loginsh, F_OK) != 0) { - fprintf (stderr, _("%s: Warning: %s does not exist\n"), Prog, loginsh); - } else if (access (loginsh, X_OK) != 0) { - fprintf (stderr, _("%s: Warning: %s is not executable\n"), Prog, loginsh); + if (access(loginsh, F_OK) != 0) { + fprintf(stderr, _("%s: Warning: %s does not exist\n"), Prog, loginsh); + } else if (access(loginsh, X_OK) != 0) { + fprintf(stderr, _("%s: Warning: %s is not executable\n"), Prog, loginsh); } } - update_shell (user, loginsh, &flags); + update_shell(user, loginsh, &flags); SYSLOG(LOG_INFO, "changed user '%s' shell to '%s'", user, loginsh); - nscd_flush_cache ("passwd"); - sssd_flush_cache (SSSD_DB_PASSWD); + nscd_flush_cache("passwd"); + sssd_flush_cache(SSSD_DB_PASSWD); - closelog (); - exit (E_SUCCESS); + closelog(); + exit(E_SUCCESS); } diff --git a/src/faillog.c b/src/faillog.c index 28cf7f58e1..dddaf0532a 100644 --- a/src/faillog.c +++ b/src/faillog.c @@ -34,7 +34,7 @@ /* local function prototypes */ -NORETURN static void usage (int status); +NORETURN static void usage(int status); static void print_one (/*@null@*/const struct passwd *pw, bool force); static void set_locktime (long locktime); static bool set_locktime_one (uid_t uid, long locktime); @@ -69,26 +69,26 @@ static struct stat statbuf; /* fstat buffer for file size */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options]\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -a, --all display faillog records for all users\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -l, --lock-secs SEC after failed login lock account for SEC seconds\n"), usageout); - (void) fputs (_(" -m, --maximum MAX set maximum failed login counters to MAX\n"), usageout); - (void) fputs (_(" -r, --reset reset the counters of login failures\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -t, --time DAYS display faillog records more recent than DAYS\n"), usageout); - (void) fputs (_(" -u, --user LOGIN/RANGE display faillog record or maintains failure\n" - " counters and limits (if used with -r, -m,\n" + (void) fputs(_(" -a, --all display faillog records for all users\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -l, --lock-secs SEC after failed login lock account for SEC seconds\n"), usageout); + (void) fputs(_(" -m, --maximum MAX set maximum failed login counters to MAX\n"), usageout); + (void) fputs(_(" -r, --reset reset the counters of login failures\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -t, --time DAYS display faillog records more recent than DAYS\n"), usageout); + (void) fputs(_(" -u, --user LOGIN/RANGE display faillog record or maintains failure\n" + " counters and limits(if used with -r, -m,\n" " or -l) only for the specified LOGIN(s)\n"), usageout); - (void) fputs ("\n", usageout); - exit (status); + (void) fputs("\n", usageout); + exit(status); } /* @@ -116,7 +116,7 @@ static off_t lookup_faillog(struct faillog *fl, uid_t uid) * entered for this user, which should be able to get the * empty entry in this case. */ - if (fread(fl, sizeof(*fl), 1, fail) != 1) { + if (fread(fl, sizeof (*fl), 1, fail) != 1) { fprintf(stderr, _("%s: Failed to get the entry for UID %lu\n"), Prog, (unsigned long)uid); @@ -128,7 +128,7 @@ static off_t lookup_faillog(struct faillog *fl, uid_t uid) * as if we were reading an non existing entry in the * sparse faillog file). */ - memzero(fl, sizeof(*fl)); + memzero(fl, sizeof (*fl)); } return offset; @@ -165,38 +165,38 @@ static void print_one (/*@null@*/const struct passwd *pw, bool force) /* Print the header only once */ if (!once) { - puts (_("Login Failures Maximum Latest On\n")); + puts(_("Login Failures Maximum Latest On\n")); once = true; } - tm = localtime (&fl.fail_time); + tm = localtime(&fl.fail_time); if (!tm) { - fprintf (stderr, "Cannot read time from faillog.\n"); + fprintf(stderr, "Cannot read time from faillog.\n"); return; } strftime_a(ptime, "%D %H:%M:%S %z", tm); cp = ptime; - printf ("%-9s %5d %5d ", + printf("%-9s %5d %5d ", pw->pw_name, fl.fail_cnt, fl.fail_max); - printf ("%s %s", cp, fl.fail_line); + printf("%s %s", cp, fl.fail_line); if (0 != fl.fail_locktime) { if ( ((fl.fail_time + fl.fail_locktime) > now) && (0 != fl.fail_cnt)) { - printf (_(" [%lus left]"), + printf(_(" [%lus left]"), (unsigned long) fl.fail_time + fl.fail_locktime - now); } else { - printf (_(" [%lds lock]"), + printf(_(" [%lds lock]"), fl.fail_locktime); } } - putchar ('\n'); + putchar('\n'); } -static void print (void) +static void print(void) { if (uflg && has_umin && has_umax && (umin==umax)) { - print_one (getpwuid (umin), true); + print_one(getpwuid(umin), true); } else { /* We only print records for existing users. * Loop based on the user database instead of reading the @@ -206,16 +206,16 @@ static void print (void) */ struct passwd *pwent; - setpwent (); - while ( (pwent = getpwent ()) != NULL ) { + setpwent(); + while ( (pwent = getpwent()) != NULL ) { if ( uflg && ( (has_umin && (pwent->pw_uid < (uid_t)umin)) || (has_umax && (pwent->pw_uid > (uid_t)umax)))) { continue; } - print_one (pwent, aflg); + print_one(pwent, aflg); } - endpwent (); + endpwent(); } } @@ -224,7 +224,7 @@ static void print (void) * * This returns a boolean indicating if an error occurred. */ -static bool reset_one (uid_t uid) +static bool reset_one(uid_t uid) { off_t offset; struct faillog fl; @@ -245,29 +245,29 @@ static bool reset_one (uid_t uid) fl.fail_cnt = 0; - if ( (fseeko (fail, offset, SEEK_SET) == 0) - && (fwrite(&fl, sizeof(fl), 1, fail) == 1)) { - (void) fflush (fail); + if ( (fseeko(fail, offset, SEEK_SET) == 0) + && (fwrite(&fl, sizeof (fl), 1, fail) == 1)) { + (void) fflush(fail); return false; } - fprintf (stderr, + fprintf(stderr, _("%s: Failed to reset fail count for UID %lu\n"), Prog, (unsigned long)uid); return true; } -static void reset (void) +static void reset(void) { if (uflg && has_umin && has_umax && (umin==umax)) { - if (reset_one (umin)) { + if (reset_one(umin)) { errors = true; } } else { /* There is no need to reset outside of the faillog * database. */ - uid_t uidmax = statbuf.st_size / sizeof(struct faillog); + uid_t uidmax = statbuf.st_size / sizeof (struct faillog); if (uidmax > 1) { uidmax--; } @@ -299,18 +299,18 @@ static void reset (void) */ struct passwd *pwent; - setpwent (); - while ( (pwent = getpwent ()) != NULL ) { + setpwent(); + while ( (pwent = getpwent()) != NULL ) { if ( uflg && ( (has_umin && (pwent->pw_uid < (uid_t)umin)) || (pwent->pw_uid > uidmax))) { continue; } - if (reset_one (pwent->pw_uid)) { + if (reset_one(pwent->pw_uid)) { errors = true; } } - endpwent (); + endpwent(); } } } @@ -320,7 +320,7 @@ static void reset (void) * * This returns a boolean indicating if an error occurred. */ -static bool setmax_one (uid_t uid, short max) +static bool setmax_one(uid_t uid, short max) { off_t offset; struct faillog fl; @@ -341,22 +341,22 @@ static bool setmax_one (uid_t uid, short max) fl.fail_max = max; - if ( (fseeko (fail, offset, SEEK_SET) == 0) - && (fwrite(&fl, sizeof(fl), 1, fail) == 1)) { - (void) fflush (fail); + if ( (fseeko(fail, offset, SEEK_SET) == 0) + && (fwrite(&fl, sizeof (fl), 1, fail) == 1)) { + (void) fflush(fail); return false; } - fprintf (stderr, + fprintf(stderr, _("%s: Failed to set max for UID %lu\n"), Prog, (unsigned long)uid); return true; } -static void setmax (short max) +static void setmax(short max) { if (uflg && has_umin && has_umax && (umin==umax)) { - if (setmax_one (umin, max)) { + if (setmax_one(umin, max)) { errors = true; } } else { @@ -373,7 +373,7 @@ static void setmax (short max) /* The default umax value is based on the size of the * faillog database. */ - uid_t uidmax = statbuf.st_size / sizeof(struct faillog); + uid_t uidmax = statbuf.st_size / sizeof (struct faillog); if (uidmax > 1) { uidmax--; } @@ -397,18 +397,18 @@ static void setmax (short max) */ struct passwd *pwent; - setpwent (); - while ( (pwent = getpwent ()) != NULL ) { + setpwent(); + while ( (pwent = getpwent()) != NULL ) { if ( uflg && ( (has_umin && (pwent->pw_uid < (uid_t)umin)) || (has_umax && (pwent->pw_uid > (uid_t)umax)))) { continue; } - if (setmax_one (pwent->pw_uid, max)) { + if (setmax_one(pwent->pw_uid, max)) { errors = true; } } - endpwent (); + endpwent(); } } } @@ -418,7 +418,7 @@ static void setmax (short max) * * This returns a boolean indicating if an error occurred. */ -static bool set_locktime_one (uid_t uid, long locktime) +static bool set_locktime_one(uid_t uid, long locktime) { off_t offset; struct faillog fl; @@ -439,22 +439,22 @@ static bool set_locktime_one (uid_t uid, long locktime) fl.fail_locktime = locktime; - if ( (fseeko (fail, offset, SEEK_SET) == 0) - && (fwrite(&fl, sizeof(fl), 1, fail) == 1)) { - (void) fflush (fail); + if ( (fseeko(fail, offset, SEEK_SET) == 0) + && (fwrite(&fl, sizeof (fl), 1, fail) == 1)) { + (void) fflush(fail); return false; } - fprintf (stderr, + fprintf(stderr, _("%s: Failed to set locktime for UID %lu\n"), Prog, (unsigned long)uid); return true; } -static void set_locktime (long locktime) +static void set_locktime(long locktime) { if (uflg && has_umin && has_umax && (umin==umax)) { - if (set_locktime_one (umin, locktime)) { + if (set_locktime_one(umin, locktime)) { errors = true; } } else { @@ -471,7 +471,7 @@ static void set_locktime (long locktime) /* The default umax value is based on the size of the * faillog database. */ - uid_t uidmax = statbuf.st_size / sizeof(struct faillog); + uid_t uidmax = statbuf.st_size / sizeof (struct faillog); if (uidmax > 1) { uidmax--; } @@ -495,23 +495,23 @@ static void set_locktime (long locktime) */ struct passwd *pwent; - setpwent (); - while ( (pwent = getpwent ()) != NULL ) { + setpwent(); + while ( (pwent = getpwent()) != NULL ) { if ( uflg && ( (has_umin && (pwent->pw_uid < (uid_t)umin)) || (has_umax && (pwent->pw_uid > (uid_t)umax)))) { continue; } - if (set_locktime_one (pwent->pw_uid, locktime)) { + if (set_locktime_one(pwent->pw_uid, locktime)) { errors = true; } } - endpwent (); + endpwent(); } } } -int main (int argc, char **argv) +int main(int argc, char **argv) { long fail_locktime = 0; short fail_max = 0; // initialize to silence compiler warning @@ -520,11 +520,11 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); { int c; @@ -539,14 +539,14 @@ int main (int argc, char **argv) {"user", required_argument, NULL, 'u'}, {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "ahl:m:rR:t:u:", + while ((c = getopt_long(argc, argv, "ahl:m:rR:t:u:", long_options, NULL)) != -1) { switch (c) { case 'a': aflg = true; break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'l': if (str2sl(&fail_locktime, optarg) == -1) { @@ -575,10 +575,10 @@ int main (int argc, char **argv) break; case 't': if (str2sl(&days, optarg) == -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } seconds = (time_t) days * DAY; tflg = true; @@ -633,15 +633,15 @@ int main (int argc, char **argv) /* Open the faillog database */ if (lflg || mflg || rflg) { - fail = fopen (FAILLOG_FILE, "r+"); + fail = fopen(FAILLOG_FILE, "r+"); } else { - fail = fopen (FAILLOG_FILE, "r"); + fail = fopen(FAILLOG_FILE, "r"); } if (NULL == fail) { - fprintf (stderr, + fprintf(stderr, _("%s: Cannot open %s: %s\n"), Prog, FAILLOG_FILE, strerrno()); - exit (E_NOPERM); + exit(E_NOPERM); } /* Get the size of the faillog */ diff --git a/src/free_subid_range.c b/src/free_subid_range.c index fcce80b4b5..0d1a0bda77 100644 --- a/src/free_subid_range.c +++ b/src/free_subid_range.c @@ -17,7 +17,7 @@ static const char Prog[] = "free_subid_range"; static void usage(void) { fprintf(stderr, "Usage: %s [-g] user start count\n", Prog); - fprintf(stderr, " Release a user's subuid (or with -g, subgid) range\n"); + fprintf(stderr, " Release a user's subuid(or with -g, subgid) range\n"); exit(EXIT_FAILURE); } @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) if (!subid_init(Prog, stderr)) fprintf(stderr, "subid_init: %s\n", strerrno()); while ((c = getopt(argc, argv, "g")) != EOF) { - switch(c) { + switch (c) { case 'g': group = true; break; default: usage(); } diff --git a/src/gpasswd.c b/src/gpasswd.c index 6ffbc10092..15444ca4e7 100644 --- a/src/gpasswd.c +++ b/src/gpasswd.c @@ -90,25 +90,25 @@ static uid_t bywho; /* local function prototypes */ NORETURN static void failure(void); -static void usage (int status); -static void catch_signals (int killed); -static bool is_valid_user_list (const char *users); -static void process_flags (int argc, char **argv, struct option_flags *flags); -static void check_flags (int argc, int opt_index); +static void usage(int status); +static void catch_signals(int killed); +static bool is_valid_user_list(const char *users); +static void process_flags(int argc, char **argv, struct option_flags *flags); +static void check_flags(int argc, int opt_index); static void open_files(const struct option_flags *flags); static void close_files(const struct option_flags *flags); #ifdef SHADOWGRP static void get_group(struct group *gr, struct sgrp *sg, const struct option_flags *flags); static void check_perms(const struct sgrp *sg); -static void update_group (struct group *gr, struct sgrp *sg); -static void change_passwd (struct group *gr, struct sgrp *sg); +static void update_group(struct group *gr, struct sgrp *sg); +static void change_passwd(struct group *gr, struct sgrp *sg); #else static void get_group(struct group *gr, const struct option_flags *flags); static void check_perms(void); -static void update_group (struct group *gr); -static void change_passwd (struct group *gr); +static void update_group(struct group *gr); +static void change_passwd(struct group *gr); #endif -static void log_gpasswd_failure (const char *suffix); +static void log_gpasswd_failure(const char *suffix); static void log_gpasswd_failure_system (/*@null@*/MAYBE_UNUSED void *_1); static void log_gpasswd_failure_group (/*@null@*/MAYBE_UNUSED void *_1); #ifdef SHADOWGRP @@ -121,29 +121,29 @@ static void log_gpasswd_success_group (/*@null@*/MAYBE_UNUSED void *_1); /* * usage - display usage message */ -static void usage (int status) +static void usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [option] GROUP\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -a, --add USER add USER to GROUP\n"), usageout); - (void) fputs (_(" -d, --delete USER remove USER from GROUP\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -Q, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -r, --remove-password remove the GROUP's password\n"), usageout); - (void) fputs (_(" -R, --restrict restrict access to GROUP to its members\n"), usageout); - (void) fputs (_(" -M, --members USER,... set the list of members of GROUP\n"), usageout); + (void) fputs(_(" -a, --add USER add USER to GROUP\n"), usageout); + (void) fputs(_(" -d, --delete USER remove USER from GROUP\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -Q, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -r, --remove-password remove the GROUP's password\n"), usageout); + (void) fputs(_(" -R, --restrict restrict access to GROUP to its members\n"), usageout); + (void) fputs(_(" -M, --members USER,... set the list of members of GROUP\n"), usageout); #ifdef SHADOWGRP - (void) fputs (_(" -A, --administrators ADMIN,...\n" + (void) fputs(_(" -A, --administrators ADMIN,...\n" " set the list of administrators for GROUP\n"), usageout); - (void) fputs (_("Except for the -A and -M options, the options cannot be combined.\n"), usageout); + (void) fputs(_("Except for the -A and -M options, the options cannot be combined.\n"), usageout); #else - (void) fputs (_("The options cannot be combined.\n"), usageout); + (void) fputs(_("The options cannot be combined.\n"), usageout); #endif - exit (status); + exit(status); } /* @@ -154,19 +154,19 @@ static void usage (int status) * calls catch_signals() with a signal number, the terminal modes are * then reset. */ -static void catch_signals (int killed) +static void catch_signals(int killed) { static TERMIO sgtty; if (0 != killed) { - STTY (0, &sgtty); + STTY(0, &sgtty); } else { - GTTY (0, &sgtty); + GTTY(0, &sgtty); } if (0 != killed) { - (void) write (STDOUT_FILENO, "\n", 1); - _exit (killed); + (void) write(STDOUT_FILENO, "\n", 1); + _exit(killed); } } @@ -178,7 +178,7 @@ static void catch_signals (int killed) * * It returns true if the list of users is valid. */ -static bool is_valid_user_list (const char *users) +static bool is_valid_user_list(const char *users) { bool is_valid = true; char *dup, *tmpusers; @@ -217,7 +217,7 @@ static void failure(void) /* * process_flags - process the command line options and arguments */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { int c; static struct option long_options[] = { @@ -232,18 +232,18 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "a:A:d:ghM:Q:rR", + while ((c = getopt_long(argc, argv, "a:A:d:ghM:Q:rR", long_options, NULL)) != -1) { switch (c) { case 'a': /* add a user */ aflg = true; user = optarg; /* local, no need for xgetpwnam */ - if (getpwnam (user) == NULL) { - fprintf (stderr, + if (getpwnam(user) == NULL) { + fprintf(stderr, _("%s: user '%s' does not exist\n"), Prog, user); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } break; #ifdef SHADOWGRP @@ -272,8 +272,8 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) break; case 'M': /* set the list of members */ members = optarg; - if (!is_valid_user_list (members)) { - exit (E_BAD_ARG); + if (!is_valid_user_list(members)) { + exit(E_BAD_ARG); } Mflg = true; break; @@ -294,13 +294,13 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) /* Get the name of the group that is being affected. */ group = argv[optind]; - check_flags (argc, optind); + check_flags(argc, optind); } /* * check_flags - check the validity of options */ -static void check_flags (int argc, int opt_index) +static void check_flags(int argc, int opt_index) { int exclusive = 0; /* @@ -322,14 +322,14 @@ static void check_flags (int argc, int opt_index) exclusive++; } if (exclusive > 1) { - usage (E_USAGE); + usage(E_USAGE); } /* * Make sure one (and only one) group was provided */ if ((argc != (opt_index+1)) || (NULL == group)) { - usage (E_USAGE); + usage(E_USAGE); } } @@ -344,60 +344,60 @@ static void open_files(const struct option_flags *flags) process_selinux = !flags->chroot; - if (gr_lock () == 0) { - fprintf (stderr, + if (gr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, gr_dbname ()); - exit (E_NOPERM); + Prog, gr_dbname()); + exit(E_NOPERM); } - add_cleanup (cleanup_unlock_group, &process_selinux); + add_cleanup(cleanup_unlock_group, &process_selinux); #ifdef SHADOWGRP if (is_shadowgrp) { - if (sgr_lock () == 0) { - fprintf (stderr, + if (sgr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sgr_dbname ()); - exit (E_NOPERM); + Prog, sgr_dbname()); + exit(E_NOPERM); } - add_cleanup (cleanup_unlock_gshadow, &process_selinux); + add_cleanup(cleanup_unlock_gshadow, &process_selinux); } #endif /* SHADOWGRP */ - add_cleanup (log_gpasswd_failure_system, NULL); + add_cleanup(log_gpasswd_failure_system, NULL); - if (gr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (gr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, gr_dbname ()); + Prog, gr_dbname()); SYSLOG(LOG_WARN, "cannot open %s", gr_dbname()); - exit (E_NOPERM); + exit(E_NOPERM); } #ifdef SHADOWGRP if (is_shadowgrp) { - if (sgr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (sgr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, sgr_dbname ()); + Prog, sgr_dbname()); SYSLOG(LOG_WARN, "cannot open %s", sgr_dbname()); - exit (E_NOPERM); + exit(E_NOPERM); } - add_cleanup (log_gpasswd_failure_gshadow, NULL); + add_cleanup(log_gpasswd_failure_gshadow, NULL); } #endif /* SHADOWGRP */ - add_cleanup (log_gpasswd_failure_group, NULL); - del_cleanup (log_gpasswd_failure_system); + add_cleanup(log_gpasswd_failure_group, NULL); + del_cleanup(log_gpasswd_failure_system); } -static void log_gpasswd_failure (const char *suffix) +static void log_gpasswd_failure(const char *suffix) { if (aflg) { SYSLOG(LOG_ERR, "%s failed to add user %s to group %s%s", myname, user, group, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "add-user-to-group", user, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_FAILURE); @@ -406,7 +406,7 @@ static void log_gpasswd_failure (const char *suffix) SYSLOG(LOG_ERR, "%s failed to remove user %s from group %s%s", myname, user, group, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "delete-user-from-group", user, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_FAILURE); @@ -415,7 +415,7 @@ static void log_gpasswd_failure (const char *suffix) SYSLOG(LOG_ERR, "%s failed to remove password of group %s%s", myname, group, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_GRP_CHAUTHTOK, + audit_logger_with_group(AUDIT_GRP_CHAUTHTOK, "delete-group-password", myname, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_FAILURE); @@ -424,7 +424,7 @@ static void log_gpasswd_failure (const char *suffix) SYSLOG(LOG_ERR, "%s failed to restrict access to group %s%s", myname, group, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_GRP_MGMT, + audit_logger_with_group(AUDIT_GRP_MGMT, "restrict-group", myname, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_FAILURE); @@ -436,7 +436,7 @@ static void log_gpasswd_failure (const char *suffix) "%s failed to set the administrators of group %s to %s%s", myname, group, admins, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_GRP_MGMT, + audit_logger_with_group(AUDIT_GRP_MGMT, "set-admins-of-group", admins, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_FAILURE); @@ -448,7 +448,7 @@ static void log_gpasswd_failure (const char *suffix) "%s failed to set the members of group %s to %s%s", myname, group, members, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "add-users-to-group", members, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_FAILURE); @@ -458,7 +458,7 @@ static void log_gpasswd_failure (const char *suffix) SYSLOG(LOG_ERR, "%s failed to change password of group %s%s", myname, group, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_GRP_CHAUTHTOK, + audit_logger_with_group(AUDIT_GRP_CHAUTHTOK, "change-password", myname, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_FAILURE); @@ -469,7 +469,7 @@ static void log_gpasswd_failure (const char *suffix) static void log_gpasswd_failure_system(MAYBE_UNUSED void *_1) { - log_gpasswd_failure (""); + log_gpasswd_failure(""); } static void @@ -478,7 +478,7 @@ log_gpasswd_failure_group(MAYBE_UNUSED void *_1) char buf[1024]; stprintf_a(buf, " in %s", gr_dbname()); - log_gpasswd_failure (buf); + log_gpasswd_failure(buf); } #ifdef SHADOWGRP @@ -488,11 +488,11 @@ log_gpasswd_failure_gshadow(MAYBE_UNUSED void *_1) char buf[1024]; stprintf_a(buf, " in %s", sgr_dbname()); - log_gpasswd_failure (buf); + log_gpasswd_failure(buf); } #endif /* SHADOWGRP */ -static void log_gpasswd_success (const char *suffix) +static void log_gpasswd_success(const char *suffix) { #ifdef WITH_AUDIT char buf[1024]; @@ -502,7 +502,7 @@ static void log_gpasswd_success (const char *suffix) SYSLOG(LOG_INFO, "user %s added by %s to group %s%s", user, myname, group, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "add-user-to-group", user, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_SUCCESS); @@ -511,7 +511,7 @@ static void log_gpasswd_success (const char *suffix) SYSLOG(LOG_INFO, "user %s removed by %s from group %s%s", user, myname, group, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "delete-user-from-group", user, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_SUCCESS); @@ -522,7 +522,7 @@ static void log_gpasswd_success (const char *suffix) #ifdef WITH_AUDIT stprintf_a(buf, "password of group %s removed by %s%s", group, myname, suffix); - audit_logger_with_group (AUDIT_GRP_CHAUTHTOK, + audit_logger_with_group(AUDIT_GRP_CHAUTHTOK, "delete-group-password", myname, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_SUCCESS); @@ -533,7 +533,7 @@ static void log_gpasswd_success (const char *suffix) #ifdef WITH_AUDIT stprintf_a(buf, "access to group %s restricted by %s%s", group, myname, suffix); - audit_logger_with_group (AUDIT_GRP_MGMT, + audit_logger_with_group(AUDIT_GRP_MGMT, "restrict-group", myname, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_SUCCESS); @@ -544,7 +544,7 @@ static void log_gpasswd_success (const char *suffix) SYSLOG(LOG_INFO, "administrators of group %s set by %s to %s%s", group, myname, admins, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_GRP_MGMT, + audit_logger_with_group(AUDIT_GRP_MGMT, "set-admins-of-group", admins, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_SUCCESS); @@ -555,7 +555,7 @@ static void log_gpasswd_success (const char *suffix) SYSLOG(LOG_INFO, "members of group %s set by %s to %s%s", group, myname, members, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "add-users-to-group", members, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_SUCCESS); @@ -565,7 +565,7 @@ static void log_gpasswd_success (const char *suffix) SYSLOG(LOG_INFO, "password of group %s changed by %s%s", group, myname, suffix); #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_GRP_CHAUTHTOK, + audit_logger_with_group(AUDIT_GRP_CHAUTHTOK, "change-password", myname, AUDIT_NO_ID, "grp", group, SHADOW_AUDIT_SUCCESS); @@ -576,7 +576,7 @@ static void log_gpasswd_success (const char *suffix) static void log_gpasswd_success_system(MAYBE_UNUSED void *_1) { - log_gpasswd_success (""); + log_gpasswd_success(""); } static void @@ -585,7 +585,7 @@ log_gpasswd_success_group(MAYBE_UNUSED void *_1) char buf[1024]; stprintf_a(buf, " in %s", gr_dbname()); - log_gpasswd_success (buf); + log_gpasswd_success(buf); } /* @@ -601,35 +601,35 @@ static void close_files(const struct option_flags *flags) process_selinux = !flags->chroot; - if (gr_close (process_selinux) == 0) { - fprintf (stderr, + if (gr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, gr_dbname ()); - exit (E_NOPERM); + Prog, gr_dbname()); + exit(E_NOPERM); } - add_cleanup (log_gpasswd_success_group, NULL); - del_cleanup (log_gpasswd_failure_group); + add_cleanup(log_gpasswd_success_group, NULL); + del_cleanup(log_gpasswd_failure_group); - cleanup_unlock_group (&process_selinux); - del_cleanup (cleanup_unlock_group); + cleanup_unlock_group(&process_selinux); + del_cleanup(cleanup_unlock_group); #ifdef SHADOWGRP if (is_shadowgrp) { - if (sgr_close (process_selinux) == 0) { - fprintf (stderr, + if (sgr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, sgr_dbname ()); - exit (E_NOPERM); + Prog, sgr_dbname()); + exit(E_NOPERM); } - del_cleanup (log_gpasswd_failure_gshadow); + del_cleanup(log_gpasswd_failure_gshadow); - cleanup_unlock_gshadow (&process_selinux); - del_cleanup (cleanup_unlock_gshadow); + cleanup_unlock_gshadow(&process_selinux); + del_cleanup(cleanup_unlock_gshadow); } #endif /* SHADOWGRP */ - log_gpasswd_success_system (NULL); - del_cleanup (log_gpasswd_success_group); + log_gpasswd_success_system(NULL); + del_cleanup(log_gpasswd_success_group); } /* @@ -639,16 +639,16 @@ static void close_files(const struct option_flags *flags) * It only returns if the user is allowed. */ #ifdef SHADOWGRP -static void check_perms (const struct sgrp *sg) +static void check_perms(const struct sgrp *sg) #else -static void check_perms (void) +static void check_perms(void) #endif { /* * Only root can use the -M and -A options. */ if (!amroot && (Aflg || Mflg)) { - failure (); + failure(); } #ifdef SHADOWGRP @@ -660,8 +660,8 @@ static void check_perms (void) * Administrative members can do anything to a group that * the root user can. */ - if (!amroot && !is_on_list (sg->sg_adm, myname)) { - failure (); + if (!amroot && !is_on_list(sg->sg_adm, myname)) { + failure(); } } else #endif /* SHADOWGRP */ @@ -673,23 +673,23 @@ static void check_perms (void) * update_group - Update the group information in the databases */ #ifdef SHADOWGRP -static void update_group (struct group *gr, struct sgrp *sg) +static void update_group(struct group *gr, struct sgrp *sg) #else -static void update_group (struct group *gr) +static void update_group(struct group *gr) #endif { - if (gr_update (gr) == 0) { - fprintf (stderr, + if (gr_update(gr) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), gr->gr_name); - exit (1); + Prog, gr_dbname(), gr->gr_name); + exit(1); } #ifdef SHADOWGRP - if (is_shadowgrp && (sgr_update (sg) == 0)) { - fprintf (stderr, + if (is_shadowgrp && (sgr_update(sg) == 0)) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), sg->sg_namp); - exit (1); + Prog, sgr_dbname(), sg->sg_namp); + exit(1); } #endif /* SHADOWGRP */ } @@ -716,52 +716,52 @@ static void get_group(struct group *gr, const struct option_flags *flags) process_selinux = !flags->chroot; - if (gr_open (O_RDONLY) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); + if (gr_open(O_RDONLY) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, gr_dbname()); SYSLOG(LOG_WARN, "cannot open %s", gr_dbname()); - exit (E_NOPERM); + exit(E_NOPERM); } - tmpgr = gr_locate (group); + tmpgr = gr_locate(group); if (NULL == tmpgr) { - fprintf (stderr, + fprintf(stderr, _("%s: group '%s' does not exist in %s\n"), - Prog, group, gr_dbname ()); - exit (E_BAD_ARG); + Prog, group, gr_dbname()); + exit(E_BAD_ARG); } *gr = *tmpgr; - gr->gr_name = xstrdup (tmpgr->gr_name); - gr->gr_passwd = xstrdup (tmpgr->gr_passwd); - gr->gr_mem = dup_list (tmpgr->gr_mem); + gr->gr_name = xstrdup(tmpgr->gr_name); + gr->gr_passwd = xstrdup(tmpgr->gr_passwd); + gr->gr_mem = dup_list(tmpgr->gr_mem); - if (gr_close (process_selinux) == 0) { - fprintf (stderr, + if (gr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while closing read-only %s\n"), - Prog, gr_dbname ()); + Prog, gr_dbname()); SYSLOG(LOG_ERR, "failure while closing read-only %s", gr_dbname()); - exit (E_NOPERM); + exit(E_NOPERM); } #ifdef SHADOWGRP if (is_shadowgrp) { - if (sgr_open (O_RDONLY) == 0) { - fprintf (stderr, + if (sgr_open(O_RDONLY) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, sgr_dbname ()); + Prog, sgr_dbname()); SYSLOG(LOG_WARN, "cannot open %s", sgr_dbname()); - exit (E_NOPERM); + exit(E_NOPERM); } - tmpsg = sgr_locate (group); + tmpsg = sgr_locate(group); if (NULL != tmpsg) { *sg = *tmpsg; - sg->sg_namp = xstrdup (tmpsg->sg_namp); - sg->sg_passwd = xstrdup (tmpsg->sg_passwd); + sg->sg_namp = xstrdup(tmpsg->sg_namp); + sg->sg_passwd = xstrdup(tmpsg->sg_passwd); - sg->sg_mem = dup_list (tmpsg->sg_mem); - sg->sg_adm = dup_list (tmpsg->sg_adm); + sg->sg_mem = dup_list(tmpsg->sg_mem); + sg->sg_adm = dup_list(tmpsg->sg_adm); } else { - sg->sg_namp = xstrdup (group); + sg->sg_namp = xstrdup(group); sg->sg_passwd = gr->gr_passwd; gr->gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ @@ -792,9 +792,9 @@ static void get_group(struct group *gr, const struct option_flags *flags) * It will call exit in case of error. */ #ifdef SHADOWGRP -static void change_passwd (struct group *gr, struct sgrp *sg) +static void change_passwd(struct group *gr, struct sgrp *sg) #else -static void change_passwd (struct group *gr) +static void change_passwd(struct group *gr) #endif { char *cp; @@ -808,48 +808,48 @@ static void change_passwd (struct group *gr) * identical. There is no need to validate the old password since * the invoker is either the group owner, or root. */ - printf (_("Changing the password for group %s\n"), group); + printf(_("Changing the password for group %s\n"), group); for (retries = 0; retries < RETRIES; retries++) { - cp = agetpass (_("New Password: ")); + cp = agetpass(_("New Password: ")); if (NULL == cp) { - exit (1); + exit(1); } strtcpy_a(pass, cp); - erase_pass (cp); - cp = agetpass (_("Re-enter new password: ")); + erase_pass(cp); + cp = agetpass(_("Re-enter new password: ")); if (NULL == cp) { memzero_a(pass); - exit (1); + exit(1); } if (streq(pass, cp)) { - erase_pass (cp); + erase_pass(cp); break; } - erase_pass (cp); + erase_pass(cp); memzero_a(pass); if (retries + 1 < RETRIES) { - puts (_("They don't match; try again")); + puts(_("They don't match; try again")); } } if (retries == RETRIES) { - fprintf (stderr, _("%s: Try again later\n"), Prog); - exit (1); + fprintf(stderr, _("%s: Try again later\n"), Prog); + exit(1); } - salt = crypt_make_salt (NULL, NULL); - cp = pw_encrypt (pass, salt); + salt = crypt_make_salt(NULL, NULL); + cp = pw_encrypt(pass, salt); memzero_a(pass); if (NULL == cp) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to crypt password with salt '%s': %s\n"), Prog, salt, strerrno()); - exit (1); + exit(1); } #ifdef SHADOWGRP if (is_shadowgrp) { @@ -865,7 +865,7 @@ static void change_passwd (struct group *gr) /* * gpasswd - administer the /etc/group file */ -int main (int argc, char **argv) +int main(int argc, char **argv) { struct group grent; #ifdef SHADOWGRP @@ -874,12 +874,12 @@ int main (int argc, char **argv) struct passwd *pw = NULL; struct option_flags flags = {.chroot = false}; - sanitize_env (); - check_fds (); + sanitize_env(); + check_fds(); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); /* * Make a note of whether or not this command was invoked by root. @@ -888,22 +888,22 @@ int main (int argc, char **argv) * prevent the invoker from issuing signals which would interfere * with this command. */ - bywho = getuid (); + bywho = getuid(); log_set_progname(Prog); log_set_logfd(stderr); - OPENLOG (Prog); + OPENLOG(Prog); #ifdef WITH_AUDIT - audit_help_open (); + audit_help_open(); #endif - setbuf (stdout, NULL); - setbuf (stderr, NULL); + setbuf(stdout, NULL); + setbuf(stderr, NULL); - process_root_flag ("-Q", argc, argv); + process_root_flag("-Q", argc, argv); #ifdef SHADOWGRP - is_shadowgrp = sgr_file_present (); + is_shadowgrp = sgr_file_present(); #endif /* @@ -912,24 +912,24 @@ int main (int argc, char **argv) * can be executed and so many ways to trip up the routines that * report the user name. */ - pw = get_my_pwent (); + pw = get_my_pwent(); if (NULL == pw) { - fprintf (stderr, _("%s: Cannot determine your user name.\n"), + fprintf(stderr, _("%s: Cannot determine your user name.\n"), Prog); SYSLOG(LOG_WARN, - "Cannot determine the user name of the caller (UID %lu)", + "Cannot determine the user name of the caller(UID %lu)", (unsigned long) getuid()); - exit (E_NOPERM); + exit(E_NOPERM); } - myname = xstrdup (pw->pw_name); + myname = xstrdup(pw->pw_name); /* * Register an exit function to warn for any inconsistency that we * could create. */ - if (atexit (do_cleanups) != 0) { + if (atexit(do_cleanups) != 0) { fprintf(stderr, "%s: cannot set exit function\n", Prog); - exit (1); + exit(1); } /* Parse the options */ @@ -939,9 +939,9 @@ int main (int argc, char **argv) * Replicate the group so it can be modified later on. */ #ifdef SHADOWGRP - get_group (&grent, &sgent, &flags); + get_group(&grent, &sgent, &flags); #else - get_group (&grent, &flags); + get_group(&grent, &flags); #endif /* @@ -990,11 +990,11 @@ int main (int argc, char **argv) * well. Call the appropriate routine and split. */ if (aflg) { - printf (_("Adding user %s to group %s\n"), user, group); - grent.gr_mem = add_list (grent.gr_mem, user); + printf(_("Adding user %s to group %s\n"), user, group); + grent.gr_mem = add_list(grent.gr_mem, user); #ifdef SHADOWGRP if (is_shadowgrp) { - sgent.sg_mem = add_list (sgent.sg_mem, user); + sgent.sg_mem = add_list(sgent.sg_mem, user); } #endif goto output; @@ -1007,25 +1007,25 @@ int main (int argc, char **argv) if (dflg) { bool removed = false; - printf (_("Removing user %s from group %s\n"), user, group); + printf(_("Removing user %s from group %s\n"), user, group); - if (is_on_list (grent.gr_mem, user)) { + if (is_on_list(grent.gr_mem, user)) { removed = true; - grent.gr_mem = del_list (grent.gr_mem, user); + grent.gr_mem = del_list(grent.gr_mem, user); } #ifdef SHADOWGRP if (is_shadowgrp) { - if (is_on_list (sgent.sg_mem, user)) { + if (is_on_list(sgent.sg_mem, user)) { removed = true; - sgent.sg_mem = del_list (sgent.sg_mem, user); + sgent.sg_mem = del_list(sgent.sg_mem, user); } } #endif if (!removed) { - fprintf (stderr, + fprintf(stderr, _("%s: user '%s' is not a member of '%s'\n"), Prog, user, group); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } goto output; } @@ -1036,7 +1036,7 @@ int main (int argc, char **argv) * in place. */ if (Aflg) { - sgent.sg_adm = comma_to_list (admins); + sgent.sg_adm = comma_to_list(admins); if (!Mflg) { goto output; } @@ -1050,9 +1050,9 @@ int main (int argc, char **argv) */ if (Mflg) { #ifdef SHADOWGRP - sgent.sg_mem = comma_to_list (members); + sgent.sg_mem = comma_to_list(members); #endif - grent.gr_mem = comma_to_list (members); + grent.gr_mem = comma_to_list(members); goto output; } @@ -1061,9 +1061,9 @@ int main (int argc, char **argv) * be a tty. The typical keyboard signals are caught so the termio * modes can be restored. */ - if ((isatty (0) == 0) || (isatty (1) == 0)) { - fprintf (stderr, _("%s: Not a tty\n"), Prog); - exit (E_NOPERM); + if ((isatty(0) == 0) || (isatty(1) == 0)) { + fprintf(stderr, _("%s: Not a tty\n"), Prog); + exit(E_NOPERM); } catch_signals (0); /* save tty modes */ @@ -1076,9 +1076,9 @@ int main (int argc, char **argv) /* Prompt for the new password */ #ifdef SHADOWGRP - change_passwd (&grent, &sgent); + change_passwd(&grent, &sgent); #else - change_passwd (&grent); + change_passwd(&grent); #endif /* @@ -1088,26 +1088,26 @@ int main (int argc, char **argv) * output, etc. */ output: - if (setuid (0) != 0) { - fputs (_("Cannot change ID to root.\n"), stderr); + if (setuid(0) != 0) { + fputs(_("Cannot change ID to root.\n"), stderr); SYSLOG(LOG_ERR, "can't setuid(0)"); - closelog (); - exit (E_NOPERM); + closelog(); + exit(E_NOPERM); } - pwd_init (); + pwd_init(); - open_files (&flags); + open_files(&flags); #ifdef SHADOWGRP - update_group (&grent, &sgent); + update_group(&grent, &sgent); #else - update_group (&grent); + update_group(&grent); #endif - close_files (&flags); + close_files(&flags); - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_GROUP); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_GROUP); #ifdef SHADOWGRP if (is_shadowgrp) { @@ -1116,6 +1116,6 @@ int main (int argc, char **argv) } #endif free(grent.gr_mem); - exit (E_SUCCESS); + exit(E_SUCCESS); } diff --git a/src/groupadd.c b/src/groupadd.c index a2a13f066d..a65c79bdb8 100644 --- a/src/groupadd.c +++ b/src/groupadd.c @@ -100,29 +100,29 @@ static void check_flags (void); */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] GROUP\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -f, --force exit successfully if the group already exists,\n" + (void) fputs(_(" -f, --force exit successfully if the group already exists,\n" " and cancel -g if the GID is already used\n"), usageout); - (void) fputs (_(" -g, --gid GID use GID for the new group\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -K, --key KEY=VALUE override /etc/login.defs defaults\n"), usageout); - (void) fputs (_(" -o, --non-unique allow to create groups with duplicate\n" + (void) fputs(_(" -g, --gid GID use GID for the new group\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -K, --key KEY=VALUE override /etc/login.defs defaults\n"), usageout); + (void) fputs(_(" -o, --non-unique allow to create groups with duplicate\n" " (non-unique) GID\n"), usageout); - (void) fputs (_(" -p, --password PASSWORD use this encrypted password for the new group\n"), usageout); - (void) fputs (_(" -r, --system create a system account\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout); - (void) fputs (_(" -U, --users USERS comma-separated list of users to add as\n" + (void) fputs(_(" -p, --password PASSWORD use this encrypted password for the new group\n"), usageout); + (void) fputs(_(" -r, --system create a system account\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout); + (void) fputs(_(" -U, --users USERS comma-separated list of users to add as\n" " members of this group\n"), usageout); - (void) fputs ("\n", usageout); - exit (status); + (void) fputs("\n", usageout); + exit(status); } static void fail_exit(int status) @@ -131,7 +131,7 @@ static void fail_exit(int status) audit_logger(AUDIT_ADD_GROUP, "add-group", group_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); #endif - exit (status); + exit(status); } /* @@ -140,9 +140,9 @@ static void fail_exit(int status) * new_grent() takes all of the values that have been entered and fills * in a (struct group) with them. */ -static void new_grent (struct group *grent) +static void new_grent(struct group *grent) { - memzero(grent, sizeof(*grent)); + memzero(grent, sizeof (*grent)); grent->gr_name = group_name; if (pflg) { grent->gr_passwd = group_passwd; @@ -160,9 +160,9 @@ static void new_grent (struct group *grent) * new_sgent() takes all of the values that have been entered and fills * in a (struct sgrp) with them. */ -static void new_sgent (struct sgrp *sgent) +static void new_sgent(struct sgrp *sgent) { - memzero(sgent, sizeof(*sgent)); + memzero(sgent, sizeof (*sgent)); sgent->sg_namp = group_name; if (pflg) { sgent->sg_passwd = group_passwd; @@ -192,7 +192,7 @@ grp_update(void) * To add the group, we need to update /etc/group. * Make sure failures will be reported. */ - add_cleanup (cleanup_report_add_group_group, group_name); + add_cleanup(cleanup_report_add_group_group, group_name); #ifdef SHADOWGRP if (is_shadow_grp) { /* We also need to update /etc/gshadow */ @@ -203,9 +203,9 @@ grp_update(void) /* * Create the initial entries for this new group. */ - new_grent (&grp); + new_grent(&grp); #ifdef SHADOWGRP - new_sgent (&sgrp); + new_sgent(&sgrp); if (is_shadow_grp && pflg) { grp.gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ } @@ -232,21 +232,21 @@ grp_update(void) /* * Write out the new group file entry. */ - if (gr_update (&grp) == 0) { - fprintf (stderr, + if (gr_update(&grp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), grp.gr_name); - fail_exit (E_GRP_UPDATE); + Prog, gr_dbname(), grp.gr_name); + fail_exit(E_GRP_UPDATE); } #ifdef SHADOWGRP /* * Write out the new shadow group entries as well. */ - if (is_shadow_grp && (sgr_update (&sgrp) == 0)) { - fprintf (stderr, + if (is_shadow_grp && (sgr_update(&sgrp) == 0)) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), sgrp.sg_namp); - fail_exit (E_GRP_UPDATE); + Prog, sgr_dbname(), sgrp.sg_namp); + fail_exit(E_GRP_UPDATE); } #endif /* SHADOWGRP */ } @@ -264,7 +264,7 @@ check_new_name(void) fprintf(stderr, _("%s: '%s' is not a valid group name\n"), Prog, group_name); - fail_exit (E_BAD_ARG); + fail_exit(E_BAD_ARG); } return; @@ -304,23 +304,23 @@ static void close_files(const struct option_flags *flags) /* Now, write the changes in the shadow database */ #ifdef SHADOWGRP if (is_shadow_grp) { - if (sgr_close (process_selinux) == 0) { - fprintf (stderr, + if (sgr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, sgr_dbname ()); - fail_exit (E_GRP_UPDATE); + Prog, sgr_dbname()); + fail_exit(E_GRP_UPDATE); } #ifdef WITH_AUDIT - audit_logger (AUDIT_GRP_MGMT, + audit_logger(AUDIT_GRP_MGMT, "add-shadow-group", group_name, group_id, SHADOW_AUDIT_SUCCESS); #endif SYSLOG(LOG_INFO, "group added to %s: name=%s", sgr_dbname(), group_name); - del_cleanup (cleanup_report_add_group_gshadow); + del_cleanup(cleanup_report_add_group_gshadow); - cleanup_unlock_gshadow (&process_selinux); - del_cleanup (cleanup_unlock_gshadow); + cleanup_unlock_gshadow(&process_selinux); + del_cleanup(cleanup_unlock_gshadow); } #endif /* SHADOWGRP */ @@ -366,7 +366,7 @@ static void open_files(const struct option_flags *flags) * Now if the group is not added, it's our fault. * Make sure failures will be reported. */ - add_cleanup (cleanup_report_add_group, group_name); + add_cleanup(cleanup_report_add_group, group_name); /* And now open the databases */ if (gr_open (O_CREAT | O_RDWR) == 0) { @@ -393,7 +393,7 @@ static void open_files(const struct option_flags *flags) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { /* * Parse the command line options. @@ -414,7 +414,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "fg:hK:op:rR:P:U:", + while ((c = getopt_long(argc, argv, "fg:hK:op:rR:P:U:", long_options, NULL)) != -1) { switch (c) { case 'f': @@ -431,14 +431,14 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) gflg = true; if ( (get_gid(optarg, &group_id) == -1) || (group_id == (gid_t)-1)) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid group ID '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'K': /* @@ -448,13 +448,13 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) */ cp = stpsep(optarg, "="); if (NULL == cp) { - fprintf (stderr, + fprintf(stderr, _("%s: -K requires KEY=VALUE\n"), Prog); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } - if (putdef_str (optarg, cp, NULL) < 0) { - exit (E_BAD_ARG); + if (putdef_str(optarg, cp, NULL) < 0) { + exit(E_BAD_ARG); } break; case 'o': @@ -477,7 +477,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) user_list = optarg; break; default: - usage (E_USAGE); + usage(E_USAGE); } } @@ -485,11 +485,11 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * Check the flags consistency */ if (optind != argc - 1) { - usage (E_USAGE); + usage(E_USAGE); } group_name = argv[optind]; - check_flags (); + check_flags(); } /* @@ -497,7 +497,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * * It will not return if an error is encountered. */ -static void check_flags (void) +static void check_flags(void) { /* -o does not make sense without -g */ if (oflg && !gflg) { @@ -535,10 +535,10 @@ static void check_flags (void) /* Turn off -g, we can use any GID */ gflg = false; } else { - fprintf (stderr, + fprintf(stderr, _("%s: GID '%lu' already exists\n"), Prog, (unsigned long) group_id); - fail_exit (E_GID_IN_USE); + fail_exit(E_GID_IN_USE); } } } @@ -546,68 +546,68 @@ static void check_flags (void) /* * main - groupadd command */ -int main (int argc, char **argv) +int main(int argc, char **argv) { struct option_flags flags = {.chroot = false, .prefix = false}; log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); - prefix = process_prefix_flag ("-P", argc, argv); + process_root_flag("-R", argc, argv); + prefix = process_prefix_flag("-P", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); #ifdef WITH_AUDIT - audit_help_open (); + audit_help_open(); #endif - if (atexit (do_cleanups) != 0) { - fprintf (stderr, + if (atexit(do_cleanups) != 0) { + fprintf(stderr, _("%s: Cannot setup cleanup service.\n"), Prog); - fail_exit (1); + fail_exit(1); } /* * Parse the command line options. */ - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); - if (run_parts ("/etc/shadow-maint/groupadd-pre.d", group_name, + if (run_parts("/etc/shadow-maint/groupadd-pre.d", group_name, Prog)) { exit(1); } #ifdef SHADOWGRP - is_shadow_grp = sgr_file_present (); + is_shadow_grp = sgr_file_present(); #endif /* * Do the hard stuff - open the files, create the group entries, * then close and update the files. */ - open_files (&flags); + open_files(&flags); if (!gflg) { - if (find_new_gid (rflg, &group_id, NULL) < 0) { - fail_exit (E_GID_IN_USE); + if (find_new_gid(rflg, &group_id, NULL) < 0) { + fail_exit(E_GID_IN_USE); } } - grp_update (); - close_files (&flags); - if (run_parts ("/etc/shadow-maint/groupadd-post.d", group_name, + grp_update(); + close_files(&flags); + if (run_parts("/etc/shadow-maint/groupadd-post.d", group_name, Prog)) { exit(1); } - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_GROUP); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_GROUP); return E_SUCCESS; } diff --git a/src/groupdel.c b/src/groupdel.c index 0df511719c..875fdfbacc 100644 --- a/src/groupdel.c +++ b/src/groupdel.c @@ -60,28 +60,28 @@ static bool is_shadow_grp; #define E_GRP_UPDATE 10 /* can't update group file */ /* local function prototypes */ -NORETURN static void usage (int status); -static void grp_update (void); +NORETURN static void usage(int status); +static void grp_update(void); static void close_files(const struct option_flags *flags); static void open_files(const struct option_flags *flags); -static void group_busy (gid_t gid); -static void process_flags (int argc, char **argv, struct option_flags *flags); +static void group_busy(gid_t gid); +static void process_flags(int argc, char **argv, struct option_flags *flags); /* * usage - display usage message and exit */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] GROUP\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout); (void) fputs (_(" -f, --force delete group even if it is the primary group of a user\n"), usageout); (void) fputs ("\n", usageout); @@ -102,13 +102,13 @@ static void fail_exit(int status) * * grp_update() writes the new records to the group files. */ -static void grp_update (void) +static void grp_update(void) { /* * To add the group, we need to update /etc/group. * Make sure failures will be reported. */ - add_cleanup (cleanup_report_del_group_group, group_name); + add_cleanup(cleanup_report_del_group_group, group_name); #ifdef SHADOWGRP if (is_shadow_grp) { /* We also need to update /etc/gshadow */ @@ -119,23 +119,23 @@ static void grp_update (void) /* * Delete the group entry. */ - if (gr_remove (group_name) == 0) { - fprintf (stderr, + if (gr_remove(group_name) == 0) { + fprintf(stderr, _("%s: cannot remove entry '%s' from %s\n"), - Prog, group_name, gr_dbname ()); - fail_exit (E_GRP_UPDATE); + Prog, group_name, gr_dbname()); + fail_exit(E_GRP_UPDATE); } #ifdef SHADOWGRP /* * Delete the shadow group entries as well. */ - if (is_shadow_grp && (sgr_locate (group_name) != NULL)) { - if (sgr_remove (group_name) == 0) { - fprintf (stderr, + if (is_shadow_grp && (sgr_locate(group_name) != NULL)) { + if (sgr_remove(group_name) == 0) { + fprintf(stderr, _("%s: cannot remove entry '%s' from %s\n"), - Prog, group_name, sgr_dbname ()); - fail_exit (E_GRP_UPDATE); + Prog, group_name, sgr_dbname()); + fail_exit(E_GRP_UPDATE); } } #endif /* SHADOWGRP */ @@ -176,28 +176,28 @@ static void close_files(const struct option_flags *flags) /* Then, write the changes in the shadow database */ #ifdef SHADOWGRP if (is_shadow_grp) { - if (sgr_close (process_selinux) == 0) { - fprintf (stderr, + if (sgr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, sgr_dbname ()); - fail_exit (E_GRP_UPDATE); + Prog, sgr_dbname()); + fail_exit(E_GRP_UPDATE); } #ifdef WITH_AUDIT - audit_logger (AUDIT_GRP_MGMT, + audit_logger(AUDIT_GRP_MGMT, "delete-shadow-group", group_name, group_id, SHADOW_AUDIT_SUCCESS); #endif SYSLOG(LOG_INFO, "group '%s' removed from %s", group_name, sgr_dbname()); - del_cleanup (cleanup_report_del_group_gshadow); + del_cleanup(cleanup_report_del_group_gshadow); - cleanup_unlock_gshadow (&process_selinux); - del_cleanup (cleanup_unlock_gshadow); + cleanup_unlock_gshadow(&process_selinux); + del_cleanup(cleanup_unlock_gshadow); } #endif /* SHADOWGRP */ SYSLOG(LOG_INFO, "group '%s' removed\n", group_name); - del_cleanup (cleanup_report_del_group); + del_cleanup(cleanup_report_del_group); } /* @@ -235,7 +235,7 @@ static void open_files(const struct option_flags *flags) * Now, if the group is not removed, it's our fault. * Make sure failures will be reported. */ - add_cleanup (cleanup_report_del_group, group_name); + add_cleanup(cleanup_report_del_group, group_name); /* An now open the databases */ if (gr_open (O_CREAT | O_RDWR) == 0) { @@ -265,7 +265,7 @@ static void open_files(const struct option_flags *flags) * for any user. You must remove all users before you remove * the group. */ -static void group_busy (gid_t gid) +static void group_busy(gid_t gid) { struct passwd *pwd; @@ -273,11 +273,11 @@ static void group_busy (gid_t gid) * Nice slow linear search. */ - prefix_setpwent (); + prefix_setpwent(); - while ( ((pwd = prefix_getpwent ()) != NULL) && (pwd->pw_gid != gid) ); + while ( ((pwd = prefix_getpwent()) != NULL) && (pwd->pw_gid != gid) ); - prefix_endpwent (); + prefix_endpwent(); /* * If pwd isn't NULL, it stopped because the gid's matched. @@ -290,10 +290,10 @@ static void group_busy (gid_t gid) /* * Can't remove the group. */ - fprintf (stderr, + fprintf(stderr, _("%s: cannot remove the primary group of user '%s'\n"), Prog, pwd->pw_name); - fail_exit (E_GROUP_BUSY); + fail_exit(E_GROUP_BUSY); } /* @@ -301,7 +301,7 @@ static void group_busy (gid_t gid) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { /* * Parse the command line options. @@ -315,11 +315,11 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "hfR:P:", + while ((c = getopt_long(argc, argv, "hfR:P:", long_options, NULL)) != -1) { switch (c) { case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ flags->chroot = true; @@ -351,37 +351,37 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * The named group will be deleted. */ -int main (int argc, char **argv) +int main(int argc, char **argv) { struct option_flags flags = {.chroot = false, .prefix = false}; log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); - prefix = process_prefix_flag ("-P", argc, argv); + process_root_flag("-R", argc, argv); + prefix = process_prefix_flag("-P", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); #ifdef WITH_AUDIT - audit_help_open (); + audit_help_open(); #endif - if (atexit (do_cleanups) != 0) { - fprintf (stderr, + if (atexit(do_cleanups) != 0) { + fprintf(stderr, _("%s: Cannot setup cleanup service.\n"), Prog); - fail_exit (1); + fail_exit(1); } - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); #ifdef SHADOWGRP - is_shadow_grp = sgr_file_present (); + is_shadow_grp = sgr_file_present(); #endif { @@ -404,10 +404,10 @@ int main (int argc, char **argv) * Make sure this isn't the primary group of anyone. */ if (check_group_busy) { - group_busy (group_id); + group_busy(group_id); } - if (run_parts ("/etc/shadow-maint/groupdel-pre.d", group_name, + if (run_parts("/etc/shadow-maint/groupdel-pre.d", group_name, Prog)) { exit(1); } @@ -416,19 +416,19 @@ int main (int argc, char **argv) * Do the hard stuff - open the files, delete the group entries, * then close and update the files. */ - open_files (&flags); + open_files(&flags); - grp_update (); + grp_update(); - close_files (&flags); + close_files(&flags); - if (run_parts ("/etc/shadow-maint/groupdel-post.d", group_name, + if (run_parts("/etc/shadow-maint/groupdel-post.d", group_name, Prog)) { exit(1); } - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_GROUP); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_GROUP); return E_SUCCESS; } diff --git a/src/groupmems.c b/src/groupmems.c index 88054bb704..9550dfb676 100644 --- a/src/groupmems.c +++ b/src/groupmems.c @@ -91,7 +91,7 @@ NORETURN static void fail_exit (int code, bool process_selinux); static char *whoami (void) { /* local, no need for xgetgrgid */ - struct group *grp = getgrgid (getgid ()); + struct group *grp = getgrgid(getgid()); /* local, no need for xgetpwuid */ struct passwd *usr = getpwuid (getuid ()); @@ -107,7 +107,7 @@ static char *whoami (void) /* * add_user - Add a user to the specified group */ -static void add_user (const char *user, +static void add_user(const char *user, const struct group *grp, bool process_selinux) { @@ -130,11 +130,11 @@ static void add_user (const char *user, } /* Add the user to the /etc/group group */ - newgrp->gr_mem = add_list (newgrp->gr_mem, user); + newgrp->gr_mem = add_list(newgrp->gr_mem, user); #ifdef SHADOWGRP if (is_shadowgrp) { - const struct sgrp *sg = sgr_locate (newgrp->gr_name); + const struct sgrp *sg = sgr_locate(newgrp->gr_name); struct sgrp *newsg; if (NULL == sg) { @@ -151,39 +151,39 @@ static void add_user (const char *user, newsg = &sgrent; } else { - newsg = __sgr_dup (sg); + newsg = __sgr_dup(sg); if (NULL == newsg) { - fprintf (stderr, + fprintf(stderr, _("%s: Out of memory. Cannot update %s.\n"), - Prog, sgr_dbname ()); - fail_exit (13, process_selinux); + Prog, sgr_dbname()); + fail_exit(13, process_selinux); } /* Add the user to the members */ newsg->sg_mem = add_list (newsg->sg_mem, user); /* Do not touch the administrators */ } - if (sgr_update (newsg) == 0) { - fprintf (stderr, + if (sgr_update(newsg) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), newsg->sg_namp); - fail_exit (13, process_selinux); + Prog, sgr_dbname(), newsg->sg_namp); + fail_exit(13, process_selinux); } } #endif - if (gr_update (newgrp) == 0) { - fprintf (stderr, + if (gr_update(newgrp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), newgrp->gr_name); - fail_exit (13, process_selinux); + Prog, gr_dbname(), newgrp->gr_name); + fail_exit(13, process_selinux); } } /* * remove_user - Remove a user from a given group */ -static void remove_user (const char *user, +static void remove_user(const char *user, const struct group *grp, bool process_selinux) { @@ -206,11 +206,11 @@ static void remove_user (const char *user, } /* Remove the user from the /etc/group group */ - newgrp->gr_mem = del_list (newgrp->gr_mem, user); + newgrp->gr_mem = del_list(newgrp->gr_mem, user); #ifdef SHADOWGRP if (is_shadowgrp) { - const struct sgrp *sg = sgr_locate (newgrp->gr_name); + const struct sgrp *sg = sgr_locate(newgrp->gr_name); struct sgrp *newsg; if (NULL == sg) { @@ -227,48 +227,48 @@ static void remove_user (const char *user, newsg = &sgrent; } else { - newsg = __sgr_dup (sg); + newsg = __sgr_dup(sg); if (NULL == newsg) { - fprintf (stderr, + fprintf(stderr, _("%s: Out of memory. Cannot update %s.\n"), - Prog, sgr_dbname ()); - fail_exit (13, process_selinux); + Prog, sgr_dbname()); + fail_exit(13, process_selinux); } /* Remove the user from the members */ newsg->sg_mem = del_list (newsg->sg_mem, user); /* Remove the user from the administrators */ - newsg->sg_adm = del_list (newsg->sg_adm, user); + newsg->sg_adm = del_list(newsg->sg_adm, user); } - if (sgr_update (newsg) == 0) { - fprintf (stderr, + if (sgr_update(newsg) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), newsg->sg_namp); - fail_exit (13, process_selinux); + Prog, sgr_dbname(), newsg->sg_namp); + fail_exit(13, process_selinux); } } #endif - if (gr_update (newgrp) == 0) { - fprintf (stderr, + if (gr_update(newgrp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), newgrp->gr_name); - fail_exit (13, process_selinux); + Prog, gr_dbname(), newgrp->gr_name); + fail_exit(13, process_selinux); } } /* * purge_members - Remove every members of the specified group */ -static void purge_members (const struct group *grp, bool process_selinux) +static void purge_members(const struct group *grp, bool process_selinux) { - struct group *newgrp = __gr_dup (grp); + struct group *newgrp = __gr_dup(grp); if (NULL == newgrp) { - fprintf (stderr, + fprintf(stderr, _("%s: Out of memory. Cannot update %s.\n"), - Prog, gr_dbname ()); - fail_exit (13, process_selinux); + Prog, gr_dbname()); + fail_exit(13, process_selinux); } /* Remove all the members of the /etc/group group */ @@ -282,7 +282,7 @@ static void purge_members (const struct group *grp, bool process_selinux) if (NULL == sg) { /* Create a shadow group based on this group */ static struct sgrp sgrent; - sgrent.sg_namp = xstrdup (newgrp->gr_name); + sgrent.sg_namp = xstrdup(newgrp->gr_name); sgrent.sg_mem = xmalloc_T(1, char *); sgrent.sg_mem[0] = NULL; sgrent.sg_adm = xmalloc_T(1, char *); @@ -309,65 +309,65 @@ static void purge_members (const struct group *grp, bool process_selinux) newsg->sg_adm[0] = NULL; } - if (sgr_update (newsg) == 0) { - fprintf (stderr, + if (sgr_update(newsg) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), newsg->sg_namp); - fail_exit (13, process_selinux); + Prog, sgr_dbname(), newsg->sg_namp); + fail_exit(13, process_selinux); } } #endif - if (gr_update (newgrp) == 0) { - fprintf (stderr, + if (gr_update(newgrp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), newgrp->gr_name); - fail_exit (13, process_selinux); + Prog, gr_dbname(), newgrp->gr_name); + fail_exit(13, process_selinux); } } -static void display_members (const char *const *members) +static void display_members(const char *const *members) { int i; for (i = 0; NULL != members[i]; i++) { - printf ("%s ", members[i]); + printf("%s ", members[i]); if (NULL == members[i + 1]) { - printf ("\n"); + printf("\n"); } else { - printf (" "); + printf(" "); } } } NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (EXIT_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] [action]\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -g, --group groupname change groupname instead of the user's group\n" + (void) fputs(_(" -g, --group groupname change groupname instead of the user's group\n" " (root only)\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_("\n"), usageout); - (void) fputs (_("Actions:\n"), usageout); - (void) fputs (_(" -a, --add username add username to the members of the group\n"), usageout); - (void) fputs (_(" -d, --delete username remove username from the members of the group\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -p, --purge purge all members from the group\n"), usageout); - (void) fputs (_(" -l, --list list the members of the group\n"), usageout); - exit (status); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_("\n"), usageout); + (void) fputs(_("Actions:\n"), usageout); + (void) fputs(_(" -a, --add username add username to the members of the group\n"), usageout); + (void) fputs(_(" -d, --delete username remove username from the members of the group\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -p, --purge purge all members from the group\n"), usageout); + (void) fputs(_(" -l, --list list the members of the group\n"), usageout); + exit(status); } /* * process_flags - perform command line argument setting */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { int c; static struct option long_options[] = { @@ -381,22 +381,22 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "a:d:g:hlpR:", + while ((c = getopt_long(argc, argv, "a:d:g:hlpR:", long_options, NULL)) != EOF) { switch (c) { case 'a': - adduser = xstrdup (optarg); + adduser = xstrdup(optarg); ++exclusive; break; case 'd': - deluser = xstrdup (optarg); + deluser = xstrdup(optarg); ++exclusive; break; case 'g': - thisgroup = xstrdup (optarg); + thisgroup = xstrdup(optarg); break; case 'h': - usage (EXIT_SUCCESS); + usage(EXIT_SUCCESS); /*@notreached@*/break; case 'l': list = true; @@ -410,12 +410,12 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) flags->chroot = true; break; default: - usage (EXIT_USAGE); + usage(EXIT_USAGE); } } if ((exclusive > 1) || (optind < argc)) { - usage (EXIT_USAGE); + usage(EXIT_USAGE); } /* local, no need for xgetpwnam */ @@ -439,43 +439,43 @@ check_perms(MAYBE_UNUSED bool process_selinux) pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */ if (NULL == pampw) { - fprintf (stderr, + fprintf(stderr, _("%s: Cannot determine your user name.\n"), Prog); - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } - retval = pam_start (Prog, pampw->pw_name, &conv, &pamh); + retval = pam_start(Prog, pampw->pw_name, &conv, &pamh); if (PAM_SUCCESS == retval) { - retval = pam_authenticate (pamh, 0); + retval = pam_authenticate(pamh, 0); } if (PAM_SUCCESS == retval) { - retval = pam_acct_mgmt (pamh, 0); + retval = pam_acct_mgmt(pamh, 0); } if (PAM_SUCCESS != retval) { - fprintf (stderr, _("%s: PAM: %s\n"), - Prog, pam_strerror (pamh, retval)); + fprintf(stderr, _("%s: PAM: %s\n"), + Prog, pam_strerror(pamh, retval)); SYSLOG(LOG_ERR, "%s", pam_strerror(pamh, retval)); if (NULL != pamh) { - (void) pam_end (pamh, retval); + (void) pam_end(pamh, retval); } - fail_exit (1, process_selinux); + fail_exit(1, process_selinux); } - (void) pam_end (pamh, retval); + (void) pam_end(pamh, retval); #endif } } -static void fail_exit (int code, bool process_selinux) +static void fail_exit(int code, bool process_selinux) { if (gr_locked) { - if (gr_unlock (process_selinux) == 0) { - fprintf (stderr, + if (gr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), - Prog, gr_dbname ()); + Prog, gr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", gr_dbname()); /* continue */ } @@ -493,43 +493,43 @@ static void fail_exit (int code, bool process_selinux) } #endif - exit (code); + exit(code); } -static void open_files (bool process_selinux) +static void open_files(bool process_selinux) { if (!list) { - if (gr_lock () == 0) { - fprintf (stderr, + if (gr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, gr_dbname ()); - fail_exit (EXIT_GROUP_FILE, process_selinux); + Prog, gr_dbname()); + fail_exit(EXIT_GROUP_FILE, process_selinux); } gr_locked = true; #ifdef SHADOWGRP if (is_shadowgrp) { - if (sgr_lock () == 0) { - fprintf (stderr, + if (sgr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sgr_dbname ()); - fail_exit (EXIT_GROUP_FILE, process_selinux); + Prog, sgr_dbname()); + fail_exit(EXIT_GROUP_FILE, process_selinux); } sgr_locked = true; } #endif } - if (gr_open (list ? O_RDONLY : O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); - fail_exit (EXIT_GROUP_FILE, process_selinux); + if (gr_open(list ? O_RDONLY : O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, gr_dbname()); + fail_exit(EXIT_GROUP_FILE, process_selinux); } #ifdef SHADOWGRP if (is_shadowgrp) { - if (sgr_open (list ? O_RDONLY : O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ()); - fail_exit (EXIT_GROUP_FILE, process_selinux); + if (sgr_open(list ? O_RDONLY : O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname()); + fail_exit(EXIT_GROUP_FILE, process_selinux); } } #endif @@ -541,14 +541,14 @@ static void close_files(const struct option_flags *flags) process_selinux = !flags->chroot; - if ((gr_close (process_selinux) == 0) && !list) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); + if ((gr_close(process_selinux) == 0) && !list) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", gr_dbname()); - fail_exit (EXIT_GROUP_FILE, process_selinux); + fail_exit(EXIT_GROUP_FILE, process_selinux); } if (gr_locked) { - if (gr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + if (gr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", gr_dbname()); /* continue */ } @@ -574,7 +574,7 @@ static void close_files(const struct option_flags *flags) #endif } -int main (int argc, char **argv) +int main(int argc, char **argv) { char *name; const struct group *grp; @@ -584,58 +584,58 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); #ifdef SHADOWGRP - is_shadowgrp = sgr_file_present (); + is_shadowgrp = sgr_file_present(); #endif - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); process_selinux = !flags.chroot; if (NULL == thisgroup) { - name = whoami (); + name = whoami(); if (!list && (NULL == name)) { - fprintf (stderr, _("%s: your groupname does not match your username\n"), Prog); - fail_exit (EXIT_NOT_PRIMARY, process_selinux); + fprintf(stderr, _("%s: your groupname does not match your username\n"), Prog); + fail_exit(EXIT_NOT_PRIMARY, process_selinux); } } else { name = thisgroup; - if (!list && !isroot ()) { - fprintf (stderr, _("%s: only root can use the -g/--group option\n"), Prog); - fail_exit (EXIT_NOT_ROOT, process_selinux); + if (!list && !isroot()) { + fprintf(stderr, _("%s: only root can use the -g/--group option\n"), Prog); + fail_exit(EXIT_NOT_ROOT, process_selinux); } } - check_perms (process_selinux); + check_perms(process_selinux); - open_files (process_selinux); + open_files(process_selinux); - grp = gr_locate (name); + grp = gr_locate(name); if (NULL == grp) { - fprintf (stderr, _("%s: group '%s' does not exist in %s\n"), - Prog, name, gr_dbname ()); - fail_exit (EXIT_INVALID_GROUP, process_selinux); + fprintf(stderr, _("%s: group '%s' does not exist in %s\n"), + Prog, name, gr_dbname()); + fail_exit(EXIT_INVALID_GROUP, process_selinux); } if (list) { - display_members ((const char *const *)grp->gr_mem); + display_members((const char *const *)grp->gr_mem); } else if (NULL != adduser) { - add_user (adduser, grp, process_selinux); + add_user(adduser, grp, process_selinux); } else if (NULL != deluser) { - remove_user (deluser, grp, process_selinux); + remove_user(deluser, grp, process_selinux); } else if (purge) { - purge_members (grp, process_selinux); + purge_members(grp, process_selinux); } - close_files (&flags); + close_files(&flags); - exit (EXIT_SUCCESS); + exit(EXIT_SUCCESS); } diff --git a/src/groupmod.c b/src/groupmod.c index b019c0103e..174daae45d 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -92,44 +92,44 @@ static bool pflg = false; /* new encrypted password */ /* local function prototypes */ -static void usage (int status); -static void new_grent (struct group *); +static void usage(int status); +static void new_grent(struct group *); #ifdef SHADOWGRP -static void new_sgent (struct sgrp *); +static void new_sgent(struct sgrp *); #endif -static void grp_update (void); -static void check_new_gid (void); -static void check_new_name (void); -static void process_flags (int, char **, struct option_flags *); +static void grp_update(void); +static void check_new_gid(void); +static void check_new_name(void); +static void process_flags(int, char **, struct option_flags *); static void lock_files(const struct option_flags *flags); -static void prepare_failure_reports (void); -static void open_files (void); +static void prepare_failure_reports(void); +static void open_files(void); static void close_files(const struct option_flags *flags); -static void update_primary_groups (gid_t ogid, gid_t ngid); +static void update_primary_groups(gid_t ogid, gid_t ngid); /* * usage - display usage message and exit */ -static void usage (int status) +static void usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] GROUP\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -a, --append append the users mentioned by -U option to the group \n" + (void) fputs(_(" -a, --append append the users mentioned by -U option to the group \n" " without removing existing user members\n"), usageout); - (void) fputs (_(" -g, --gid GID change the group ID to GID\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -n, --new-name NEW_GROUP change the name to NEW_GROUP\n"), usageout); - (void) fputs (_(" -o, --non-unique allow to use a duplicate (non-unique) GID\n"), usageout); - (void) fputs (_(" -p, --password PASSWORD change the password to this (encrypted)\n" + (void) fputs(_(" -g, --gid GID change the group ID to GID\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -n, --new-name NEW_GROUP change the name to NEW_GROUP\n"), usageout); + (void) fputs(_(" -o, --non-unique allow to use a duplicate(non-unique) GID\n"), usageout); + (void) fputs(_(" -p, --password PASSWORD change the password to this(encrypted)\n" " PASSWORD\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout); (void) fputs (_(" -U, --users USERS comma-separated list of users to add as\n" " members of this group\n"), usageout); @@ -143,10 +143,10 @@ static void usage (int status) * new_grent() takes all of the values that have been entered and fills * in a (struct group) with them. */ -static void new_grent (struct group *grent) +static void new_grent(struct group *grent) { if (nflg) { - grent->gr_name = xstrdup (group_newname); + grent->gr_name = xstrdup(group_newname); } if (gflg) { @@ -175,10 +175,10 @@ static void new_grent (struct group *grent) * new_sgent() takes all of the values that have been entered and fills * in a (struct sgrp) with them. */ -static void new_sgent (struct sgrp *sgent) +static void new_sgent(struct sgrp *sgent) { if (nflg) { - sgent->sg_namp = xstrdup (group_newname); + sgent->sg_namp = xstrdup(group_newname); } /* Always update the shadowed password if there is a shadow entry @@ -213,22 +213,22 @@ grp_update(void) /* * Get the current settings for this group. */ - ogrp = gr_locate (group_name); + ogrp = gr_locate(group_name); if (NULL == ogrp) { - fprintf (stderr, + fprintf(stderr, _("%s: group '%s' does not exist in %s\n"), - Prog, group_name, gr_dbname ()); - exit (E_GRP_UPDATE); + Prog, group_name, gr_dbname()); + exit(E_GRP_UPDATE); } grp = *ogrp; - new_grent (&grp); + new_grent(&grp); #ifdef SHADOWGRP if ( is_shadow_grp && (pflg || nflg || user_list)) { - osgrp = sgr_locate (group_name); + osgrp = sgr_locate(group_name); if (NULL != osgrp) { sgrp = *osgrp; - new_sgent (&sgrp); + new_sgent(&sgrp); } else if ( pflg && streq(grp.gr_passwd, SHADOW_PASSWD_STRING)) { static char *empty = NULL; @@ -237,12 +237,12 @@ grp_update(void) * shadowed password, we force the creation of a * gshadow entry when a new password is requested. */ - bzero(&sgrp, sizeof(sgrp)); - sgrp.sg_namp = xstrdup (grp.gr_name); - sgrp.sg_passwd = xstrdup (grp.gr_passwd); + bzero(&sgrp, sizeof (sgrp)); + sgrp.sg_namp = xstrdup(grp.gr_name); + sgrp.sg_passwd = xstrdup(grp.gr_passwd); sgrp.sg_adm = ∅ - sgrp.sg_mem = dup_list (grp.gr_mem); - new_sgent (&sgrp); + sgrp.sg_mem = dup_list(grp.gr_mem); + new_sgent(&sgrp); osgrp = &sgrp; /* entry needs to be committed */ } } @@ -296,17 +296,17 @@ grp_update(void) /* * Write out the new group file entry. */ - if (gr_update (&grp) == 0) { - fprintf (stderr, + if (gr_update(&grp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), grp.gr_name); - exit (E_GRP_UPDATE); + Prog, gr_dbname(), grp.gr_name); + exit(E_GRP_UPDATE); } - if (nflg && (gr_remove (group_name) == 0)) { - fprintf (stderr, + if (nflg && (gr_remove(group_name) == 0)) { + fprintf(stderr, _("%s: cannot remove entry '%s' from %s\n"), - Prog, grp.gr_name, gr_dbname ()); - exit (E_GRP_UPDATE); + Prog, grp.gr_name, gr_dbname()); + exit(E_GRP_UPDATE); } #ifdef SHADOWGRP @@ -317,17 +317,17 @@ grp_update(void) /* * Write out the new shadow group entries as well. */ - if (sgr_update (&sgrp) == 0) { - fprintf (stderr, + if (sgr_update(&sgrp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), sgrp.sg_namp); - exit (E_GRP_UPDATE); + Prog, sgr_dbname(), sgrp.sg_namp); + exit(E_GRP_UPDATE); } - if (nflg && (sgr_remove (group_name) == 0)) { - fprintf (stderr, + if (nflg && (sgr_remove(group_name) == 0)) { + fprintf(stderr, _("%s: cannot remove entry '%s' from %s\n"), - Prog, group_name, sgr_dbname ()); - exit (E_GRP_UPDATE); + Prog, group_name, sgr_dbname()); + exit(E_GRP_UPDATE); } } #endif /* SHADOWGRP */ @@ -338,7 +338,7 @@ grp_update(void) * * check_new_gid() insures that the new GID value is unique. */ -static void check_new_gid (void) +static void check_new_gid(void) { /* * First, the easy stuff. If the ID can be duplicated, or if the ID @@ -359,10 +359,10 @@ static void check_new_gid (void) /* * Tell the user what they did wrong. */ - fprintf (stderr, + fprintf(stderr, _("%s: GID '%lu' already exists\n"), Prog, (unsigned long) group_newid); - exit (E_GID_IN_USE); + exit(E_GID_IN_USE); } /* @@ -407,7 +407,7 @@ check_new_name(void) * values that the user will be created with accordingly. The values * are checked for sanity. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { int c; static struct option long_options[] = { @@ -422,7 +422,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {"users", required_argument, NULL, 'U'}, {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "ag:hn:op:R:P:U:", + while ((c = getopt_long(argc, argv, "ag:hn:op:R:P:U:", long_options, NULL)) != -1) { switch (c) { case 'a': @@ -432,14 +432,14 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) gflg = true; if ( (get_gid(optarg, &group_newid) == -1) || (group_newid == (gid_t)-1)) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid group ID '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); break; case 'n': nflg = true; @@ -462,16 +462,16 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) user_list = optarg; break; default: - usage (E_USAGE); + usage(E_USAGE); } } if (oflg && !gflg) { - usage (E_USAGE); + usage(E_USAGE); } if (optind != (argc - 1)) { - usage (E_USAGE); + usage(E_USAGE); } group_name = argv[argc - 1]; @@ -489,32 +489,32 @@ static void close_files(const struct option_flags *flags) process_selinux = !flags->chroot && !flags->prefix; - if (gr_close (process_selinux) == 0) { - fprintf (stderr, + if (gr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, gr_dbname ()); - exit (E_GRP_UPDATE); + Prog, gr_dbname()); + exit(E_GRP_UPDATE); } #ifdef WITH_AUDIT - audit_logger (AUDIT_GRP_MGMT, + audit_logger(AUDIT_GRP_MGMT, info_group.audit_msg, group_name, AUDIT_NO_ID, SHADOW_AUDIT_SUCCESS); #endif - SYSLOG(LOG_INFO, "group changed in %s (%s)", gr_dbname(), info_group.action); - del_cleanup (cleanup_report_mod_group); + SYSLOG(LOG_INFO, "group changed in %s(%s)", gr_dbname(), info_group.action); + del_cleanup(cleanup_report_mod_group); - cleanup_unlock_group (&process_selinux); - del_cleanup (cleanup_unlock_group); + cleanup_unlock_group(&process_selinux); + del_cleanup(cleanup_unlock_group); #ifdef SHADOWGRP if ( is_shadow_grp && (pflg || nflg || user_list)) { - if (sgr_close (process_selinux) == 0) { - fprintf (stderr, + if (sgr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, sgr_dbname ()); - exit (E_GRP_UPDATE); + Prog, sgr_dbname()); + exit(E_GRP_UPDATE); } #ifdef WITH_AUDIT /* If both happened, log password change as its more important */ @@ -571,7 +571,7 @@ static void close_files(const struct option_flags *flags) * prepare_failure_reports - Prepare the cleanup_info structure for logging * of success and failure to syslog or audit. */ -static void prepare_failure_reports (void) +static void prepare_failure_reports(void) { char *gr, *gr_end; #ifdef SHADOWGRP @@ -597,11 +597,11 @@ static void prepare_failure_reports (void) info_passwd.audit_msg = pw; pw_end = pw + 512; - gr = stpeprintf(gr, gr_end, "changing %s; ", gr_dbname ()); + gr = stpeprintf(gr, gr_end, "changing %s; ", gr_dbname()); #ifdef SHADOWGRP - sgr = stpeprintf(sgr, sgr_end, "changing %s; ", sgr_dbname ()); + sgr = stpeprintf(sgr, sgr_end, "changing %s; ", sgr_dbname()); #endif - pw = stpeprintf(pw, pw_end, "changing %s; ", pw_dbname ()); + pw = stpeprintf(pw, pw_end, "changing %s; ", pw_dbname()); info_group.action = gr; #ifdef SHADOWGRP @@ -643,15 +643,15 @@ static void prepare_failure_reports (void) } // FIXME: add a system cleanup - add_cleanup (cleanup_report_mod_group, &info_group); + add_cleanup(cleanup_report_mod_group, &info_group); #ifdef SHADOWGRP if ( is_shadow_grp && (pflg || nflg || user_list)) { - add_cleanup (cleanup_report_mod_gshadow, &info_gshadow); + add_cleanup(cleanup_report_mod_gshadow, &info_gshadow); } #endif if (gflg) { - add_cleanup (cleanup_report_mod_passwd, &info_passwd); + add_cleanup(cleanup_report_mod_passwd, &info_passwd); } } @@ -667,35 +667,35 @@ static void lock_files(const struct option_flags *flags) process_selinux = !flags->chroot && !flags->prefix; - if (gr_lock () == 0) { - fprintf (stderr, + if (gr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, gr_dbname ()); - exit (E_GRP_UPDATE); + Prog, gr_dbname()); + exit(E_GRP_UPDATE); } - add_cleanup (cleanup_unlock_group, &process_selinux); + add_cleanup(cleanup_unlock_group, &process_selinux); #ifdef SHADOWGRP if ( is_shadow_grp && (pflg || nflg || user_list)) { - if (sgr_lock () == 0) { - fprintf (stderr, + if (sgr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sgr_dbname ()); - exit (E_GRP_UPDATE); + Prog, sgr_dbname()); + exit(E_GRP_UPDATE); } - add_cleanup (cleanup_unlock_gshadow, &process_selinux); + add_cleanup(cleanup_unlock_gshadow, &process_selinux); } #endif if (gflg) { - if (pw_lock () == 0) { - fprintf (stderr, + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - exit (E_GRP_UPDATE); + Prog, pw_dbname()); + exit(E_GRP_UPDATE); } - add_cleanup (cleanup_unlock_passwd, &process_selinux); + add_cleanup(cleanup_unlock_passwd, &process_selinux); } } @@ -705,102 +705,102 @@ static void lock_files(const struct option_flags *flags) * * open_files() opens the group, gshadow, and passwd databases. */ -static void open_files (void) +static void open_files(void) { - if (gr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); + if (gr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, gr_dbname()); SYSLOG(LOG_WARN, "cannot open %s", gr_dbname()); - exit (E_GRP_UPDATE); + exit(E_GRP_UPDATE); } #ifdef SHADOWGRP if ( is_shadow_grp && (pflg || nflg || user_list)) { - if (sgr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (sgr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, sgr_dbname ()); + Prog, sgr_dbname()); SYSLOG(LOG_WARN, "cannot open %s", sgr_dbname()); - exit (E_GRP_UPDATE); + exit(E_GRP_UPDATE); } } #endif /* SHADOWGRP */ if (gflg) { - if (pw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (pw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, pw_dbname ()); + Prog, pw_dbname()); SYSLOG(LOG_WARN, "cannot open %s", gr_dbname()); - exit (E_GRP_UPDATE); + exit(E_GRP_UPDATE); } } } -void update_primary_groups (gid_t ogid, gid_t ngid) +void update_primary_groups(gid_t ogid, gid_t ngid) { struct passwd *pwd; - prefix_setpwent (); + prefix_setpwent(); while (NULL != (pwd = prefix_getpwent())) { if (pwd->pw_gid == ogid) { const struct passwd *lpwd; struct passwd npwd; - lpwd = pw_locate (pwd->pw_name); + lpwd = pw_locate(pwd->pw_name); if (NULL == lpwd) { - fprintf (stderr, + fprintf(stderr, _("%s: user '%s' does not exist in %s\n"), - Prog, pwd->pw_name, pw_dbname ()); - exit (E_GRP_UPDATE); + Prog, pwd->pw_name, pw_dbname()); + exit(E_GRP_UPDATE); } else { npwd = *lpwd; npwd.pw_gid = ngid; - if (pw_update (&npwd) == 0) { - fprintf (stderr, + if (pw_update(&npwd) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, pw_dbname (), npwd.pw_name); - exit (E_GRP_UPDATE); + Prog, pw_dbname(), npwd.pw_name); + exit(E_GRP_UPDATE); } } } } - prefix_endpwent (); + prefix_endpwent(); } /* * main - groupmod command * */ -int main (int argc, char **argv) +int main(int argc, char **argv) { struct option_flags flags = {.chroot = false, .prefix = false}; log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); - prefix = process_prefix_flag ("-P", argc, argv); + process_root_flag("-R", argc, argv); + prefix = process_prefix_flag("-P", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); #ifdef WITH_AUDIT - audit_help_open (); + audit_help_open(); #endif - if (atexit (do_cleanups) != 0) { - fprintf (stderr, + if (atexit(do_cleanups) != 0) { + fprintf(stderr, _("%s: Cannot setup cleanup service.\n"), Prog); - exit (E_CLEANUP_SERVICE); + exit(E_CLEANUP_SERVICE); } - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); #ifdef SHADOWGRP - is_shadow_grp = sgr_file_present (); + is_shadow_grp = sgr_file_present(); #endif { struct group *grp; @@ -832,20 +832,20 @@ int main (int argc, char **argv) * Now if the group is not changed, it's our fault. * Make sure failures will be reported. */ - prepare_failure_reports (); + prepare_failure_reports(); /* * Do the hard stuff - open the files, create the group entries, * then close and update the files. */ - open_files (); + open_files(); - grp_update (); + grp_update(); - close_files (&flags); + close_files(&flags); - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_GROUP); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_GROUP); return E_SUCCESS; } diff --git a/src/grpck.c b/src/grpck.c index 385c105e87..79bde87420 100644 --- a/src/grpck.c +++ b/src/grpck.c @@ -75,37 +75,37 @@ static bool sort_mode = false; static bool silence_warnings = false; /* local function prototypes */ -static void fail_exit (int status, bool process_selinux); -NORETURN static void usage (int status); -static void delete_member (char **, const char *); -static void process_flags (int argc, char **argv, struct option_flags *flags); -static void open_files (bool process_selinux); +static void fail_exit(int status, bool process_selinux); +NORETURN static void usage(int status); +static void delete_member(char **, const char *); +static void process_flags(int argc, char **argv, struct option_flags *flags); +static void open_files(bool process_selinux); static void close_files(bool changed, const struct option_flags *flags); -static int check_members (const char *groupname, +static int check_members(const char *groupname, char **members, const char *fmt_info, const char *fmt_prompt, const char *fmt_syslog, bool *errors); -static void check_grp_file (bool *errors, bool *changed, +static void check_grp_file(bool *errors, bool *changed, const struct option_flags *flags); #ifdef SHADOWGRP -static void compare_members_lists (const char *groupname, +static void compare_members_lists(const char *groupname, char **members, char **other_members, const char *file, const char *other_file); -static void check_sgr_file (bool *errors, bool *changed); +static void check_sgr_file(bool *errors, bool *changed); #endif /* * fail_exit - exit with an error code after unlocking files */ -static void fail_exit (int status, bool process_selinux) +static void fail_exit(int status, bool process_selinux) { if (gr_locked) { - if (gr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + if (gr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", gr_dbname()); /* continue */ } @@ -121,9 +121,9 @@ static void fail_exit (int status, bool process_selinux) } #endif - closelog (); + closelog(); - exit (status); + exit(status); } /* @@ -131,30 +131,30 @@ static void fail_exit (int status, bool process_selinux) */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; #ifdef SHADOWGRP - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] [group [gshadow]]\n" "\n" "Options:\n"), Prog); #else /* !SHADOWGRP */ - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] [group]\n" "\n" "Options:\n"), Prog); #endif /* !SHADOWGRP */ - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -r, --read-only display errors and warnings\n" + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -r, --read-only display errors and warnings\n" " but do not change files\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -s, --sort sort entries by UID\n"), usageout); - (void) fputs (_(" -S, --silence-warnings silence controversial/paranoid warnings\n"), usageout); - (void) fputs ("\n", usageout); - exit (status); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -s, --sort sort entries by UID\n"), usageout); + (void) fputs(_(" -S, --silence-warnings silence controversial/paranoid warnings\n"), usageout); + (void) fputs("\n", usageout); + exit(status); } /* @@ -164,7 +164,7 @@ usage (int status) * The member is defined by its address, no string comparison are * performed. */ -static void delete_member (char **list, const char *member) +static void delete_member(char **list, const char *member) { int i; @@ -184,7 +184,7 @@ static void delete_member (char **list, const char *member) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { int c; static struct option long_options[] = { @@ -200,11 +200,11 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) /* * Parse the command line arguments */ - while ((c = getopt_long (argc, argv, "hqrR:sS", + while ((c = getopt_long(argc, argv, "hqrR:sS", long_options, NULL)) != -1) { switch (c) { case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'q': /* quiet - ignored for now */ @@ -240,7 +240,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) if (argc > (optind + 1)) #endif { - usage (E_USAGE); + usage(E_USAGE); } /* @@ -249,17 +249,17 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) */ if (optind != argc) { grp_file = argv[optind]; - gr_setdbname (grp_file); + gr_setdbname(grp_file); use_system_grp_file = false; } #ifdef SHADOWGRP if ((optind + 2) == argc) { sgr_file = argv[optind + 1]; - sgr_setdbname (sgr_file); + sgr_setdbname(sgr_file); is_shadow = true; use_system_sgr_file = false; } else if (optind == argc) { - is_shadow = sgr_file_present (); + is_shadow = sgr_file_present(); } #endif } @@ -270,26 +270,26 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * In read-only mode, the databases are not locked and are opened * only for reading. */ -static void open_files (bool process_selinux) +static void open_files(bool process_selinux) { /* * Lock the files if we aren't in "read-only" mode */ if (!read_only) { - if (gr_lock () == 0) { - fprintf (stderr, + if (gr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), Prog, grp_file); - fail_exit (E_CANT_LOCK, process_selinux); + fail_exit(E_CANT_LOCK, process_selinux); } gr_locked = true; #ifdef SHADOWGRP if (is_shadow) { - if (sgr_lock () == 0) { - fprintf (stderr, + if (sgr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), Prog, sgr_file); - fail_exit (E_CANT_LOCK, process_selinux); + fail_exit(E_CANT_LOCK, process_selinux); } sgr_locked = true; } @@ -300,22 +300,22 @@ static void open_files (bool process_selinux) * Open the files. Use O_RDONLY if we are in read_only mode, * O_RDWR otherwise. */ - if (gr_open (read_only ? O_RDONLY : O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, + if (gr_open(read_only ? O_RDONLY : O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, grp_file); if (use_system_grp_file) { SYSLOG(LOG_WARN, "cannot open %s", grp_file); } - fail_exit (E_CANT_OPEN, process_selinux); + fail_exit(E_CANT_OPEN, process_selinux); } #ifdef SHADOWGRP - if (is_shadow && (sgr_open (read_only ? O_RDONLY : O_CREAT | O_RDWR) == 0)) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, + if (is_shadow && (sgr_open(read_only ? O_RDONLY : O_CREAT | O_RDWR) == 0)) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, sgr_file); if (use_system_sgr_file) { SYSLOG(LOG_WARN, "cannot open %s", sgr_file); } - fail_exit (E_CANT_OPEN, process_selinux); + fail_exit(E_CANT_OPEN, process_selinux); } #endif } @@ -338,16 +338,16 @@ static void close_files(bool changed, const struct option_flags *flags) * changes to the files. */ if (changed) { - if (gr_close (process_selinux) == 0) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), + if (gr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, grp_file); - fail_exit (E_CANT_UPDATE, process_selinux); + fail_exit(E_CANT_UPDATE, process_selinux); } #ifdef SHADOWGRP - if (is_shadow && (sgr_close (process_selinux) == 0)) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), + if (is_shadow && (sgr_close(process_selinux) == 0)) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_file); - fail_exit (E_CANT_UPDATE, process_selinux); + fail_exit(E_CANT_UPDATE, process_selinux); } #endif } @@ -357,8 +357,8 @@ static void close_files(bool changed, const struct option_flags *flags) */ #ifdef SHADOWGRP if (sgr_locked) { - if (sgr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + if (sgr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sgr_dbname()); /* continue */ } @@ -394,7 +394,7 @@ static void close_files(bool changed, const struct option_flags *flags) * * fmt_syslog must contain two string flags (%s): for the * group's name and the missing member. */ -static int check_members (const char *groupname, +static int check_members(const char *groupname, char **members, const char *fmt_info, const char *fmt_prompt, @@ -417,16 +417,16 @@ static int check_members (const char *groupname, * from the list. */ *errors = true; - printf (fmt_info, groupname, members[i]); - printf (fmt_prompt, members[i]); + printf(fmt_info, groupname, members[i]); + printf(fmt_prompt, members[i]); - if (!yes_or_no (read_only)) { + if (!yes_or_no(read_only)) { continue; } SYSLOG(LOG_INFO, fmt_syslog, members[i], groupname); members_changed = 1; - delete_member (members, members[i]); + delete_member(members, members[i]); /* Rewind in case of removal */ i--; @@ -446,7 +446,7 @@ static int check_members (const char *groupname, * * TODO: no changes are performed on the lists. */ -static void compare_members_lists (const char *groupname, +static void compare_members_lists(const char *groupname, char **members, char **other_members, const char *file, @@ -486,7 +486,7 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag /* * Loop through the entire group file. */ - for (gre = __gr_get_head (); NULL != gre; gre = gre->next) { + for (gre = __gr_get_head(); NULL != gre; gre = gre->next) { /* * Skip all NIS entries. */ @@ -506,14 +506,14 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag * Tell the user this entire line is bogus and ask * them to delete it. */ - (void) puts (_("invalid group file entry")); - printf (_("delete line '%s'? "), gre->line); + (void) puts(_("invalid group file entry")); + printf(_("delete line '%s'? "), gre->line); *errors = true; /* * prompt the user to delete the entry or not */ - if (!yes_or_no (read_only)) { + if (!yes_or_no(read_only)) { continue; } @@ -527,7 +527,7 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag SYSLOG(LOG_INFO, "delete group line '%s'", gre->line); *changed = true; - __gr_del_entry (gre); + __gr_del_entry(gre); continue; } @@ -539,7 +539,7 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag /* * Make sure this entry has a unique name. */ - for (tgre = __gr_get_head (); NULL != tgre; tgre = tgre->next) { + for (tgre = __gr_get_head(); NULL != tgre; tgre = tgre->next) { const struct group *ent = tgre->eptr; @@ -565,14 +565,14 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag * Tell the user this entry is a duplicate of * another and ask them to delete it. */ - (void) puts (_("duplicate group entry")); - printf (_("delete line '%s'? "), gre->line); + (void) puts(_("duplicate group entry")); + printf(_("delete line '%s'? "), gre->line); *errors = true; /* * prompt the user to delete the entry or not */ - if (yes_or_no (read_only)) { + if (yes_or_no(read_only)) { goto delete_gr; } } @@ -580,16 +580,16 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag /* * Check for invalid group names. --marekm */ - if (!is_valid_group_name (grp->gr_name)) { + if (!is_valid_group_name(grp->gr_name)) { *errors = true; - printf (_("invalid group name '%s'\n"), grp->gr_name); + printf(_("invalid group name '%s'\n"), grp->gr_name); } /* * Check for invalid group ID. */ if (grp->gr_gid == (gid_t)-1) { - printf (_("invalid group ID '%lu'\n"), (long unsigned int)grp->gr_gid); + printf(_("invalid group ID '%lu'\n"), (long unsigned int)grp->gr_gid); *errors = true; } @@ -605,14 +605,14 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag grp->gr_mem[0] = NULL; } - if (check_members (grp->gr_name, grp->gr_mem, + if (check_members(grp->gr_name, grp->gr_mem, _("group %s: no user %s\n"), _("delete member '%s'? "), "delete member '%s' from group '%s'", errors) == 1) { *changed = true; gre->changed = true; - __gr_set_changed (); + __gr_set_changed(); } #ifdef SHADOWGRP @@ -621,14 +621,14 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag */ if (is_shadow) { - sgr = sgr_locate (grp->gr_name); + sgr = sgr_locate(grp->gr_name); if (sgr == NULL) { - printf (_("no matching group file entry in %s\n"), + printf(_("no matching group file entry in %s\n"), sgr_file); - printf (_("add group '%s' in %s? "), + printf(_("add group '%s' in %s? "), grp->gr_name, sgr_file); *errors = true; - if (yes_or_no (read_only)) { + if (yes_or_no(read_only)) { struct sgrp sg; struct group gr; static char *empty = NULL; @@ -641,20 +641,20 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag grp->gr_name, sgr_file); *changed = true; - if (sgr_update (&sg) == 0) { - fprintf (stderr, + if (sgr_update(&sg) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), sg.sg_namp); - fail_exit (E_CANT_UPDATE, process_selinux); + Prog, sgr_dbname(), sg.sg_namp); + fail_exit(E_CANT_UPDATE, process_selinux); } /* remove password from /etc/group */ gr = *grp; gr.gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ - if (gr_update (&gr) == 0) { - fprintf (stderr, + if (gr_update(&gr) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), gr.gr_name); - fail_exit (E_CANT_UPDATE, process_selinux); + Prog, gr_dbname(), gr.gr_name); + fail_exit(E_CANT_UPDATE, process_selinux); } } } else { @@ -662,7 +662,7 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag * Verify that all the members defined in /etc/group are also * present in /etc/gshadow. */ - compare_members_lists (grp->gr_name, + compare_members_lists(grp->gr_name, grp->gr_mem, sgr->sg_mem, grp_file, sgr_file); @@ -670,7 +670,7 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag * Make sure no passwords are in group. */ if (!streq(grp->gr_passwd, SHADOW_PASSWD_STRING)) { - printf (_("group %s has an entry in %s, but its password field in %s is not set to 'x'\n"), + printf(_("group %s has an entry in %s, but its password field in %s is not set to 'x'\n"), grp->gr_name, sgr_file, grp_file); *errors = true; } @@ -685,7 +685,7 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag /* * check_sgr_file - check the content of the shadowed group file (gshadow) */ -static void check_sgr_file (bool *errors, bool *changed) +static void check_sgr_file(bool *errors, bool *changed) { const struct group *grp; struct commonio_entry *sge, *tsge; @@ -694,7 +694,7 @@ static void check_sgr_file (bool *errors, bool *changed) /* * Loop through the entire shadow group file. */ - for (sge = __sgr_get_head (); NULL != sge; sge = sge->next) { + for (sge = __sgr_get_head(); NULL != sge; sge = sge->next) { /* * Start with the entries that are completely corrupt. They @@ -707,14 +707,14 @@ static void check_sgr_file (bool *errors, bool *changed) * Tell the user this entire line is bogus and ask * them to delete it. */ - (void) puts (_("invalid shadow group file entry")); - printf (_("delete line '%s'? "), sge->line); + (void) puts(_("invalid shadow group file entry")); + printf(_("delete line '%s'? "), sge->line); *errors = true; /* * prompt the user to delete the entry or not */ - if (!yes_or_no (read_only)) { + if (!yes_or_no(read_only)) { continue; } @@ -728,7 +728,7 @@ static void check_sgr_file (bool *errors, bool *changed) SYSLOG(LOG_INFO, "delete shadow line '%s'", sge->line); *changed = true; - __sgr_del_entry (sge); + __sgr_del_entry(sge); continue; } @@ -740,7 +740,7 @@ static void check_sgr_file (bool *errors, bool *changed) /* * Make sure this entry has a unique name. */ - for (tsge = __sgr_get_head (); NULL != tsge; tsge = tsge->next) { + for (tsge = __sgr_get_head(); NULL != tsge; tsge = tsge->next) { const struct sgrp *ent = tsge->eptr; @@ -766,14 +766,14 @@ static void check_sgr_file (bool *errors, bool *changed) * Tell the user this entry is a duplicate of * another and ask them to delete it. */ - (void) puts (_("duplicate shadow group entry")); - printf (_("delete line '%s'? "), sge->line); + (void) puts(_("duplicate shadow group entry")); + printf(_("delete line '%s'? "), sge->line); *errors = true; /* * prompt the user to delete the entry or not */ - if (yes_or_no (read_only)) { + if (yes_or_no(read_only)) { goto delete_sg; } } @@ -781,13 +781,13 @@ static void check_sgr_file (bool *errors, bool *changed) /* * Make sure this entry exists in the /etc/group file. */ - grp = gr_locate (sgr->sg_namp); + grp = gr_locate(sgr->sg_namp); if (grp == NULL) { - printf (_("no matching group file entry in %s\n"), + printf(_("no matching group file entry in %s\n"), grp_file); - printf (_("delete line '%s'? "), sge->line); + printf(_("delete line '%s'? "), sge->line); *errors = true; - if (yes_or_no (read_only)) { + if (yes_or_no(read_only)) { goto delete_sg; } } else { @@ -795,7 +795,7 @@ static void check_sgr_file (bool *errors, bool *changed) * Verify that the all members defined in /etc/gshadow are also * present in /etc/group. */ - compare_members_lists (sgr->sg_namp, + compare_members_lists(sgr->sg_namp, sgr->sg_mem, grp->gr_mem, sgr_file, grp_file); } @@ -803,27 +803,27 @@ static void check_sgr_file (bool *errors, bool *changed) /* * Make sure each administrator exists */ - if (check_members (sgr->sg_namp, sgr->sg_adm, + if (check_members(sgr->sg_namp, sgr->sg_adm, _("shadow group %s: no administrative user %s\n"), _("delete administrative member '%s'? "), "delete admin '%s' from shadow group '%s'", errors) == 1) { *changed = true; sge->changed = true; - __sgr_set_changed (); + __sgr_set_changed(); } /* * Make sure each member exists */ - if (check_members (sgr->sg_namp, sgr->sg_mem, + if (check_members(sgr->sg_namp, sgr->sg_mem, _("shadow group %s: no user %s\n"), _("delete member '%s'? "), "delete member '%s' from shadow group '%s'", errors) == 1) { *changed = true; sge->changed = true; - __sgr_set_changed (); + __sgr_set_changed(); } } } @@ -832,7 +832,7 @@ static void check_sgr_file (bool *errors, bool *changed) /* * grpck - verify group file integrity */ -int main (int argc, char **argv) +int main(int argc, char **argv) { bool errors = false; bool changed = false; @@ -842,13 +842,13 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); /* Parse the command line arguments */ process_flags (argc, argv, &flags); @@ -874,11 +874,11 @@ int main (int argc, char **argv) } /* Commit the change in the database if needed */ - close_files (changed, &flags); + close_files(changed, &flags); if (!read_only && changed) { - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_GROUP); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_GROUP); } /* @@ -886,9 +886,9 @@ int main (int argc, char **argv) */ if (errors) { if (changed) { - printf (_("%s: the files have been updated\n"), Prog); + printf(_("%s: the files have been updated\n"), Prog); } else { - printf (_("%s: no changes\n"), Prog); + printf(_("%s: no changes\n"), Prog); } } diff --git a/src/grpconv.c b/src/grpconv.c index 840a8c2d04..c44c94cba5 100644 --- a/src/grpconv.c +++ b/src/grpconv.c @@ -71,8 +71,8 @@ static void fail_exit (int status, bool process_selinux) } if (sgr_locked) { - if (sgr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + if (sgr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sgr_dbname()); /* continue */ } @@ -100,7 +100,7 @@ static void usage (int status) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { /* * Parse the command line options. @@ -112,26 +112,26 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "hR:", + while ((c = getopt_long(argc, argv, "hR:", long_options, NULL)) != -1) { switch (c) { case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ flags->chroot = true; break; default: - usage (E_USAGE); + usage(E_USAGE); } } if (optind != argc) { - usage (E_USAGE); + usage(E_USAGE); } } -int main (int argc, char **argv) +int main(int argc, char **argv) { const struct group *gr; struct group grent; @@ -143,69 +143,69 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); process_selinux = !flags.chroot; - if (gr_lock () == 0) { - fprintf (stderr, + if (gr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, gr_dbname ()); - fail_exit (5, process_selinux); + Prog, gr_dbname()); + fail_exit(5, process_selinux); } gr_locked = true; - if (gr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); - fail_exit (1, process_selinux); + if (gr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, gr_dbname()); + fail_exit(1, process_selinux); } - if (sgr_lock () == 0) { - fprintf (stderr, + if (sgr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sgr_dbname ()); - fail_exit (5, process_selinux); + Prog, sgr_dbname()); + fail_exit(5, process_selinux); } sgr_locked = true; - if (sgr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ()); - fail_exit (1, process_selinux); + if (sgr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname()); + fail_exit(1, process_selinux); } /* * Remove /etc/gshadow entries for groups not in /etc/group. */ - (void) sgr_rewind (); + (void) sgr_rewind(); while (NULL != (sg = sgr_next())) { - if (gr_locate (sg->sg_namp) != NULL) { + if (gr_locate(sg->sg_namp) != NULL) { continue; } - if (sgr_remove (sg->sg_namp) == 0) { + if (sgr_remove(sg->sg_namp) == 0) { /* * This shouldn't happen (the entry exists) but... */ - fprintf (stderr, + fprintf(stderr, _("%s: cannot remove entry '%s' from %s\n"), - Prog, sg->sg_namp, sgr_dbname ()); - fail_exit (3, process_selinux); + Prog, sg->sg_namp, sgr_dbname()); + fail_exit(3, process_selinux); } - (void) sgr_rewind (); + (void) sgr_rewind(); } /* * Update shadow group passwords if non-shadow password is not "x". * Add any missing shadow group entries. */ - (void) gr_rewind (); - while ((gr = gr_next ()) != NULL) { - sg = sgr_locate (gr->gr_name); + (void) gr_rewind(); + while ((gr = gr_next()) != NULL) { + sg = sgr_locate(gr->gr_name); if (NULL != sg) { /* update existing shadow group entry */ sgent = *sg; @@ -215,7 +215,7 @@ int main (int argc, char **argv) static char *empty = NULL; /* add new shadow group entry */ - bzero(&sgent, sizeof(sgent)); + bzero(&sgent, sizeof (sgent)); sgent.sg_namp = gr->gr_name; sgent.sg_passwd = gr->gr_passwd; sgent.sg_adm = ∅ @@ -228,39 +228,39 @@ int main (int argc, char **argv) */ sgent.sg_mem = gr->gr_mem; - if (sgr_update (&sgent) == 0) { - fprintf (stderr, + if (sgr_update(&sgent) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), sgent.sg_namp); - fail_exit (3, process_selinux); + Prog, sgr_dbname(), sgent.sg_namp); + fail_exit(3, process_selinux); } /* remove password from /etc/group */ grent = *gr; grent.gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ - if (gr_update (&grent) == 0) { - fprintf (stderr, + if (gr_update(&grent) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), grent.gr_name); - fail_exit (3, process_selinux); + Prog, gr_dbname(), grent.gr_name); + fail_exit(3, process_selinux); } } - if (sgr_close (process_selinux) == 0) { - fprintf (stderr, + if (sgr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, sgr_dbname ()); + Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", sgr_dbname()); - fail_exit (3, process_selinux); + fail_exit(3, process_selinux); } - if (gr_close (process_selinux) == 0) { - fprintf (stderr, + if (gr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, gr_dbname ()); + Prog, gr_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", gr_dbname()); - fail_exit (3, process_selinux); + fail_exit(3, process_selinux); } - if (sgr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + if (sgr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sgr_dbname()); /* continue */ } @@ -270,8 +270,8 @@ int main (int argc, char **argv) /* continue */ } - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_GROUP); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_GROUP); return 0; } @@ -279,9 +279,9 @@ int main (int argc, char **argv) int main(MAYBE_UNUSED int _1, char **argv) { - fprintf (stderr, + fprintf(stderr, "%s: not configured for shadow group support.\n", argv[0]); - exit (1); + exit(1); } #endif /* !SHADOWGRP */ diff --git a/src/grpunconv.c b/src/grpunconv.c index 8f17398fd5..301aebc325 100644 --- a/src/grpunconv.c +++ b/src/grpunconv.c @@ -70,8 +70,8 @@ static void fail_exit (int status, bool process_selinux) } if (sgr_locked) { - if (sgr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + if (sgr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sgr_dbname()); /* continue */ } @@ -99,7 +99,7 @@ static void usage (int status) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { /* * Parse the command line options. @@ -111,26 +111,26 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "hR:", + while ((c = getopt_long(argc, argv, "hR:", long_options, NULL)) != -1) { switch (c) { case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ flags->chroot = true; break; default: - usage (E_USAGE); + usage(E_USAGE); } } if (optind != argc) { - usage (E_USAGE); + usage(E_USAGE); } } -int main (int argc, char **argv) +int main(int argc, char **argv) { const struct group *gr; struct group grent; @@ -141,18 +141,18 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); process_selinux = !flags.chroot; - if (sgr_file_present () == 0) { + if (sgr_file_present() == 0) { exit (0); /* no /etc/gshadow, nothing to do */ } @@ -185,9 +185,9 @@ int main (int argc, char **argv) /* * Update group passwords if non-shadow password is "x". */ - (void) gr_rewind (); + (void) gr_rewind(); while (NULL != (gr = gr_next())) { - sg = sgr_locate (gr->gr_name); + sg = sgr_locate(gr->gr_name); if ( (NULL != sg) && streq(gr->gr_passwd, SHADOW_PASSWD_STRING)) { /* add password to /etc/group */ @@ -204,24 +204,24 @@ int main (int argc, char **argv) (void) sgr_close (process_selinux); /* was only open O_RDONLY */ - if (gr_close (process_selinux) == 0) { - fprintf (stderr, + if (gr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, gr_dbname ()); + Prog, gr_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", gr_dbname()); - fail_exit (3, process_selinux); + fail_exit(3, process_selinux); } if (unlink(_PATH_GSHADOW) != 0) { - fprintf (stderr, + fprintf(stderr, _("%s: cannot delete %s\n"), Prog, _PATH_GSHADOW); SYSLOG(LOG_ERR, "cannot delete %s", _PATH_GSHADOW); - fail_exit (3, process_selinux); + fail_exit(3, process_selinux); } - if (gr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + if (gr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", gr_dbname()); /* continue */ } @@ -232,8 +232,8 @@ int main (int argc, char **argv) /* continue */ } - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_GROUP); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_GROUP); return 0; } @@ -241,9 +241,9 @@ int main (int argc, char **argv) int main(MAYBE_UNUSED int _1, char **argv) { - fprintf (stderr, + fprintf(stderr, "%s: not configured for shadow group support.\n", argv[0]); - exit (1); + exit(1); } #endif /* !SHADOWGRP */ diff --git a/src/lastlog.c b/src/lastlog.c index ae172a0b6a..82aeef0f14 100644 --- a/src/lastlog.c +++ b/src/lastlog.c @@ -115,17 +115,17 @@ static void print_one (/*@null@*/const struct passwd *pw) offset = (off_t) pw->pw_uid * sizeof (ll); if (offset + ssizeof(ll) <= statbuf.st_size) { /* fseeko errors are not really relevant for us. */ - int err = fseeko (lastlogfile, offset, SEEK_SET); - assert (0 == err); + int err = fseeko(lastlogfile, offset, SEEK_SET); + assert(0 == err); /* lastlog is a sparse file. Even if no entries were * entered for this user, which should be able to get the * empty entry in this case. */ - if (fread(&ll, sizeof(ll), 1, lastlogfile) != 1) { - fprintf (stderr, + if (fread(&ll, sizeof (ll), 1, lastlogfile) != 1) { + fprintf(stderr, _("%s: Failed to get the entry for UID %lu\n"), Prog, (unsigned long)pw->pw_uid); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } } else { /* Outsize of the lastlog file. @@ -133,7 +133,7 @@ static void print_one (/*@null@*/const struct passwd *pw) * as if we were reading an non existing entry in the * sparse lastlog file). */ - memzero(&ll, sizeof(ll)); + memzero(&ll, sizeof (ll)); } /* Filter out entries that do not match with the -t or -b options */ @@ -148,15 +148,15 @@ static void print_one (/*@null@*/const struct passwd *pw) /* Print the header only once */ if (!once) { #ifdef HAVE_LL_HOST - printf (_("Username Port From%*sLatest\n"), maxIPv6Addrlen-4, " "); + printf(_("Username Port From%*sLatest\n"), maxIPv6Addrlen-4, " "); #else - puts (_("Username Port Latest")); + puts(_("Username Port Latest")); #endif once = true; } ll_time = ll.ll_time; - tm = localtime (&ll_time); + tm = localtime(&ll_time); if (tm == NULL) { cp = "(unknown)"; } else { @@ -219,7 +219,7 @@ static void update_one (/*@null@*/const struct passwd *pw) return; } - offset = (off_t) pw->pw_uid * sizeof(ll); + offset = (off_t) pw->pw_uid * sizeof (ll); /* fseeko errors are not really relevant for us. */ err = fseeko (lastlogfile, offset, SEEK_SET); assert (0 == err); @@ -262,37 +262,37 @@ static void update (void) if (!uflg) /* safety measure */ return; - lastlog_uid_max = getdef_ulong ("LASTLOG_UID_MAX", 0xFFFFFFFFUL); + lastlog_uid_max = getdef_ulong("LASTLOG_UID_MAX", 0xFFFFFFFFUL); if ( (has_umin && umin > lastlog_uid_max) || (has_umax && umax > lastlog_uid_max)) { - fprintf (stderr, _("%s: Selected uid(s) are higher than LASTLOG_UID_MAX (%lu),\n" + fprintf(stderr, _("%s: Selected uid(s) are higher than LASTLOG_UID_MAX(%lu),\n" "\tthey will not be updated.\n"), Prog, lastlog_uid_max); return; } if (has_umin && has_umax && (umin == umax)) { - update_one (getpwuid (umin)); + update_one(getpwuid(umin)); } else { - setpwent (); - while ( (pwent = getpwent ()) != NULL ) { + setpwent(); + while ( (pwent = getpwent()) != NULL ) { if ((has_umin && (pwent->pw_uid < (uid_t)umin)) || (has_umax && (pwent->pw_uid > (uid_t)umax))) { continue; } - update_one (pwent); + update_one(pwent); } - endpwent (); + endpwent(); } - if (fflush (lastlogfile) != 0 || fsync (fileno (lastlogfile)) != 0) { - fprintf (stderr, + if (fflush(lastlogfile) != 0 || fsync(fileno(lastlogfile)) != 0) { + fprintf(stderr, _("%s: Failed to update the lastlog file\n"), Prog); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } } -int main (int argc, char **argv) +int main(int argc, char **argv) { /* * Get the program name. The program name is used as a prefix to @@ -301,14 +301,14 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); #ifdef WITH_AUDIT - audit_help_open (); + audit_help_open(); #endif { @@ -325,17 +325,17 @@ int main (int argc, char **argv) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "b:ChR:St:u:a", longopts, + while ((c = getopt_long(argc, argv, "b:ChR:St:u:a", longopts, NULL)) != -1) { switch (c) { case 'b': { unsigned long inverse_days; if (str2ul(&inverse_days, optarg) == -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } inverse_seconds = (time_t) inverse_days * DAY; bflg = true; @@ -347,7 +347,7 @@ int main (int argc, char **argv) break; } case 'h': - usage (EXIT_SUCCESS); + usage(EXIT_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ break; @@ -360,10 +360,10 @@ int main (int argc, char **argv) { unsigned long days; if (str2ul(&days, optarg) == -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } seconds = (time_t) days * DAY; tflg = true; @@ -410,29 +410,29 @@ int main (int argc, char **argv) } } if (argc > optind) { - fprintf (stderr, + fprintf(stderr, _("%s: unexpected argument: %s\n"), Prog, argv[optind]); - usage (EXIT_FAILURE); + usage(EXIT_FAILURE); } if (Cflg && Sflg) { - fprintf (stderr, + fprintf(stderr, _("%s: Option -C cannot be used together with option -S\n"), Prog); - usage (EXIT_FAILURE); + usage(EXIT_FAILURE); } if ((Cflg || Sflg) && !uflg) { - fprintf (stderr, + fprintf(stderr, _("%s: Options -C and -S require option -u to specify the user\n"), Prog); - usage (EXIT_FAILURE); + usage(EXIT_FAILURE); } } lastlogfile = fopen(_PATH_LASTLOG, (Cflg || Sflg)?"r+":"r"); if (NULL == lastlogfile) { perror(_PATH_LASTLOG); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } /* Get the lastlog size */ diff --git a/src/login.c b/src/login.c index 1da71b1046..d0adb3147c 100644 --- a/src/login.c +++ b/src/login.c @@ -118,15 +118,15 @@ static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use #ifndef USE_PAM static struct faillog faillog; -static void bad_time_notify (void); -static void check_nologin (bool login_to_root); +static void bad_time_notify(void); +static void check_nologin(bool login_to_root); #else -static void get_pam_user (char **ptr_pam_user); +static void get_pam_user(char **ptr_pam_user); #endif -static void init_env (void); -static void alarm_handler (int); -static void exit_handler (int); +static void init_env(void); +static void alarm_handler(int); +static void exit_handler(int); /* * usage - print login command usage and exit @@ -135,17 +135,17 @@ static void exit_handler (int); * login -h hostname (for telnetd, etc.) * login -f name (for pre-authenticated login: datakit, xterm, etc.) */ -static void usage (void) +static void usage(void) { - fprintf (stderr, _("Usage: %s [-p] [name]\n"), Prog); + fprintf(stderr, _("Usage: %s [-p] [name]\n"), Prog); if (!amroot) { - exit (1); + exit(1); } - fprintf (stderr, _(" %s [-p] [-h host] [-f name]\n"), Prog); - exit (1); + fprintf(stderr, _(" %s [-p] [-h host] [-f name]\n"), Prog); + exit(1); } -static void setup_tty (void) +static void setup_tty(void) { TERMIO termio; @@ -178,23 +178,23 @@ static void setup_tty (void) * getdef_num cannot validate this. */ if (erasechar != (int) termio.c_cc[VERASE]) { - fprintf (stderr, + fprintf(stderr, _("configuration error - cannot parse %s value: '%d'"), "ERASECHAR", erasechar); - exit (1); + exit(1); } if (killchar != (int) termio.c_cc[VKILL]) { - fprintf (stderr, + fprintf(stderr, _("configuration error - cannot parse %s value: '%d'"), "KILLCHAR", killchar); - exit (1); + exit(1); } /* * ttymon invocation prefers this, but these settings * won't come into effect after the first username login */ - (void) STTY (0, &termio); + (void) STTY(0, &termio); } } @@ -203,13 +203,13 @@ static void setup_tty (void) /* * Tell the user that this is not the right time to login at this tty */ -static void bad_time_notify (void) +static void bad_time_notify(void) { - (void) puts (_("Invalid login time")); - (void) fflush (stdout); + (void) puts(_("Invalid login time")); + (void) fflush(stdout); } -static void check_nologin (bool login_to_root) +static void check_nologin(bool login_to_root) { const char *fname; @@ -220,28 +220,28 @@ static void check_nologin (bool login_to_root) * out for root so she knows to remove the file if she's * forgotten about it ... */ - fname = getdef_str ("NOLOGINS_FILE"); - if ((NULL != fname) && (access (fname, F_OK) == 0)) { + fname = getdef_str("NOLOGINS_FILE"); + if ((NULL != fname) && (access(fname, F_OK) == 0)) { FILE *nlfp; /* * Cat the file if it can be opened, otherwise just * print a default message */ - nlfp = fopen (fname, "r"); + nlfp = fopen(fname, "r"); if (NULL != nlfp) { int c; - while ((c = getc (nlfp)) != EOF) { + while ((c = getc(nlfp)) != EOF) { if (c == '\n') { - (void) putchar ('\r'); + (void) putchar('\r'); } - (void) putchar (c); + (void) putchar(c); } - (void) fflush (stdout); - (void) fclose (nlfp); + (void) fflush(stdout); + (void) fclose(nlfp); } else { - (void) puts (_("\nSystem closed for routine maintenance")); + (void) puts(_("\nSystem closed for routine maintenance")); } /* * Non-root users must exit. Root gets the message, but @@ -249,15 +249,15 @@ static void check_nologin (bool login_to_root) */ if (!login_to_root) { - closelog (); - exit (0); + closelog(); + exit(0); } - (void) puts (_("\n[Disconnect bypassed -- root login allowed.]")); + (void) puts(_("\n[Disconnect bypassed -- root login allowed.]")); } } #endif /* !USE_PAM */ -static void process_flags (int argc, char *const *argv) +static void process_flags(int argc, char *const *argv) { int arg; int flag; @@ -269,7 +269,7 @@ static void process_flags (int argc, char *const *argv) */ for (arg = 1; arg < argc; arg++) { if (strprefix(argv[arg], "-") && strlen(argv[arg]) > 2) { - usage (); + usage(); } if (streq(argv[arg], "--")) { break; /* stop checking on a "--" */ @@ -279,7 +279,7 @@ static void process_flags (int argc, char *const *argv) /* * Process options. */ - while ((flag = getopt (argc, argv, "d:fh:pr:")) != EOF) { + while ((flag = getopt(argc, argv, "d:fh:pr:")) != EOF) { switch (flag) { case 'd': /* "-d device" ignored for compatibility */ @@ -304,50 +304,50 @@ static void process_flags (int argc, char *const *argv) */ if ((fflg || hflg) && !amroot) { - fprintf (stderr, _("%s: Permission denied.\n"), Prog); - exit (1); + fprintf(stderr, _("%s: Permission denied.\n"), Prog); + exit(1); } /* * Get the user name. */ if (optind < argc) { - assert (NULL == username); - username = xstrdup (argv[optind]); - strzero (argv[optind]); + assert(NULL == username); + username = xstrdup(argv[optind]); + strzero(argv[optind]); ++optind; } if (fflg && (NULL == username)) { - usage (); + usage(); } } -static void init_env (void) +static void init_env(void) { #ifndef USE_PAM const char *cp; #endif char *tmp; - tmp = getenv ("LANG"); + tmp = getenv("LANG"); if (NULL != tmp) { - addenv ("LANG", tmp); + addenv("LANG", tmp); } /* * Add the timezone environmental variable so that time functions * work correctly. */ - tmp = getenv ("TZ"); + tmp = getenv("TZ"); if (NULL != tmp) { - addenv ("TZ", tmp); + addenv("TZ", tmp); } #ifndef USE_PAM else { - cp = getdef_str ("ENV_TZ"); + cp = getdef_str("ENV_TZ"); if (NULL != cp) { addenv(strprefix(cp, "/") ? tz(cp) : cp, NULL); } @@ -357,15 +357,15 @@ static void init_env (void) * Add the clock frequency so that profiling commands work * correctly. */ - tmp = getenv ("HZ"); + tmp = getenv("HZ"); if (NULL != tmp) { - addenv ("HZ", tmp); + addenv("HZ", tmp); } #ifndef USE_PAM else { - cp = getdef_str ("ENV_HZ"); + cp = getdef_str("ENV_HZ"); if (NULL != cp) { - addenv (cp, NULL); + addenv(cp, NULL); } } #endif /* !USE_PAM */ @@ -374,7 +374,7 @@ static void init_env (void) static void exit_handler(MAYBE_UNUSED int _1) { - _exit (0); + _exit(0); } static void @@ -391,19 +391,19 @@ alarm_handler(MAYBE_UNUSED int _1) * * ptr_pam_user shall point to a malloc'ed string (or NULL). */ -static void get_pam_user (char **ptr_pam_user) +static void get_pam_user(char **ptr_pam_user) { int retcode; const void *ptr_user; - assert (NULL != ptr_pam_user); + assert(NULL != ptr_pam_user); - retcode = pam_get_item (pamh, PAM_USER, &ptr_user); + retcode = pam_get_item(pamh, PAM_USER, &ptr_user); PAM_FAIL_CHECK; - free (*ptr_pam_user); + free(*ptr_pam_user); if (NULL != ptr_user) { - *ptr_pam_user = xstrdup (ptr_user); + *ptr_pam_user = xstrdup(ptr_user); } else { *ptr_pam_user = NULL; } @@ -450,7 +450,7 @@ static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use * -f - do not perform authentication, user is preauthenticated * -h - the name of the remote host */ -int main (int argc, char **argv) +int main(int argc, char **argv) { int err; bool subroot = false; @@ -484,26 +484,26 @@ int main (int argc, char **argv) * Some quick initialization. */ - sanitize_env (); + sanitize_env(); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - initenv (); + initenv(); - amroot = (getuid () == 0); + amroot = (getuid() == 0); log_set_progname(Prog); log_set_logfd(stderr); if (geteuid() != 0) { - fprintf (stderr, _("%s: Cannot possibly work without effective root\n"), Prog); - exit (1); + fprintf(stderr, _("%s: Cannot possibly work without effective root\n"), Prog); + exit(1); } - process_flags (argc, argv); + process_flags(argc, argv); - if ((isatty (0) == 0) || (isatty (1) == 0) || (isatty (2) == 0)) { + if ((isatty(0) == 0) || (isatty(1) == 0) || (isatty(2) == 0)) { exit (1); /* must be a terminal */ } @@ -517,17 +517,17 @@ int main (int argc, char **argv) SYSLOG(LOG_ERR, "No session entry, error %d. You must exec \"login\" from the lowest level \"sh\"", err); - exit (1); + exit(1); } - tmptty = ttyname (0); + tmptty = ttyname(0); if (NULL == tmptty) { tmptty = "UNKNOWN"; } strtcpy_a(tty, tmptty); #ifndef USE_PAM - is_console = console (tty); + is_console = console(tty); #endif if (hflg) { @@ -535,18 +535,18 @@ int main (int argc, char **argv) * Add remote hostname to the environment. I think * (not sure) I saw it once on Irix. --marekm */ - addenv ("REMOTEHOST", hostname); + addenv("REMOTEHOST", hostname); } if (fflg) { preauth_flag = true; } - OPENLOG (Prog); + OPENLOG(Prog); - setup_tty (); + setup_tty(); #ifndef USE_PAM - (void) umask (getdef_num ("UMASK", GETDEF_DEFAULT_UMASK)); + (void) umask(getdef_num("UMASK", GETDEF_DEFAULT_UMASK)); { /* @@ -555,10 +555,10 @@ int main (int argc, char **argv) * user may have one for themselves, but otherwise, * just take what you get. */ - long limit = getdef_long ("ULIMIT", -1L); + long limit = getdef_long("ULIMIT", -1L); if (limit != -1) { - set_filesize_limit (limit); + set_filesize_limit(limit); } } @@ -585,7 +585,7 @@ int main (int argc, char **argv) init_env (); if (optind < argc) { /* now set command line variables */ - set_env (argc - optind, &argv[optind]); + set_env(argc - optind, &argv[optind]); } if (hflg) { @@ -613,17 +613,17 @@ int main (int argc, char **argv) } environ = newenvp; /* make new environment active */ - delay = getdef_unum ("FAIL_DELAY", 1); - retries = getdef_unum ("LOGIN_RETRIES", RETRIES); + delay = getdef_unum("FAIL_DELAY", 1); + retries = getdef_unum("LOGIN_RETRIES", RETRIES); #ifdef USE_PAM - retcode = pam_start (Prog, username, &conv, &pamh); + retcode = pam_start(Prog, username, &conv, &pamh); if (retcode != PAM_SUCCESS) { - fprintf (stderr, + fprintf(stderr, _("login: PAM Failure, aborting: %s\n"), - pam_strerror (pamh, retcode)); + pam_strerror(pamh, retcode)); SYSLOG(LOG_ERR, "Couldn't initialize PAM: %s", pam_strerror(pamh, retcode)); - exit (99); + exit(99); } /* @@ -634,12 +634,12 @@ int main (int argc, char **argv) * PAM_RHOST and PAM_TTY are used for authentication, only use * information coming from login or from the caller (e.g. no utmp) */ - retcode = pam_set_item (pamh, PAM_RHOST, hostname); + retcode = pam_set_item(pamh, PAM_RHOST, hostname); PAM_FAIL_CHECK; - retcode = pam_set_item (pamh, PAM_TTY, tty); + retcode = pam_set_item(pamh, PAM_TTY, tty); PAM_FAIL_CHECK; #ifdef HAVE_PAM_FAIL_DELAY - retcode = pam_fail_delay (pamh, 1000000 * delay); + retcode = pam_fail_delay(pamh, 1000000 * delay); PAM_FAIL_CHECK; #endif /* if fflg, then the user has already been authenticated */ @@ -649,20 +649,20 @@ int main (int argc, char **argv) unsigned int failcount = 0; /* Make the login prompt look like we want it */ - if (gethostname(hostn, sizeof(hostn)) == 0) { + if (gethostname(hostn, sizeof (hostn)) == 0) { stprintf_a(loginprompt, _("%s login: "), hostn); } else { strtcpy_a(loginprompt, _("login: ")); } - retcode = pam_set_item (pamh, PAM_USER_PROMPT, loginprompt); + retcode = pam_set_item(pamh, PAM_USER_PROMPT, loginprompt); PAM_FAIL_CHECK; /* if we didn't get a user on the command line, set it to NULL */ - get_pam_user (&pam_user); + get_pam_user(&pam_user); if ((NULL != pam_user) && streq(pam_user, "")) { - retcode = pam_set_item (pamh, PAM_USER, NULL); + retcode = pam_set_item(pamh, PAM_USER, NULL); PAM_FAIL_CHECK; } @@ -686,17 +686,17 @@ int main (int argc, char **argv) } #endif - retcode = pam_authenticate (pamh, 0); + retcode = pam_authenticate(pamh, 0); - get_pam_user (&pam_user); - failent_user = get_failent_user (pam_user); + get_pam_user(&pam_user); + failent_user = get_failent_user(pam_user); if (retcode == PAM_MAXTRIES) { SYSLOG(LOG_NOTICE, - "TOO MANY LOGIN TRIES (%u)%s FOR '%s'", + "TOO MANY LOGIN TRIES(%u)%s FOR '%s'", failcount, fromhost, failent_user); - fprintf (stderr, - _("Maximum number of tries exceeded (%u)\n"), + fprintf(stderr, + _("Maximum number of tries exceeded(%u)\n"), failcount); PAM_END; exit(0); @@ -729,18 +729,18 @@ int main (int argc, char **argv) NULL, /* addr */ tty, 0); /* result */ - close (audit_fd); + close(audit_fd); #endif /* WITH_AUDIT */ - (void) puts (""); - (void) puts (_("Login incorrect")); + (void) puts(""); + (void) puts(_("Login incorrect")); if (failcount >= retries) { SYSLOG(LOG_NOTICE, - "TOO MANY LOGIN TRIES (%u)%s FOR '%s'", + "TOO MANY LOGIN TRIES(%u)%s FOR '%s'", failcount, fromhost, failent_user); - fprintf (stderr, - _("Maximum number of tries exceeded (%u)\n"), + fprintf(stderr, + _("Maximum number of tries exceeded(%u)\n"), failcount); PAM_END; exit(0); @@ -751,7 +751,7 @@ int main (int argc, char **argv) * Even if a username was given on the command * line, prompt again for the username. */ - retcode = pam_set_item (pamh, PAM_USER, NULL); + retcode = pam_set_item(pamh, PAM_USER, NULL); PAM_FAIL_CHECK; } @@ -760,9 +760,9 @@ int main (int argc, char **argv) } /* Check the account validity */ - retcode = pam_acct_mgmt (pamh, 0); + retcode = pam_acct_mgmt(pamh, 0); if (retcode == PAM_NEW_AUTHTOK_REQD) { - retcode = pam_chauthtok (pamh, PAM_CHANGE_EXPIRED_AUTHTOK); + retcode = pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK); } PAM_FAIL_CHECK; @@ -777,29 +777,29 @@ int main (int argc, char **argv) * From now on, we will discard changes of the user (PAM_USER) by * PAM APIs. */ - get_pam_user (&pam_user); - free (username); - username = xstrdup (pam_user); - failent_user = get_failent_user (username); + get_pam_user(&pam_user); + free(username); + username = xstrdup(pam_user); + failent_user = get_failent_user(username); - pwd = xgetpwnam (username); + pwd = xgetpwnam(username); if (NULL == pwd) { SYSLOG(LOG_ERR, "cannot find user %s", failent_user); - fprintf (stderr, - _("Cannot find user (%s)\n"), + fprintf(stderr, + _("Cannot find user(%s)\n"), username); - exit (1); + exit(1); } /* This set up the process credential (group) and initialize the * supplementary group access list. * This has to be done before pam_setcred */ - if (setup_groups (pwd) != 0) { - exit (1); + if (setup_groups(pwd) != 0) { + exit(1); } - retcode = pam_setcred (pamh, PAM_ESTABLISH_CRED); + retcode = pam_setcred(pamh, PAM_ESTABLISH_CRED); PAM_FAIL_CHECK; /* Note: if pam_setcred changes PAM_USER, this will not be taken * into account. @@ -817,11 +817,11 @@ int main (int argc, char **argv) /* Do some cleanup to avoid keeping entries we do not need * anymore. */ if (NULL != pwd) { - pw_free (pwd); + pw_free(pwd); pwd = NULL; } if (NULL != spwd) { - spw_free (spwd); + spw_free(spwd); spwd = NULL; } @@ -831,8 +831,8 @@ int main (int argc, char **argv) max_size = login_name_max_size(); if (subroot) { - closelog (); - exit (1); + closelog(); + exit(1); } preauth_flag = false; username = xmalloc_T(max_size, char); @@ -846,9 +846,9 @@ int main (int argc, char **argv) } } /* Get the username to be used to log failures */ - failent_user = get_failent_user (username); + failent_user = get_failent_user(username); - pwd = xgetpwnam (username); + pwd = xgetpwnam(username); if (NULL == pwd) { preauth_flag = false; failed = true; @@ -881,7 +881,7 @@ int main (int argc, char **argv) } if (streq(user_passwd, SHADOW_PASSWD_STRING)) { - spwd = xgetspnam (username); + spwd = xgetspnam(username); if (NULL != spwd) { user_passwd = spwd->sp_pwdp; } else { @@ -930,8 +930,8 @@ int main (int argc, char **argv) failed = true; } if ( (NULL != pwd) - && getdef_bool ("FAILLOG_ENAB") - && !failcheck (pwd->pw_uid, &faillog, failed)) { + && getdef_bool("FAILLOG_ENAB") + && !failcheck(pwd->pw_uid, &faillog, failed)) { SYSLOG(LOG_CRIT, "exceeded failure limit for '%s' %s", username, fromhost); failed = true; @@ -968,7 +968,7 @@ int main (int argc, char **argv) * Authentication of this user failed. * The username must be confirmed in the next try. */ - free (username); + free(username); username = NULL; /* @@ -977,10 +977,10 @@ int main (int argc, char **argv) * before the sleep() below completes, login will exit. */ if (delay > 0) { - (void) sleep (delay); + (void) sleep(delay); } - (void) puts (_("Login incorrect")); + (void) puts(_("Login incorrect")); /* allow only one attempt with -f */ if (fflg || (retries <= 0)) { @@ -989,8 +989,8 @@ int main (int argc, char **argv) } } /* while (true) */ #endif /* ! USE_PAM */ - assert (NULL != username); - assert (NULL != pwd); + assert(NULL != username); + assert(NULL != pwd); (void) alarm (0); /* turn off alarm clock */ @@ -1000,16 +1000,16 @@ int main (int argc, char **argv) * authenticated. now prints a message, as suggested * by Ivan Nejgebauer . --marekm */ - if ( getdef_bool ("PORTTIME_CHECKS_ENAB") - && !isttytime (username, tty, time (NULL))) { + if ( getdef_bool("PORTTIME_CHECKS_ENAB") + && !isttytime(username, tty, time(NULL))) { SYSLOG(LOG_WARN, "invalid login time for '%s'%s", username, fromhost); - closelog (); - bad_time_notify (); - exit (1); + closelog(); + bad_time_notify(); + exit(1); } - check_nologin (pwd->pw_uid == 0); + check_nologin(pwd->pw_uid == 0); #endif if (getenv ("IFS")) { /* don't export user IFS ... */ @@ -1041,13 +1041,13 @@ int main (int argc, char **argv) NULL, /* addr */ tty, 1); /* result */ - close (audit_fd); + close(audit_fd); #endif /* WITH_AUDIT */ #ifndef USE_PAM /* pam_lastlog handles this */ #ifdef ENABLE_LASTLOG - if ( getdef_bool ("LASTLOG_ENAB") - && pwd->pw_uid <= (uid_t) getdef_ulong ("LASTLOG_UID_MAX", 0xFFFFFFFFUL)) { + if ( getdef_bool("LASTLOG_ENAB") + && pwd->pw_uid <= (uid_t) getdef_ulong("LASTLOG_UID_MAX", 0xFFFFFFFFUL)) { /* give last login and log this one */ dolastlog (&ll, pwd, tty, hostname); } @@ -1067,16 +1067,16 @@ int main (int argc, char **argv) * entry for a long time, and there might be other * getxxyyy in between. */ - pw_free (pwd); - pwd = xgetpwnam (username); + pw_free(pwd); + pwd = xgetpwnam(username); if (NULL == pwd) { SYSLOG(LOG_ERR, "cannot find user %s after update of expired password", username); - exit (1); + exit(1); } - spw_free (spwd); - spwd = xgetspnam (username); + spw_free(spwd); + spwd = xgetspnam(username); } } setup_limits (pwd); /* nice, ulimit etc. */ @@ -1088,8 +1088,8 @@ int main (int argc, char **argv) * We must fork before setuid() because we need to call * pam_close_session() as root. */ - (void) signal (SIGINT, SIG_IGN); - child = fork (); + (void) signal(SIGINT, SIG_IGN); + child = fork(); if (child < 0) { /* error in fork() */ fprintf(stderr, _("%s: failure forking: %s"), Prog, strerrno()); @@ -1100,9 +1100,9 @@ int main (int argc, char **argv) * parent - wait for child to finish, then cleanup * session */ - wait (NULL); + wait(NULL); PAM_END; - exit (0); + exit(0); } /* child */ #endif @@ -1111,7 +1111,7 @@ int main (int argc, char **argv) if (1 == initial_pid) { setsid(); if (ioctl(0, TIOCSCTTY, 1) != 0) { - fprintf (stderr, _("TIOCSCTTY failed on %s"), tty); + fprintf(stderr, _("TIOCSCTTY failed on %s"), tty); } } @@ -1144,10 +1144,10 @@ int main (int argc, char **argv) /* The group privileges were already dropped. * See setup_groups() above. */ - if (change_uid (pwd)) + if (change_uid(pwd)) #endif { - exit (1); + exit(1); } setup_env (pwd); /* set env vars, cd to the home dir */ @@ -1179,9 +1179,9 @@ int main (int argc, char **argv) if (motd() == -1) exit(EXIT_FAILURE); - if ( getdef_bool ("FAILLOG_ENAB") + if ( getdef_bool("FAILLOG_ENAB") && (0 != faillog.fail_cnt)) { - failprint (&faillog); + failprint(&faillog); /* Reset the lockout times if logged in */ if ( (0 != faillog.fail_max) && (faillog.fail_cnt >= faillog.fail_max)) { @@ -1217,10 +1217,10 @@ int main (int argc, char **argv) mailcheck (); /* report on the status of mail */ #endif /* !USE_PAM */ } else { - addenv ("HUSHLOGIN=TRUE", NULL); + addenv("HUSHLOGIN=TRUE", NULL); } - ttytype (tty); + ttytype(tty); (void) signal (SIGQUIT, SIG_DFL); /* default quit signal */ (void) signal (SIGTERM, SIG_DFL); /* default terminate signal */ diff --git a/src/login_nopam.c b/src/login_nopam.c index 3269e74f74..295bd500da 100644 --- a/src/login_nopam.c +++ b/src/login_nopam.c @@ -97,7 +97,7 @@ login_access(const char *user, const char *from) * mandatory. The first field should be a "+" or "-" character. A * non-existing table means no access control. */ - fp = fopen (TABLE, "r"); + fp = fopen(TABLE, "r"); if (NULL != fp) { intmax_t lineno = 0; /* for diagnostics */ while ( !match @@ -146,7 +146,7 @@ login_access(const char *user, const char *from) /* list_match - match an item against a list of tokens with exceptions */ static bool -list_match(char *list, const char *item, bool (*match_fn)(char *, const char*)) +list_match(char *list, const char *item, bool(*match_fn)(char *, const char*)) { char *tok; bool inclusion = true; @@ -191,18 +191,18 @@ static char *myhostname (void) #if HAVE_INNETGR /* netgroup_match - match group against machine or user */ static bool -netgroup_match (const char *group, const char *machine, const char *user) +netgroup_match(const char *group, const char *machine, const char *user) { static char *mydomain = NULL; if (mydomain == NULL) { static char domain[MAXHOSTNAMELEN + 1]; - getdomainname (domain, MAXHOSTNAMELEN); + getdomainname(domain, MAXHOSTNAMELEN); mydomain = domain; } - return (innetgr (group, machine, user, mydomain) != 0); + return (innetgr(group, machine, user, mydomain) != 0); } #endif @@ -226,7 +226,7 @@ static bool user_match (char *tok, const char *string) return user_match(tok, string) && from_match(host, myhostname()); #if HAVE_INNETGR } else if (strprefix(tok, "@")) { /* netgroup */ - return (netgroup_match (tok + 1, NULL, string)); + return (netgroup_match(tok + 1, NULL, string)); #endif } else if (string_match (tok, string)) { /* ALL or exact match */ return true; @@ -287,7 +287,7 @@ static const char *resolve_hostname (const char *string) /* from_match - match a host or tty against a list of tokens */ -static bool from_match (char *tok, const char *string) +static bool from_match(char *tok, const char *string) { /* * If a token has the magic value "ALL" the match always succeeds. Return @@ -324,7 +324,7 @@ static bool from_match (char *tok, const char *string) } /* string_match - match a string against one token */ -static bool string_match (const char *tok, const char *string) +static bool string_match(const char *tok, const char *string) { /* diff --git a/src/new_subid_range.c b/src/new_subid_range.c index bca379d8b6..ca095c97f6 100644 --- a/src/new_subid_range.c +++ b/src/new_subid_range.c @@ -16,7 +16,7 @@ static const char Prog[] = "new_subid_range"; static void usage(void) { fprintf(stderr, "Usage: %s [-g] [-n] user count\n", Prog); - fprintf(stderr, " Find a subuid (or with -g, subgid) range for user\n"); + fprintf(stderr, " Find a subuid(or with -g, subgid) range for user\n"); fprintf(stderr, " If -n is given, a new range will be created even if one exists\n"); fprintf(stderr, " count defaults to 65536\n"); exit(EXIT_FAILURE); @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) if (!subid_init(Prog, stderr)) fprintf(stderr, "subid_init: %s\n", strerrno()); while ((c = getopt(argc, argv, "gn")) != EOF) { - switch(c) { + switch (c) { case 'n': makenew = true; break; case 'g': group = true; break; default: usage(); diff --git a/src/newgidmap.c b/src/newgidmap.c index afda66657a..57a09d573c 100644 --- a/src/newgidmap.c +++ b/src/newgidmap.c @@ -113,7 +113,7 @@ static void write_setgroups(int proc_dir_fd, bool allow_setgroups) * is write-once, so attempting to write after it's already written to will * fail. */ - if (read(setgroups_fd, policy_buffer, sizeof(policy_buffer)) < 0) { + if (read(setgroups_fd, policy_buffer, sizeof (policy_buffer)) < 0) { fprintf(stderr, _("%s: failed to read setgroups: %s\n"), Prog, strerrno()); exit(EXIT_FAILURE); @@ -177,12 +177,12 @@ int main(int argc, char **argv) usage(); } /* Who am I? */ - pw = get_my_pwent (); + pw = get_my_pwent(); if (NULL == pw) { - fprintf (stderr, + fprintf(stderr, _("%s: Cannot determine your user name.\n"), Prog); - SYSLOG(LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", + SYSLOG(LOG_WARN, "Cannot determine the user name of the caller(UID %lu)", (unsigned long) getuid()); return EXIT_FAILURE; } @@ -211,7 +211,7 @@ int main(int argc, char **argv) } if (want_subgid_file() && !sub_gid_open(O_RDONLY)) { - fprintf (stderr, + fprintf(stderr, _("%s: cannot open %s: %s\n"), Prog, sub_gid_dbname(), strerrno()); return EXIT_FAILURE; diff --git a/src/newgrp.c b/src/newgrp.c index d081cf2b5b..e8c3562a54 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -59,21 +59,21 @@ static char audit_buf[80]; #endif /* local function prototypes */ -static void usage (void); -static void check_perms (const struct group *grp, +static void usage(void); +static void check_perms(const struct group *grp, struct passwd *pwd, const char *groupname); -static void syslog_sg (const char *name, const char *group); +static void syslog_sg(const char *name, const char *group); /* * usage - print command usage message */ -static void usage (void) +static void usage(void) { if (is_newgrp) { - (void) fputs (_("Usage: newgrp [-] [group]\n"), stderr); + (void) fputs(_("Usage: newgrp [-] [group]\n"), stderr); } else { - (void) fputs (_("Usage: sg [-] group [[-c] command]\n"), stderr); + (void) fputs(_("Usage: sg [-] group [[-c] command]\n"), stderr); } } @@ -114,7 +114,7 @@ static /*@null@*/struct group *find_matching_group (const char *name, struct gro if (ingroup(name, gr)) break; } - endgrent (); + endgrent(); return gr; } @@ -125,7 +125,7 @@ static /*@null@*/struct group *find_matching_group (const char *name, struct gro * * It will not return if the user could not be authenticated. */ -static void check_perms (const struct group *grp, +static void check_perms(const struct group *grp, struct passwd *pwd, const char *groupname) { @@ -144,7 +144,7 @@ static void check_perms (const struct group *grp, * */ if ( (grp->gr_gid != pwd->pw_gid) - && !is_on_list (grp->gr_mem, pwd->pw_name)) { + && !is_on_list(grp->gr_mem, pwd->pw_name)) { needspasswd = true; } @@ -153,10 +153,10 @@ static void check_perms (const struct group *grp, * password, and the group has a password, she needs to give the * group password. */ - spwd = xgetspnam (pwd->pw_name); + spwd = xgetspnam(pwd->pw_name); if (NULL != spwd) { - pwd->pw_passwd = xstrdup (spwd->sp_pwdp); - spw_free (spwd); + pwd->pw_passwd = xstrdup(spwd->sp_pwdp); + spw_free(spwd); } if (streq(pwd->pw_passwd, "") && !streq(grp->gr_passwd, "")) { @@ -169,12 +169,12 @@ static void check_perms (const struct group *grp, * the password. Otherwise I ask for a password if she flunked one * of the tests above. */ - if ((getuid () != 0) && needspasswd) { + if ((getuid() != 0) && needspasswd) { /* * get the password from her, and set the salt for * the decryption from the group file. */ - cp = agetpass (_("Password: ")); + cp = agetpass(_("Password: ")); if (NULL == cp) { goto failure; } @@ -184,11 +184,11 @@ static void check_perms (const struct group *grp, * password in the group file. The result of this encryption * must match the previously encrypted value in the file. */ - cpasswd = pw_encrypt (cp, grp->gr_passwd); - erase_pass (cp); + cpasswd = pw_encrypt(cp, grp->gr_passwd); + erase_pass(cp); if (NULL == cpasswd) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to crypt password with previous salt: %s\n"), Prog, strerrno()); SYSLOG(LOG_INFO, @@ -202,21 +202,21 @@ static void check_perms (const struct group *grp, #ifdef WITH_AUDIT stprintf_a(audit_buf, "authentication new_gid=%lu", (unsigned long) grp->gr_gid); - audit_logger (AUDIT_GRP_AUTH, - audit_buf, NULL, getuid (), SHADOW_AUDIT_FAILURE); + audit_logger(AUDIT_GRP_AUTH, + audit_buf, NULL, getuid(), SHADOW_AUDIT_FAILURE); #endif SYSLOG(LOG_INFO, "Invalid password for group '%s' from '%s'", groupname, pwd->pw_name); - (void) sleep (1); - (void) fputs (_("Invalid password.\n"), stderr); + (void) sleep(1); + (void) fputs(_("Invalid password.\n"), stderr); goto failure; } #ifdef WITH_AUDIT stprintf_a(audit_buf, "authentication new_gid=%lu", (unsigned long) grp->gr_gid); - audit_logger (AUDIT_GRP_AUTH, - audit_buf, NULL, getuid (), SHADOW_AUDIT_SUCCESS); + audit_logger(AUDIT_GRP_AUTH, + audit_buf, NULL, getuid(), SHADOW_AUDIT_SUCCESS); #endif } @@ -226,8 +226,8 @@ static void check_perms (const struct group *grp, /* The closelog is probably unnecessary, but it does no * harm. -- JWP */ - closelog (); - exit (EXIT_FAILURE); + closelog(); + exit(EXIT_FAILURE); } /* @@ -236,18 +236,18 @@ static void check_perms (const struct group *grp, * The logout will also be logged when the user will quit the * sg/newgrp session. */ -static void syslog_sg (const char *name, const char *group) +static void syslog_sg(const char *name, const char *group) { - const char *loginname = getlogin (); - const char *tty = ttyname (0); + const char *loginname = getlogin(); + const char *tty = ttyname(0); char *free_login = NULL, *free_tty = NULL; if (loginname != NULL) { - free_login = xstrdup (loginname); + free_login = xstrdup(loginname); loginname = free_login; } if (tty != NULL) { - free_tty = xstrdup (tty); + free_tty = xstrdup(tty); tty = free_tty; } @@ -283,19 +283,19 @@ static void syslog_sg (const char *name, const char *group) /* Ignore these signals. The signal handlers will later be * restored to the default handlers. */ - (void) signal (SIGINT, SIG_IGN); - (void) signal (SIGQUIT, SIG_IGN); - (void) signal (SIGHUP, SIG_IGN); - (void) signal (SIGTSTP, SIG_IGN); - (void) signal (SIGTTIN, SIG_IGN); - (void) signal (SIGTTOU, SIG_IGN); + (void) signal(SIGINT, SIG_IGN); + (void) signal(SIGQUIT, SIG_IGN); + (void) signal(SIGHUP, SIG_IGN); + (void) signal(SIGTSTP, SIG_IGN); + (void) signal(SIGTTIN, SIG_IGN); + (void) signal(SIGTTOU, SIG_IGN); /* set SIGCHLD to default for waitpid */ (void) signal(SIGCHLD, SIG_DFL); child = fork (); if ((pid_t)-1 == child) { /* error in fork() */ - fprintf (stderr, _("%s: failure forking: %s\n"), + fprintf(stderr, _("%s: failure forking: %s\n"), is_newgrp ? "newgrp" : "sg", strerrno()); #ifdef WITH_AUDIT if (group) { @@ -303,12 +303,12 @@ static void syslog_sg (const char *name, const char *group) getuid(), "new_group", group, SHADOW_AUDIT_FAILURE); } else { - audit_logger (AUDIT_CHGRP_ID, + audit_logger(AUDIT_CHGRP_ID, "changing", NULL, getuid(), SHADOW_AUDIT_FAILURE); } #endif - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } else if (child != 0) { /* parent - wait for child to finish, then log session close */ int cst = 0; @@ -322,7 +322,7 @@ static void syslog_sg (const char *name, const char *group) if ((pid == child) && (WIFSTOPPED (cst) != 0)) { /* The child (shell) was suspended. * Suspend sg/newgrp. */ - kill (getpid (), SIGSTOP); + kill(getpid(), SIGSTOP); /* wake child when resumed */ kill (child, SIGCONT); } @@ -345,9 +345,9 @@ static void syslog_sg (const char *name, const char *group) "unknown GID '%lu' used by user '%s'", (unsigned long) gid, name); } - closelog (); - exit ((0 != WIFEXITED (cst)) ? WEXITSTATUS (cst) - : WTERMSIG (cst) + 128); + closelog(); + exit((0 != WIFEXITED(cst)) ? WEXITSTATUS(cst) + : WTERMSIG(cst) + 128); } /* child - restore signals to their default state */ @@ -366,7 +366,7 @@ static void syslog_sg (const char *name, const char *group) /* * newgrp - change the invokers current real and effective group id */ -int main (int argc, char **argv) +int main(int argc, char **argv) { bool initflag = false; bool is_member = false; @@ -421,32 +421,32 @@ int main (int argc, char **argv) * injecting arbitrary strings into our stderr/stdout, as this can * be an exploit vector. */ - is_newgrp = streq(Basename (argv[0]), "newgrp"); + is_newgrp = streq(Basename(argv[0]), "newgrp"); Prog = is_newgrp ? "newgrp" : "sg"; log_set_progname(Prog); log_set_logfd(stderr); - OPENLOG (Prog); + OPENLOG(Prog); #ifdef WITH_AUDIT - audit_help_open (); + audit_help_open(); #endif argc--; argv++; - initenv (); + initenv(); - pwd = get_my_pwent (); + pwd = get_my_pwent(); if (NULL == pwd) { - fprintf (stderr, _("%s: Cannot determine your user name.\n"), + fprintf(stderr, _("%s: Cannot determine your user name.\n"), Prog); #ifdef WITH_AUDIT - audit_logger (AUDIT_CHGRP_ID, - "changing", NULL, getuid (), SHADOW_AUDIT_FAILURE); + audit_logger(AUDIT_CHGRP_ID, + "changing", NULL, getuid(), SHADOW_AUDIT_FAILURE); #endif - SYSLOG(LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", + SYSLOG(LOG_WARN, "Cannot determine the user name of the caller(UID %lu)", (unsigned long) getuid()); - closelog (); - exit (EXIT_FAILURE); + closelog(); + exit(EXIT_FAILURE); } name = pwd->pw_name; @@ -480,8 +480,8 @@ int main (int argc, char **argv) * not "newgrp". */ if ((argc > 0) && (argv[0][0] != '-')) { - if (!is_valid_group_name (argv[0])) { - fprintf ( + if (!is_valid_group_name(argv[0])) { + fprintf( stderr, _("%s: provided group is not a valid group name\n"), Prog); goto failure; @@ -490,9 +490,9 @@ int main (int argc, char **argv) argc--; argv++; } else { - usage (); - closelog (); - exit (EXIT_FAILURE); + usage(); + closelog(); + exit(EXIT_FAILURE); } if (argc > 0) { @@ -513,11 +513,11 @@ int main (int argc, char **argv) * there aren't any flags and getting the new group name. */ if ((argc > 0) && strprefix(argv[0], "-")) { - usage (); + usage(); goto failure; } else if (argv[0] != NULL) { - if (!is_valid_group_name (argv[0])) { - fprintf ( + if (!is_valid_group_name(argv[0])) { + fprintf( stderr, _("%s: provided group is not a valid group name\n"), Prog); goto failure; @@ -531,9 +531,9 @@ int main (int argc, char **argv) * Perhaps in the past, but the default behavior now depends on the * group entry, so it had better exist. -- JWP */ - grp = xgetgrgid (pwd->pw_gid); + grp = xgetgrgid(pwd->pw_gid); if (NULL == grp) { - fprintf (stderr, + fprintf(stderr, _("%s: GID '%lu' does not exist\n"), Prog, (unsigned long) pwd->pw_gid); SYSLOG(LOG_CRIT, "GID '%lu' does not exist", @@ -624,7 +624,7 @@ int main (int argc, char **argv) * membership of the current user. */ if (!is_member) { - grp = find_matching_group (name, grp); + grp = find_matching_group(name, grp); if (NULL == grp) { /* * No matching group found. As we already know that @@ -633,12 +633,12 @@ int main (int argc, char **argv) * * Re-read the group entry for further processing. */ - grp = xgetgrnam (group); - assert (NULL != grp); + grp = xgetgrnam(group); + assert(NULL != grp); } } #ifdef SHADOWGRP - sgrp = getsgnam (group); + sgrp = getsgnam(group); if (NULL != sgrp) { grp->gr_passwd = sgrp->sg_passwd; grp->gr_mem = sgrp->sg_mem; @@ -649,15 +649,15 @@ int main (int argc, char **argv) * Check if the user is allowed to access this group. */ if (!is_member) { - check_perms (grp, pwd, group); + check_perms(grp, pwd, group); } /* * all successful validations pass through this point. The group id * will be set, and the group added to the concurrent groupset. */ - if (getdef_bool ("SYSLOG_SG_ENAB")) { - syslog_sg (name, group); + if (getdef_bool("SYSLOG_SG_ENAB")) { + syslog_sg(name, group); } gid = grp->gr_gid; @@ -681,36 +681,36 @@ int main (int argc, char **argv) * The needed structure should have been copied before, or * permission to read the database will be required. */ - endspent (); + endspent(); #ifdef SHADOWGRP - endsgent (); + endsgent(); #endif - endpwent (); - endgrent (); + endpwent(); + endgrent(); /* * Set the effective GID to the new group id and the effective UID * to the real UID. For root, this also sets the real GID to the * new group id. */ - if (setgid (gid) != 0) { - perror ("setgid"); + if (setgid(gid) != 0) { + perror("setgid"); #ifdef WITH_AUDIT stprintf_a(audit_buf, "changing new_gid=%lu", (unsigned long) gid); - audit_logger (AUDIT_CHGRP_ID, - audit_buf, NULL, getuid (), SHADOW_AUDIT_FAILURE); + audit_logger(AUDIT_CHGRP_ID, + audit_buf, NULL, getuid(), SHADOW_AUDIT_FAILURE); #endif - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } - if (setuid (getuid ()) != 0) { - perror ("setuid"); + if (setuid(getuid()) != 0) { + perror("setuid"); #ifdef WITH_AUDIT stprintf_a(audit_buf, "changing new_gid=%lu", (unsigned long) gid); - audit_logger (AUDIT_CHGRP_ID, - audit_buf, NULL, getuid (), SHADOW_AUDIT_FAILURE); + audit_logger(AUDIT_CHGRP_ID, + audit_buf, NULL, getuid(), SHADOW_AUDIT_FAILURE); #endif - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } /* @@ -718,15 +718,15 @@ int main (int argc, char **argv) * command for her using the argument that followed the "-c" flag. */ if (cflag) { - closelog (); - execl (SHELL, "sh", "-c", command, (char *) NULL); + closelog(); + execl(SHELL, "sh", "-c", command, (char *) NULL); #ifdef WITH_AUDIT stprintf_a(audit_buf, "changing new_gid=%lu", (unsigned long) gid); - audit_logger (AUDIT_CHGRP_ID, - audit_buf, NULL, getuid (), SHADOW_AUDIT_FAILURE); + audit_logger(AUDIT_CHGRP_ID, + audit_buf, NULL, getuid(), SHADOW_AUDIT_FAILURE); #endif - perror (SHELL); - exit ((errno == ENOENT) ? E_CMD_NOTFOUND : E_CMD_NOEXEC); + perror(SHELL); + exit((errno == ENOENT) ? E_CMD_NOTFOUND : E_CMD_NOEXEC); } /* @@ -746,7 +746,7 @@ int main (int argc, char **argv) * problem, try using $SHELL as a workaround; also please notify me * at jparmele@wildbear.com -- JWP */ - cp = getenv ("SHELL"); + cp = getenv("SHELL"); if (!initflag && (NULL != cp)) { prog = cp; } else if ((NULL != pwd->pw_shell) && !streq(pwd->pw_shell, "")) { @@ -759,15 +759,15 @@ int main (int argc, char **argv) * Now I try to find the basename of the login shell. This will * become argv[0] of the spawned command. */ - progbase = Basename (prog); + progbase = Basename(prog); /* * Switch back to her home directory if I am doing login * initialization. */ if (initflag) { - if (chdir (pwd->pw_dir) != 0) { - perror ("chdir"); + if (chdir(pwd->pw_dir) != 0) { + perror("chdir"); } while (NULL != *envp) { @@ -776,29 +776,29 @@ int main (int argc, char **argv) strprefix(*envp, "SHELL=") || strprefix(*envp, "TERM=")) { - addenv (*envp, NULL); + addenv(*envp, NULL); } envp++; } } else { while (NULL != *envp) { - addenv (*envp, NULL); + addenv(*envp, NULL); envp++; } } #ifdef WITH_AUDIT stprintf_a(audit_buf, "changing new_gid=%lu", (unsigned long) gid); - audit_logger (AUDIT_CHGRP_ID, - audit_buf, NULL, getuid (), SHADOW_AUDIT_SUCCESS); + audit_logger(AUDIT_CHGRP_ID, + audit_buf, NULL, getuid(), SHADOW_AUDIT_SUCCESS); #endif /* * Exec the login shell and go away. We are trying to get back to * the previous environment which should be the user's login shell. */ - err = shell (prog, initflag ? NULL : progbase, newenvp); - exit ((err == ENOENT) ? E_CMD_NOTFOUND : E_CMD_NOEXEC); + err = shell(prog, initflag ? NULL : progbase, newenvp); + exit((err == ENOENT) ? E_CMD_NOTFOUND : E_CMD_NOEXEC); /*@notreached@*/ failure: @@ -812,17 +812,17 @@ int main (int argc, char **argv) * process. The closelog is probably unnecessary, but it does no * harm. -- JWP */ - closelog (); + closelog(); #ifdef WITH_AUDIT if (NULL != group) { audit_logger_with_group(AUDIT_CHGRP_ID, "changing", NULL, getuid(), "new_group", group, SHADOW_AUDIT_FAILURE); } else { - audit_logger (AUDIT_CHGRP_ID, - "changing", NULL, getuid (), 0); + audit_logger(AUDIT_CHGRP_ID, + "changing", NULL, getuid(), 0); } #endif - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } diff --git a/src/newuidmap.c b/src/newuidmap.c index 108852eae8..cb5f4ada9a 100644 --- a/src/newuidmap.c +++ b/src/newuidmap.c @@ -111,12 +111,12 @@ int main(int argc, char **argv) } /* Who am I? */ - pw = get_my_pwent (); + pw = get_my_pwent(); if (NULL == pw) { - fprintf (stderr, + fprintf(stderr, _("%s: Cannot determine your user name.\n"), Prog); - SYSLOG(LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", + SYSLOG(LOG_WARN, "Cannot determine the user name of the caller(UID %lu)", (unsigned long) getuid()); return EXIT_FAILURE; } @@ -145,7 +145,7 @@ int main(int argc, char **argv) } if (want_subuid_file() && !sub_uid_open(O_RDONLY)) { - fprintf (stderr, + fprintf(stderr, _("%s: cannot open %s: %s\n"), Prog, sub_uid_dbname(), strerrno()); return EXIT_FAILURE; diff --git a/src/newusers.c b/src/newusers.c index 25f0841eba..723871ce51 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -118,18 +118,18 @@ extern int allow_bad_names; /* * usage - display usage message and exit */ -static void usage (int status) +static void usage(int status) { FILE *usageout = (EXIT_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options]\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -b, --badname allow bad names\n"), usageout); + (void) fputs(_(" -b, --badname allow bad names\n"), usageout); #ifndef USE_PAM - (void) fprintf (usageout, - _(" -c, --crypt-method METHOD the crypt method (one of %s)\n"), + (void) fprintf(usageout, + _(" -c, --crypt-method METHOD the crypt method(one of %s)\n"), "NONE DES MD5" " SHA256 SHA512" #if defined(USE_BCRYPT) @@ -140,27 +140,27 @@ static void usage (int status) #endif ); #endif /* !USE_PAM */ - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -r, --system create system accounts\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -r, --system create system accounts\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); #ifndef USE_PAM - (void) fputs (_(" -s, --sha-rounds number of rounds for the SHA, BCRYPT\n" + (void) fputs(_(" -s, --sha-rounds number of rounds for the SHA, BCRYPT\n" " or YESCRYPT crypt algorithms\n"), usageout); #endif /* !USE_PAM */ - (void) fputs ("\n", usageout); + (void) fputs("\n", usageout); - exit (status); + exit(status); } /* * fail_exit - undo as much as possible */ -static void fail_exit (int code, bool process_selinux) +static void fail_exit(int code, bool process_selinux) { if (spw_locked) { - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); /* continue */ } @@ -173,8 +173,8 @@ static void fail_exit (int code, bool process_selinux) } } if (gr_locked) { - if (gr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + if (gr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", gr_dbname()); /* continue */ } @@ -190,8 +190,8 @@ static void fail_exit (int code, bool process_selinux) #endif #ifdef ENABLE_SUBIDS if (sub_uid_locked) { - if (sub_uid_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname ()); + if (sub_uid_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sub_uid_dbname()); /* continue */ } @@ -205,13 +205,13 @@ static void fail_exit (int code, bool process_selinux) } #endif /* ENABLE_SUBIDS */ - exit (code); + exit(code); } /* * add_group - create a new group or add a user to an existing group */ -static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid) +static int add_group(const char *name, const char *gid, gid_t *ngid, uid_t uid) { const struct group *grp; struct group grent; @@ -224,9 +224,9 @@ static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid) * Start by seeing if the named group already exists. This will be * very easy to deal with if it does. */ - grp = getgrnam (gid); + grp = getgrnam(gid); if (NULL == grp) { - grp = gr_locate (gid); + grp = gr_locate(gid); } if (NULL != grp) { /* The user will use this ID for her primary group */ @@ -235,14 +235,14 @@ static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid) return 0; } - if (isdigit (gid[0])) { + if (isdigit(gid[0])) { /* * The GID is a number, which means either this is a brand * new group, or an existing group. */ if (get_gid(gid, &grent.gr_gid) == -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid group ID '%s'\n"), Prog, gid); return -1; @@ -251,8 +251,8 @@ static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid) /* Look in both the system database (getgrgid) and in the * internal database (gr_locate_gid), which may contain * uncommitted changes */ - if ( (getgrgid (grent.gr_gid) != NULL) - || (gr_locate_gid (grent.gr_gid) != NULL)) { + if ( (getgrgid(grent.gr_gid) != NULL) + || (gr_locate_gid(grent.gr_gid) != NULL)) { /* The user will use this ID for her * primary group */ *ngid = grent.gr_gid; @@ -280,18 +280,18 @@ static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid) * Now I have all of the fields required to create the new group. */ if (!streq(gid, "") && (!isdigit(gid[0]))) { - grent.gr_name = xstrdup (gid); + grent.gr_name = xstrdup(gid); } else { - grent.gr_name = xstrdup (name); + grent.gr_name = xstrdup(name); /* FIXME: check if the group exists */ } /* Check if this is a valid group name */ - if (!is_valid_group_name (grent.gr_name)) { - fprintf (stderr, + if (!is_valid_group_name(grent.gr_name)) { + fprintf(stderr, _("%s: invalid group name '%s'\n"), Prog, grent.gr_name); - free (grent.gr_name); + free(grent.gr_name); return -1; } @@ -344,9 +344,9 @@ static int get_user_id (const char *uid, uid_t *nuid) { * The first guess for the UID is either the numerical UID that the * caller provided, or the next available UID. */ - if (isdigit (uid[0])) { + if (isdigit(uid[0])) { if ((get_uid(uid, nuid) == -1) || (*nuid == (uid_t)-1)) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid user ID '%s'\n"), Prog, uid); return -1; @@ -379,7 +379,7 @@ static int get_user_id (const char *uid, uid_t *nuid) { /* * add_user - create a new user ID */ -static int add_user (const char *name, uid_t uid, gid_t gid) +static int add_user(const char *name, uid_t uid, gid_t gid) { struct passwd pwent; @@ -402,7 +402,7 @@ static int add_user (const char *name, uid_t uid, gid_t gid) * JUST YET, since there is still more data to be added. So, I fill * in the parts that I have. */ - pwent.pw_name = xstrdup (name); + pwent.pw_name = xstrdup(name); pwent.pw_uid = uid; pwent.pw_passwd = "x"; /* XXX warning: const */ pwent.pw_gid = gid; @@ -410,7 +410,7 @@ static int add_user (const char *name, uid_t uid, gid_t gid) pwent.pw_dir = ""; /* XXX warning: const */ pwent.pw_shell = ""; /* XXX warning: const */ - return (pw_update (&pwent) == 0) ? -1 : 0; + return (pw_update(&pwent) == 0) ? -1 : 0; } #ifndef USE_PAM @@ -419,7 +419,7 @@ static int add_user (const char *name, uid_t uid, gid_t gid) * * Return 0 if successful. */ -static int update_passwd (struct passwd *pwd, const char *password) +static int update_passwd(struct passwd *pwd, const char *password) { void *crypt_arg = NULL; char *cp; @@ -449,10 +449,10 @@ static int update_passwd (struct passwd *pwd, const char *password) if ((NULL != crypt_method) && streq(crypt_method, "NONE")) { pwd->pw_passwd = (char *)password; } else { - const char *salt = crypt_make_salt (crypt_method, crypt_arg); - cp = pw_encrypt (password, salt); + const char *salt = crypt_make_salt(crypt_method, crypt_arg); + cp = pw_encrypt(password, salt); if (NULL == cp) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to crypt password with salt '%s': %s\n"), Prog, salt, strerrno()); return 1; @@ -508,7 +508,7 @@ add_passwd(struct passwd *pwd, MAYBE_UNUSED const char *password) * harder since there are zillions of things to do ... */ if (!is_shadow) { - return update_passwd (pwd, password); + return update_passwd(pwd, password); } #endif /* USE_PAM */ @@ -516,7 +516,7 @@ add_passwd(struct passwd *pwd, MAYBE_UNUSED const char *password) * Do the first and easiest shadow file case. The user already * exists in the shadow password file. */ - sp = spw_locate (pwd->pw_name); + sp = spw_locate(pwd->pw_name); #ifndef USE_PAM if (NULL != sp) { spent = *sp; @@ -525,24 +525,24 @@ add_passwd(struct passwd *pwd, MAYBE_UNUSED const char *password) { spent.sp_pwdp = (char *)password; } else { - const char *salt = crypt_make_salt (crypt_method, + const char *salt = crypt_make_salt(crypt_method, crypt_arg); - cp = pw_encrypt (password, salt); + cp = pw_encrypt(password, salt); if (NULL == cp) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to crypt password with salt '%s': %s\n"), Prog, salt, strerrno()); return 1; } spent.sp_pwdp = cp; } - spent.sp_lstchg = gettime () / DAY; + spent.sp_lstchg = gettime() / DAY; if (0 == spent.sp_lstchg) { /* Better disable aging than requiring a password * change */ spent.sp_lstchg = -1; } - return (spw_update (&spent) == 0); + return (spw_update(&spent) == 0); } /* @@ -552,7 +552,7 @@ add_passwd(struct passwd *pwd, MAYBE_UNUSED const char *password) * the password set someplace else. */ if (!streq(pwd->pw_passwd, "x")) { - return update_passwd (pwd, password); + return update_passwd(pwd, password); } #else /* USE_PAM */ /* @@ -576,10 +576,10 @@ add_passwd(struct passwd *pwd, MAYBE_UNUSED const char *password) if ((crypt_method != NULL) && streq(crypt_method, "NONE")) { spent.sp_pwdp = (char *)password; } else { - const char *salt = crypt_make_salt (crypt_method, crypt_arg); - cp = pw_encrypt (password, salt); + const char *salt = crypt_make_salt(crypt_method, crypt_arg); + cp = pw_encrypt(password, salt); if (NULL == cp) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to crypt password with salt '%s': %s\n"), Prog, salt, strerrno()); return 1; @@ -593,7 +593,7 @@ add_passwd(struct passwd *pwd, MAYBE_UNUSED const char *password) */ spent.sp_pwdp = "!"; #endif - spent.sp_lstchg = gettime () / DAY; + spent.sp_lstchg = gettime() / DAY; if (0 == spent.sp_lstchg) { /* Better disable aging than requiring a password change */ spent.sp_lstchg = -1; @@ -613,7 +613,7 @@ add_passwd(struct passwd *pwd, MAYBE_UNUSED const char *password) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { int c; #ifndef USE_PAM @@ -633,7 +633,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, + while ((c = getopt_long(argc, argv, #ifndef USE_PAM "c:bhrs:", #else /* USE_PAM */ @@ -650,7 +650,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) break; #endif /* !USE_PAM */ case 'h': - usage (EXIT_SUCCESS); + usage(EXIT_SUCCESS); break; case 'r': rflg = true; @@ -715,7 +715,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) } /* validate options */ - check_flags (); + check_flags(); } /* @@ -723,14 +723,14 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * * It will not return if an error is encountered. */ -static void check_flags (void) +static void check_flags(void) { #ifndef USE_PAM if (sflg && !cflg) { - fprintf (stderr, + fprintf(stderr, _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-s", "-c"); - usage (EXIT_FAILURE); + usage(EXIT_FAILURE); } if (cflg) { @@ -746,10 +746,10 @@ static void check_flags (void) && !streq(crypt_method, "YESCRYPT") #endif /* USE_YESCRYPT */ ) { - fprintf (stderr, + fprintf(stderr, _("%s: unsupported crypt method: %s\n"), Prog, crypt_method); - usage (EXIT_FAILURE); + usage(EXIT_FAILURE); } } #endif /* !USE_PAM */ @@ -758,7 +758,7 @@ static void check_flags (void) /* * open_files - lock and open the password, group and shadow databases */ -static void open_files (bool process_selinux) +static void open_files(bool process_selinux) { /* * Lock the password files and open them for update. This will bring @@ -766,94 +766,94 @@ static void open_files (bool process_selinux) * modified, or new entries added. The password file is the key - if * it gets locked, assume the others can be locked right away. */ - if (pw_lock () == 0) { - fprintf (stderr, + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, pw_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } pw_locked = true; if (is_shadow) { - if (spw_lock () == 0) { - fprintf (stderr, + if (spw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, spw_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, spw_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } spw_locked = true; } - if (gr_lock () == 0) { - fprintf (stderr, + if (gr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, gr_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, gr_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } gr_locked = true; #ifdef SHADOWGRP if (is_shadow_grp) { - if (sgr_lock () == 0) { - fprintf (stderr, + if (sgr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sgr_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, sgr_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } sgr_locked = true; } #endif #ifdef ENABLE_SUBIDS if (is_sub_uid) { - if (sub_uid_lock () == 0) { - fprintf (stderr, + if (sub_uid_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sub_uid_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, sub_uid_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } sub_uid_locked = true; } if (is_sub_gid) { - if (sub_gid_lock () == 0) { - fprintf (stderr, + if (sub_gid_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sub_gid_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, sub_gid_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } sub_gid_locked = true; } #endif /* ENABLE_SUBIDS */ - if (pw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + if (pw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, pw_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } - if (is_shadow && (spw_open (O_CREAT | O_RDWR) == 0)) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, spw_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + if (is_shadow && (spw_open(O_CREAT | O_RDWR) == 0)) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, spw_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } - if (gr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + if (gr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, gr_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } #ifdef SHADOWGRP - if (is_shadow_grp && (sgr_open (O_CREAT | O_RDWR) == 0)) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + if (is_shadow_grp && (sgr_open(O_CREAT | O_RDWR) == 0)) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } #endif #ifdef ENABLE_SUBIDS if (is_sub_uid) { - if (sub_uid_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (sub_uid_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, sub_uid_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, sub_uid_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } } if (is_sub_gid) { - if (sub_gid_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (sub_gid_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, sub_gid_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, sub_gid_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } } #endif /* ENABLE_SUBIDS */ @@ -868,13 +868,13 @@ static void close_files(const struct option_flags *flags) process_selinux = !flags->chroot; - if (pw_close (process_selinux) == 0) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); + if (pw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", pw_dbname()); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -898,32 +898,32 @@ static void close_files(const struct option_flags *flags) spw_locked = false; } - if (gr_close (process_selinux) == 0) { - fprintf (stderr, + if (gr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, gr_dbname ()); + Prog, gr_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", gr_dbname()); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } #ifdef ENABLE_SUBIDS - if (is_sub_uid && (sub_uid_close (process_selinux) == 0)) { - fprintf (stderr, - _("%s: failure while writing changes to %s\n"), Prog, sub_uid_dbname ()); + if (is_sub_uid && (sub_uid_close(process_selinux) == 0)) { + fprintf(stderr, + _("%s: failure while writing changes to %s\n"), Prog, sub_uid_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", sub_uid_dbname()); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } - if (is_sub_gid && (sub_gid_close (process_selinux) == 0)) { - fprintf (stderr, - _("%s: failure while writing changes to %s\n"), Prog, sub_gid_dbname ()); + if (is_sub_gid && (sub_gid_close(process_selinux) == 0)) { + fprintf(stderr, + _("%s: failure while writing changes to %s\n"), Prog, sub_gid_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", sub_gid_dbname()); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } #endif /* ENABLE_SUBIDS */ - if (gr_unlock (process_selinux) == 0) { - fprintf (stderr, + if (gr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), - Prog, gr_dbname ()); + Prog, gr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", gr_dbname()); /* continue */ } @@ -950,8 +950,8 @@ static void close_files(const struct option_flags *flags) #endif #ifdef ENABLE_SUBIDS if (is_sub_uid) { - if (sub_uid_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname ()); + if (sub_uid_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sub_uid_dbname()); /* continue */ } @@ -968,7 +968,7 @@ static void close_files(const struct option_flags *flags) #endif /* ENABLE_SUBIDS */ } -int main (int argc, char **argv) +int main(int argc, char **argv) { char buf[BUFSIZ]; char *fields[7]; @@ -989,9 +989,9 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); /* FIXME: will not work with an input file */ process_root_flag ("-R", argc, argv); @@ -1025,21 +1025,21 @@ int main (int argc, char **argv) while (fgets_a(buf, stdin) != NULL) { line++; if (stpsep(buf, "\n") == NULL && feof(stdin) == 0) { - fprintf (stderr, _("%s: line %jd: line too long\n"), + fprintf(stderr, _("%s: line %jd: line too long\n"), Prog, line); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } if (strsep2arr_a(buf, ":", fields) == -1) { - fprintf (stderr, _("%s: line %jd: invalid line\n"), + fprintf(stderr, _("%s: line %jd: invalid line\n"), Prog, line); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } /* * First check if we have to create or update a user */ - pw = pw_locate (fields[0]); + pw = pw_locate(fields[0]); /* local, no need for xgetpwnam */ if (NULL == pw && getpwnam(fields[0]) != NULL) { fprintf (stderr, @@ -1068,11 +1068,11 @@ int main (int argc, char **argv) * will be made up. */ if ( (NULL == pw) - && (add_group (fields[0], fields[3], &gid, uid) != 0)) { - fprintf (stderr, + && (add_group(fields[0], fields[3], &gid, uid) != 0)) { + fprintf(stderr, _("%s: line %jd: can't create group\n"), Prog, line); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } /* @@ -1083,23 +1083,23 @@ int main (int argc, char **argv) * will at least be a (struct passwd) for the user. */ if ( (NULL == pw) - && (add_user (fields[0], uid, gid) != 0)) { - fprintf (stderr, + && (add_user(fields[0], uid, gid) != 0)) { + fprintf(stderr, _("%s: line %jd: can't create user\n"), Prog, line); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } /* * The password, gecos field, directory, and shell fields * all come next. */ - pw = pw_locate (fields[0]); + pw = pw_locate(fields[0]); if (NULL == pw) { - fprintf (stderr, + fprintf(stderr, _("%s: line %jd: user '%s' does not exist in %s\n"), - Prog, line, fields[0], pw_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, line, fields[0], pw_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } newpw = *pw; @@ -1138,39 +1138,39 @@ int main (int argc, char **argv) if ( !streq(fields[5], "") && (access (newpw.pw_dir, F_OK) != 0)) { /* FIXME: should check for directory */ - mode_t mode = getdef_num ("HOME_MODE", - 0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK)); + mode_t mode = getdef_num("HOME_MODE", + 0777 & ~getdef_num("UMASK", GETDEF_DEFAULT_UMASK)); if (newpw.pw_dir[0] != '/') { fprintf(stderr, _("%s: line %jd: homedir must be an absolute path\n"), Prog, line); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } - if (mkdir (newpw.pw_dir, mode) != 0) { - fprintf (stderr, + if (mkdir(newpw.pw_dir, mode) != 0) { + fprintf(stderr, _("%s: line %jd: mkdir %s failed: %s\n"), Prog, line, newpw.pw_dir, strerrno()); if (errno != EEXIST) { - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } } if (chown(newpw.pw_dir, newpw.pw_uid, newpw.pw_gid) != 0) { - fprintf (stderr, + fprintf(stderr, _("%s: line %jd: chown %s failed: %s\n"), Prog, line, newpw.pw_dir, strerrno()); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } } /* * Update the password entry with the new changes made. */ - if (pw_update (&newpw) == 0) { - fprintf (stderr, + if (pw_update(&newpw) == 0) { + fprintf(stderr, _("%s: line %jd: can't update entry\n"), Prog, line); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } #ifdef ENABLE_SUBIDS @@ -1182,17 +1182,17 @@ int main (int argc, char **argv) unsigned long sub_uid_count = 0; if (find_new_sub_uids(&sub_uid_start, &sub_uid_count) != 0) { - fprintf (stderr, + fprintf(stderr, _("%s: can't find subordinate user range\n"), Prog); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } if (sub_uid_add(fields[0], sub_uid_start, sub_uid_count) == 0) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to prepare new %s entry\n"), - Prog, sub_uid_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, sub_uid_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } } @@ -1203,16 +1203,16 @@ int main (int argc, char **argv) gid_t sub_gid_start = 0; unsigned long sub_gid_count = 0; if (find_new_sub_gids(&sub_gid_start, &sub_gid_count) != 0) { - fprintf (stderr, + fprintf(stderr, _("%s: can't find subordinate group range\n"), Prog); - fail_exit (EXIT_FAILURE, process_selinux); + fail_exit(EXIT_FAILURE, process_selinux); } if (sub_gid_add(fields[0], sub_gid_start, sub_gid_count) == 0) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to prepare new %s entry\n"), - Prog, sub_uid_dbname ()); - fail_exit (EXIT_FAILURE, process_selinux); + Prog, sub_uid_dbname()); + fail_exit(EXIT_FAILURE, process_selinux); } } #endif /* ENABLE_SUBIDS */ @@ -1225,11 +1225,11 @@ int main (int argc, char **argv) * changes to be written out all at once, and then unlocked * afterwards. */ - close_files (&flags); + close_files(&flags); - nscd_flush_cache ("passwd"); - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP); + nscd_flush_cache("passwd"); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_PASSWD | SSSD_DB_GROUP); #ifdef USE_PAM /* Now update the passwords using PAM */ diff --git a/src/nologin.c b/src/nologin.c index a74428186a..7dee4e6b8f 100644 --- a/src/nologin.c +++ b/src/nologin.c @@ -12,16 +12,16 @@ #include #include -int main (void) +int main(void) { const char *user, *tty; uid_t uid; - tty = ttyname (0); + tty = ttyname(0); if (NULL == tty) { tty = "UNKNOWN"; } - user = getlogin (); + user = getlogin(); if (NULL == user) { user = "UNKNOWN"; } diff --git a/src/passwd.c b/src/passwd.c index 6fd2366e91..8e91dab7a3 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -147,36 +147,36 @@ static void update_shadow(bool); */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] [LOGIN]\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -a, --all report password status on all accounts\n"), usageout); - (void) fputs (_(" -d, --delete delete the password for the named account\n"), usageout); - (void) fputs (_(" -e, --expire force expire the password for the named account\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -k, --keep-tokens change password only if expired\n"), usageout); - (void) fputs (_(" -i, --inactive INACTIVE set password inactive after expiration\n" + (void) fputs(_(" -a, --all report password status on all accounts\n"), usageout); + (void) fputs(_(" -d, --delete delete the password for the named account\n"), usageout); + (void) fputs(_(" -e, --expire force expire the password for the named account\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -k, --keep-tokens change password only if expired\n"), usageout); + (void) fputs(_(" -i, --inactive INACTIVE set password inactive after expiration\n" " to INACTIVE\n"), usageout); - (void) fputs (_(" -l, --lock lock the password of the named account\n"), usageout); - (void) fputs (_(" -n, --mindays MIN_DAYS set minimum number of days before password\n" + (void) fputs(_(" -l, --lock lock the password of the named account\n"), usageout); + (void) fputs(_(" -n, --mindays MIN_DAYS set minimum number of days before password\n" " change to MIN_DAYS\n"), usageout); - (void) fputs (_(" -q, --quiet quiet mode\n"), usageout); - (void) fputs (_(" -r, --repository REPOSITORY change password in REPOSITORY repository\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout); - (void) fputs (_(" -S, --status report password status on the named account\n"), usageout); - (void) fputs (_(" -u, --unlock unlock the password of the named account\n"), usageout); - (void) fputs (_(" -w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS\n"), usageout); - (void) fputs (_(" -x, --maxdays MAX_DAYS set maximum number of days before password\n" + (void) fputs(_(" -q, --quiet quiet mode\n"), usageout); + (void) fputs(_(" -r, --repository REPOSITORY change password in REPOSITORY repository\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout); + (void) fputs(_(" -S, --status report password status on the named account\n"), usageout); + (void) fputs(_(" -u, --unlock unlock the password of the named account\n"), usageout); + (void) fputs(_(" -w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS\n"), usageout); + (void) fputs(_(" -x, --maxdays MAX_DAYS set maximum number of days before password\n" " change to MAX_DAYS\n"), usageout); - (void) fputs (_(" -s, --stdin read new token from stdin\n"), usageout); - (void) fputs ("\n", usageout); - exit (status); + (void) fputs(_(" -s, --stdin read new token from stdin\n"), usageout); + (void) fputs("\n", usageout); + exit(status); } @@ -184,7 +184,7 @@ usage (int status) * new_password - validate old password and replace with new (both old and * new in global "char crypt_passwd[128]") */ -static int new_password (const struct passwd *pw) +static int new_password(const struct passwd *pw) { char *clear; /* Pointer to clear text */ char *cipher; /* Pointer to cipher text */ @@ -202,16 +202,16 @@ static int new_password (const struct passwd *pw) */ if (!amroot && !streq(crypt_passwd, "")) { - clear = agetpass (_("Old password: ")); + clear = agetpass(_("Old password: ")); if (NULL == clear) { return -1; } - cipher = pw_encrypt (clear, crypt_passwd); + cipher = pw_encrypt(clear, crypt_passwd); if (NULL == cipher) { - erase_pass (clear); - fprintf (stderr, + erase_pass(clear); + fprintf(stderr, _("%s: failed to crypt password with previous salt: %s\n"), Prog, strerrno()); SYSLOG(LOG_INFO, @@ -221,18 +221,18 @@ static int new_password (const struct passwd *pw) } if (!streq(cipher, crypt_passwd)) { - erase_pass (clear); - strzero (cipher); + erase_pass(clear); + strzero(cipher); SYSLOG(LOG_WARN, "incorrect password for %s", pw->pw_name); - (void) sleep (1); - (void) fprintf (stderr, + (void) sleep(1); + (void) fprintf(stderr, _("Incorrect password for %s.\n"), pw->pw_name); return -1; } strtcpy_a(orig, clear); - erase_pass (clear); - strzero (cipher); + erase_pass(clear); + strzero(cipher); } else { strcpy(orig, ""); } @@ -248,13 +248,13 @@ static int new_password (const struct passwd *pw) obscure_get_range(&pass_min_len, &pass_max_len); if (pass_max_len == -1) { - (void) printf (_( -"Enter the new password (minimum of %d characters)\n" + (void) printf(_( +"Enter the new password(minimum of %d characters)\n" "Please use a combination of upper and lower case letters and numbers.\n"), pass_min_len); } else { - (void) printf (_( -"Enter the new password (minimum of %d, maximum of %d characters)\n" + (void) printf(_( +"Enter the new password(minimum of %d, maximum of %d characters)\n" "Please use a combination of upper and lower case letters and numbers.\n"), pass_min_len, pass_max_len); } @@ -264,21 +264,21 @@ static int new_password (const struct passwd *pw) /* * root is setting the passphrase from stdin */ - cp = agetpass_stdin (); + cp = agetpass_stdin(); if (NULL == cp) { return -1; } ret = strtcpy_a(pass, cp); - erase_pass (cp); + erase_pass(cp); if (ret == -1) { - (void) fputs (_("Password is too long.\n"), stderr); + (void) fputs(_("Password is too long.\n"), stderr); memzero_a(pass); return -1; } } else { warned = false; - for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) { - cp = agetpass (_("New password: ")); + for (i = getdef_num("PASS_CHANGE_TRIES", 5); i > 0; i--) { + cp = agetpass(_("New password: ")); if (NULL == cp) { memzero_a(orig); memzero_a(pass); @@ -288,16 +288,16 @@ static int new_password (const struct passwd *pw) warned = false; } ret = strtcpy_a(pass, cp); - erase_pass (cp); + erase_pass(cp); if (ret == -1) { - (void) fputs (_("Password is too long.\n"), stderr); + (void) fputs(_("Password is too long.\n"), stderr); memzero_a(orig); memzero_a(pass); return -1; } if (!amroot && !obscure(orig, pass)) { - (void) puts (_("Try again.")); + (void) puts(_("Try again.")); continue; } @@ -306,23 +306,23 @@ static int new_password (const struct passwd *pw) * root (enter this password again to use it anyway). * --marekm */ - if (amroot && !warned && getdef_bool ("PASS_ALWAYS_WARN") + if (amroot && !warned && getdef_bool("PASS_ALWAYS_WARN") && !obscure(orig, pass)) { - (void) puts (_("\nWarning: weak password (enter it again to use it anyway).")); + (void) puts(_("\nWarning: weak password(enter it again to use it anyway).")); warned = true; continue; } - cp = agetpass (_("Re-enter new password: ")); + cp = agetpass(_("Re-enter new password: ")); if (NULL == cp) { memzero_a(orig); memzero_a(pass); return -1; } if (!streq(cp, pass)) { - erase_pass (cp); - (void) fputs (_("They don't match; try again.\n"), stderr); + erase_pass(cp); + (void) fputs(_("They don't match; try again.\n"), stderr); } else { - erase_pass (cp); + erase_pass(cp); break; } } @@ -338,12 +338,12 @@ static int new_password (const struct passwd *pw) /* * Encrypt the password, then wipe the cleartext password. */ - salt = crypt_make_salt (NULL, NULL); - cp = pw_encrypt (pass, salt); + salt = crypt_make_salt(NULL, NULL); + cp = pw_encrypt(pass, salt); memzero_a(pass); if (NULL == cp) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to crypt password with salt '%s': %s\n"), Prog, salt, strerrno()); return -1; @@ -359,11 +359,11 @@ static int new_password (const struct passwd *pw) * check_password() sees if the invoker has permission to change the * password for the given user. */ -static void check_password (const struct passwd *pw, const struct spwd *sp, bool process_selinux) +static void check_password(const struct passwd *pw, const struct spwd *sp, bool process_selinux) { int exp_status; - exp_status = isexpired (pw, sp); + exp_status = isexpired(pw, sp); /* * If not expired and the "change only if expired" option (idea from @@ -390,11 +390,11 @@ static void check_password (const struct passwd *pw, const struct spwd *sp, bool || (exp_status > 1) || ( (sp->sp_max >= 0) && (sp->sp_min > sp->sp_max))) { - (void) fprintf (stderr, + (void) fprintf(stderr, _("The password for %s cannot be changed.\n"), sp->sp_namp); SYSLOG(LOG_WARN, "password locked for '%s'", sp->sp_namp); - closelog (); + closelog(); fail_exit(E_NOPERM, process_selinux); } @@ -411,11 +411,11 @@ static void check_password (const struct passwd *pw, const struct spwd *sp, bool } if (now < ok) { - (void) fprintf (stderr, + (void) fprintf(stderr, _("The password for %s cannot be changed yet.\n"), sp->sp_namp); SYSLOG(LOG_WARN, "now < minimum age for '%s'", sp->sp_namp); - closelog (); + closelog(); fail_exit(E_NOPERM, process_selinux); } } @@ -435,7 +435,7 @@ static /*@observer@*/const char *pw_status (const char *pass) /* * print_status - print current password status */ -static void print_status (const struct passwd *pw) +static void print_status(const struct passwd *pw) { char date[80]; struct spwd *sp; @@ -474,8 +474,8 @@ fail_exit (int status, bool process_selinux) } if (pw_locked) { - if (pw_unlock (process_selinux) == 0) { - (void) fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + (void) fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -499,36 +499,36 @@ oom (bool process_selinux) */ static void open_files(bool process_selinux) { - if (pw_lock () == 0) { - (void) fprintf (stderr, + if (pw_lock() == 0) { + (void) fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - exit (E_PWDBUSY); + Prog, pw_dbname()); + exit(E_PWDBUSY); } pw_locked = true; - if (pw_open (O_CREAT | O_RDWR) == 0) { - (void) fprintf (stderr, + if (pw_open(O_CREAT | O_RDWR) == 0) { + (void) fprintf(stderr, _("%s: cannot open %s\n"), - Prog, pw_dbname ()); + Prog, pw_dbname()); SYSLOG(LOG_WARN, "cannot open %s", pw_dbname()); - fail_exit (E_MISSING, process_selinux); + fail_exit(E_MISSING, process_selinux); } - if (!spw_file_present ()) + if (!spw_file_present()) return; - if (spw_lock () == 0) { - (void) fprintf (stderr, + if (spw_lock() == 0) { + (void) fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, spw_dbname ()); - fail_exit (E_PWDBUSY, process_selinux); + Prog, spw_dbname()); + fail_exit(E_PWDBUSY, process_selinux); } spw_locked = true; - if (spw_open (O_CREAT | O_RDWR) == 0) { - (void) fprintf (stderr, + if (spw_open(O_CREAT | O_RDWR) == 0) { + (void) fprintf(stderr, _("%s: cannot open %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); SYSLOG(LOG_WARN, "cannot open %s", spw_dbname()); - fail_exit (E_FAILURE, process_selinux); + fail_exit(E_FAILURE, process_selinux); } } @@ -541,17 +541,17 @@ static void open_files(bool process_selinux) static void close_files(bool process_selinux) { if (spw_locked) { - if (spw_close (process_selinux) == 0) { - (void) fprintf (stderr, + if (spw_close(process_selinux) == 0) { + (void) fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", spw_dbname()); - fail_exit (E_FAILURE, process_selinux); + fail_exit(E_FAILURE, process_selinux); } - if (spw_unlock (process_selinux) == 0) { - (void) fprintf (stderr, + if (spw_unlock(process_selinux) == 0) { + (void) fprintf(stderr, _("%s: failed to unlock %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); /* continue */ } @@ -574,12 +574,12 @@ static void close_files(bool process_selinux) pw_locked = false; } -static char *update_crypt_pw (char *cp, bool process_selinux) +static char *update_crypt_pw(char *cp, bool process_selinux) { if (!use_pam) { if (do_update_pwd) { - cp = xstrdup (crypt_passwd); + cp = xstrdup(crypt_passwd); } } @@ -588,11 +588,11 @@ static char *update_crypt_pw (char *cp, bool process_selinux) if (uflg && strprefix(cp, "!")) { if (cp[1] == '\0') { - (void) fprintf (stderr, + (void) fprintf(stderr, _("%s: unlocking the password would result in a passwordless account.\n" "You should set a password with usermod -p to unlock the password of this account.\n"), Prog); - fail_exit (E_FAILURE, process_selinux); + fail_exit(E_FAILURE, process_selinux); } else { cp++; } @@ -605,7 +605,7 @@ static char *update_crypt_pw (char *cp, bool process_selinux) if (!use_pam) { if (do_update_pwd) { - free (cp); + free(cp); } } cp = newpw; @@ -620,19 +620,19 @@ static void update_noshadow(bool process_selinux) struct passwd *npw; int ret; - pw = pw_locate (name); + pw = pw_locate(name); if (NULL == pw) { - (void) fprintf (stderr, + (void) fprintf(stderr, _("%s: user '%s' does not exist in %s\n"), - Prog, name, pw_dbname ()); - fail_exit (E_NOPERM, process_selinux); + Prog, name, pw_dbname()); + fail_exit(E_NOPERM, process_selinux); } check_password(pw, pwd_to_spwd(pw), process_selinux); - npw = __pw_dup (pw); + npw = __pw_dup(pw); if (NULL == npw) { - oom (process_selinux); + oom(process_selinux); } - npw->pw_passwd = update_crypt_pw (npw->pw_passwd, process_selinux); + npw->pw_passwd = update_crypt_pw(npw->pw_passwd, process_selinux); ret = pw_update(npw); #ifdef WITH_AUDIT if (lflg) { @@ -655,10 +655,10 @@ static void update_noshadow(bool process_selinux) } #endif /* WITH_AUDIT */ if (ret == 0) { - (void) fprintf (stderr, + (void) fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, pw_dbname (), npw->pw_name); - fail_exit (E_FAILURE, process_selinux); + Prog, pw_dbname(), npw->pw_name); + fail_exit(E_FAILURE, process_selinux); } } @@ -673,8 +673,8 @@ static void update_shadow(bool process_selinux) if (NULL == pw) { fprintf(stderr, _("%s: user '%s' does not exist in %s\n"), - Prog, name, pw_dbname ()); - fail_exit (E_NOPERM, process_selinux); + Prog, name, pw_dbname()); + fail_exit(E_NOPERM, process_selinux); } sp = spw_locked ? spw_locate(name) : NULL; @@ -832,9 +832,9 @@ main(int argc, char **argv) * The program behaves differently when executed by root than when * executed by a normal user. */ - amroot = (getuid () == 0); + amroot = (getuid() == 0); - OPENLOG (Prog); + OPENLOG(Prog); { /* @@ -862,7 +862,7 @@ main(int argc, char **argv) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "adehi:kln:qr:R:P:Suw:x:s", + while ((c = getopt_long(argc, argv, "adehi:kln:qr:R:P:Suw:x:s", long_options, NULL)) != -1) { switch (c) { case 'a': @@ -877,7 +877,7 @@ main(int argc, char **argv) anyflag = true; break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'i': if (a2sl(&inact, optarg, NULL, 0, -1, LONG_MAX) @@ -918,10 +918,10 @@ main(int argc, char **argv) /* -r repository (files|nis|nisplus) */ /* only "files" supported for now */ if (!streq(optarg, "files")) { - fprintf (stderr, + fprintf(stderr, _("%s: repository %s not supported\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } break; case 'R': /* no-op, handled in process_root_flag () */ @@ -982,20 +982,20 @@ main(int argc, char **argv) * command line if possible. Otherwise it is figured out from the * environment. */ - pw = get_my_pwent (); + pw = get_my_pwent(); if (NULL == pw) { - (void) fprintf (stderr, + (void) fprintf(stderr, _("%s: Cannot determine your user name.\n"), Prog); - SYSLOG(LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", + SYSLOG(LOG_WARN, "Cannot determine the user name of the caller(UID %lu)", (unsigned long) getuid()); - exit (E_NOPERM); + exit(E_NOPERM); } - myname = xstrdup (pw->pw_name); + myname = xstrdup(pw->pw_name); if (optind < argc) { - if (!is_valid_user_name (argv[optind])) { - fprintf (stderr, _("%s: Provided user name is not a valid name\n"), Prog); - fail_exit (E_NOPERM, process_selinux); + if (!is_valid_user_name(argv[optind])) { + fprintf(stderr, _("%s: Provided user name is not a valid name\n"), Prog); + fail_exit(E_NOPERM, process_selinux); } name = argv[optind]; } else { @@ -1006,7 +1006,7 @@ main(int argc, char **argv) * Make sure that at most one username was specified. */ if (argc > (optind+1)) { - usage (E_USAGE); + usage(E_USAGE); } /* @@ -1015,27 +1015,27 @@ main(int argc, char **argv) */ if (aflg) { if (anyflag || !Sflg || (optind < argc)) { - usage (E_USAGE); + usage(E_USAGE); } if (!amroot) { - (void) fprintf (stderr, + (void) fprintf(stderr, _("%s: Permission denied.\n"), Prog); - exit (E_NOPERM); + exit(E_NOPERM); } - prefix_setpwent (); - while ( (pw = prefix_getpwent ()) != NULL ) { - print_status (pw); + prefix_setpwent(); + while ( (pw = prefix_getpwent()) != NULL ) { + print_status(pw); } - prefix_endpwent (); - exit (E_SUCCESS); + prefix_endpwent(); + exit(E_SUCCESS); } #if 0 /* * Allow certain users (administrators) to change passwords of * certain users. Not implemented yet. --marekm */ - if (may_change_passwd (myname, name)) + if (may_change_passwd(myname, name)) amroot = 1; #endif @@ -1051,12 +1051,12 @@ main(int argc, char **argv) * doesn't require username. --marekm */ if (anyflag && optind >= argc) { - usage (E_USAGE); + usage(E_USAGE); } if ( (Sflg && kflg) || (anyflag && (Sflg || kflg))) { - usage (E_USAGE); + usage(E_USAGE); } if (anyflag && !amroot) { @@ -1066,21 +1066,21 @@ main(int argc, char **argv) NULL, getuid(), SHADOW_AUDIT_FAILURE); #endif /* WITH_AUDIT */ - (void) fprintf (stderr, _("%s: Permission denied.\n"), Prog); - exit (E_NOPERM); + (void) fprintf(stderr, _("%s: Permission denied.\n"), Prog); + exit(E_NOPERM); } - pw = xprefix_getpwnam (name); + pw = xprefix_getpwnam(name); if (NULL == pw) { - (void) fprintf (stderr, + (void) fprintf(stderr, _("%s: user '%s' does not exist\n"), Prog, name); - exit (E_NOPERM); + exit(E_NOPERM); } #ifdef WITH_SELINUX /* only do this check when getuid()==0 because it's a pre-condition for changing a password without entering the old one */ - if (amroot && (check_selinux_permit (Prog) != 0)) { + if (amroot && (check_selinux_permit(Prog) != 0)) { #ifdef WITH_AUDIT audit_logger(AUDIT_USER_CHAUTHTOK, "attempted-to-change-password", @@ -1093,7 +1093,7 @@ main(int argc, char **argv) (void) fprintf(stderr, _("%s: root is not authorized by SELinux to change the password of %s\n"), Prog, name); - exit (E_NOPERM); + exit(E_NOPERM); } #endif /* WITH_SELINUX */ @@ -1101,26 +1101,26 @@ main(int argc, char **argv) * If the UID of the user does not match the current real UID, * check if I'm root. */ - if (!amroot && (pw->pw_uid != getuid ())) { + if (!amroot && (pw->pw_uid != getuid())) { #ifdef WITH_AUDIT audit_logger(AUDIT_USER_CHAUTHTOK, "attempted-to-change-password", NULL, pw->pw_uid, SHADOW_AUDIT_FAILURE); #endif /* WITH_AUDIT */ - (void) fprintf (stderr, + (void) fprintf(stderr, _("%s: You may not view or modify password information for %s.\n"), Prog, name); SYSLOG(LOG_WARN, "can't view or modify password information for %s", name); - closelog (); - exit (E_NOPERM); + closelog(); + exit(E_NOPERM); } if (Sflg) { - print_status (pw); - exit (E_SUCCESS); + print_status(pw); + exit(E_SUCCESS); } if (!use_pam) { @@ -1156,15 +1156,15 @@ main(int argc, char **argv) * Let the user know whose password is being changed. */ if (!qflg) { - (void) printf (_("Changing password for %s\n"), name); + (void) printf(_("Changing password for %s\n"), name); } - if (new_password (pw) != 0) { - (void) fprintf (stderr, + if (new_password(pw) != 0) { + (void) fprintf(stderr, _("The password for %s is unchanged.\n"), name); - closelog (); - exit (E_NOPERM); + closelog(); + exit(E_NOPERM); } do_update_pwd = true; do_update_age = true; @@ -1177,7 +1177,7 @@ main(int argc, char **argv) * against unexpected signals. Any keyboard signals are set to be * ignored. */ - pwd_init (); + pwd_init(); #ifdef USE_PAM /* @@ -1185,41 +1185,41 @@ main(int argc, char **argv) */ if (!anyflag && use_pam) { if (sflg) { - cp = agetpass_stdin (); + cp = agetpass_stdin(); if (cp == NULL) { - exit (E_FAILURE); + exit(E_FAILURE); } - do_pam_passwd_non_interactive ("passwd", name, cp); - erase_pass (cp); + do_pam_passwd_non_interactive("passwd", name, cp); + erase_pass(cp); } else { - do_pam_passwd (name, qflg, kflg); + do_pam_passwd(name, qflg, kflg); } - exit (E_SUCCESS); + exit(E_SUCCESS); } #endif /* USE_PAM */ - if (setuid (0) != 0) { - (void) fputs (_("Cannot change ID to root.\n"), stderr); + if (setuid(0) != 0) { + (void) fputs(_("Cannot change ID to root.\n"), stderr); SYSLOG(LOG_ERR, "can't setuid(0)"); - closelog (); - exit (E_NOPERM); + closelog(); + exit(E_NOPERM); } open_files(process_selinux); update_shadow(process_selinux); close_files(process_selinux); - nscd_flush_cache ("passwd"); - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP); + nscd_flush_cache("passwd"); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_PASSWD | SSSD_DB_GROUP); SYSLOG(LOG_INFO, "password for '%s' changed by '%s'", name, myname); - closelog (); + closelog(); if (!qflg) { if (!anyflag) { #ifndef USE_PAM - (void) printf (_("%s: password changed.\n"), Prog); + (void) printf(_("%s: password changed.\n"), Prog); #endif /* USE_PAM */ } else { - (void) printf (_("%s: password changed.\n"), Prog); + (void) printf(_("%s: password changed.\n"), Prog); } } diff --git a/src/pwck.c b/src/pwck.c index 9d980dd5f1..8e88b4d3c8 100644 --- a/src/pwck.c +++ b/src/pwck.c @@ -87,11 +87,11 @@ extern int allow_bad_names; /* * fail_exit - do some cleanup and exit with the given error code */ -static void fail_exit (int code, bool process_selinux) +static void fail_exit(int code, bool process_selinux) { if (spw_locked) { - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname()); if (use_system_spw_file) { SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); } @@ -109,21 +109,21 @@ static void fail_exit (int code, bool process_selinux) } } - closelog (); + closelog(); - exit (code); + exit(code); } /* * usage - print syntax message and exit */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; #ifdef WITH_TCB - if (getdef_bool ("USE_TCB")) { - (void) fprintf (usageout, + if (getdef_bool("USE_TCB")) { + (void) fprintf(usageout, _("Usage: %s [options] [passwd]\n" "\n" "Options:\n"), @@ -131,26 +131,26 @@ usage (int status) } else #endif /* WITH_TCB */ { - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] [passwd [shadow]]\n" "\n" "Options:\n"), Prog); } - (void) fputs (_(" -b, --badname allow bad names\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -q, --quiet report errors only\n"), usageout); - (void) fputs (_(" -r, --read-only display errors and warnings\n" + (void) fputs(_(" -b, --badname allow bad names\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -q, --quiet report errors only\n"), usageout); + (void) fputs(_(" -r, --read-only display errors and warnings\n" " but do not change files\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); #ifdef WITH_TCB - if (!getdef_bool ("USE_TCB")) + if (!getdef_bool("USE_TCB")) #endif /* !WITH_TCB */ { - (void) fputs (_(" -s, --sort sort entries by UID\n"), usageout); + (void) fputs(_(" -s, --sort sort entries by UID\n"), usageout); } - (void) fputs ("\n", usageout); - exit (status); + (void) fputs("\n", usageout); + exit(status); } /* @@ -158,7 +158,7 @@ usage (int status) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { int c; static struct option long_options[] = { @@ -174,14 +174,14 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) /* * Parse the command line arguments */ - while ((c = getopt_long (argc, argv, "behqrR:s", + while ((c = getopt_long(argc, argv, "behqrR:s", long_options, NULL)) != -1) { switch (c) { case 'b': allow_bad_names = true; break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'e': /* added for Debian shadow-961025-2 compatibility */ case 'q': @@ -210,7 +210,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * Make certain we have the right number of arguments */ if (argc > (optind + 2)) { - usage (E_USAGE); + usage(E_USAGE); } /* @@ -218,23 +218,23 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * and shadow password filenames. */ if (optind != argc) { - pw_setdbname (argv[optind]); + pw_setdbname(argv[optind]); use_system_pw_file = false; } if ((optind + 2) == argc) { #ifdef WITH_TCB - if (getdef_bool ("USE_TCB")) { - fprintf (stderr, + if (getdef_bool("USE_TCB")) { + fprintf(stderr, _("%s: no alternative shadow file allowed when USE_TCB is enabled.\n"), Prog); - usage (E_USAGE); + usage(E_USAGE); } #endif /* WITH_TCB */ - spw_setdbname (argv[optind + 1]); + spw_setdbname(argv[optind + 1]); is_shadow = true; use_system_spw_file = false; } else if (optind == argc) { - is_shadow = spw_file_present (); + is_shadow = spw_file_present(); } } @@ -248,7 +248,7 @@ static void open_files(const struct option_flags *flags) { bool use_tcb = false; #ifdef WITH_TCB - use_tcb = getdef_bool ("USE_TCB"); + use_tcb = getdef_bool("USE_TCB"); #endif /* WITH_TCB */ bool process_selinux; @@ -258,19 +258,19 @@ static void open_files(const struct option_flags *flags) * Lock the files if we aren't in "read-only" mode */ if (!read_only) { - if (pw_lock () == 0) { - fprintf (stderr, + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - fail_exit (E_CANTLOCK, process_selinux); + Prog, pw_dbname()); + fail_exit(E_CANTLOCK, process_selinux); } pw_locked = true; if (is_shadow && !use_tcb) { - if (spw_lock () == 0) { - fprintf (stderr, + if (spw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, spw_dbname ()); - fail_exit (E_CANTLOCK, process_selinux); + Prog, spw_dbname()); + fail_exit(E_CANTLOCK, process_selinux); } spw_locked = true; } @@ -280,22 +280,22 @@ static void open_files(const struct option_flags *flags) * Open the files. Use O_RDONLY if we are in read_only mode, O_RDWR * otherwise. */ - if (pw_open (read_only ? O_RDONLY : O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), - Prog, pw_dbname ()); + if (pw_open(read_only ? O_RDONLY : O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), + Prog, pw_dbname()); if (use_system_pw_file) { SYSLOG(LOG_WARN, "cannot open %s", pw_dbname()); } - fail_exit (E_CANTOPEN, process_selinux); + fail_exit(E_CANTOPEN, process_selinux); } if (is_shadow && !use_tcb) { - if (spw_open (read_only ? O_RDONLY : O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), - Prog, spw_dbname ()); + if (spw_open(read_only ? O_RDONLY : O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), + Prog, spw_dbname()); if (use_system_spw_file) { SYSLOG(LOG_WARN, "cannot open %s", spw_dbname()); } - fail_exit (E_CANTOPEN, process_selinux); + fail_exit(E_CANTOPEN, process_selinux); } spw_opened = true; } @@ -319,27 +319,27 @@ static void close_files(bool changed, const struct option_flags *flags) * changes to the files. */ if (changed) { - if (pw_close (process_selinux) == 0) { - fprintf (stderr, + if (pw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, pw_dbname ()); + Prog, pw_dbname()); if (use_system_pw_file) { SYSLOG(LOG_ERR, "failure while writing changes to %s", pw_dbname()); } - fail_exit (E_CANTUPDATE, process_selinux); + fail_exit(E_CANTUPDATE, process_selinux); } - if (spw_opened && (spw_close (process_selinux) == 0)) { - fprintf (stderr, + if (spw_opened && (spw_close(process_selinux) == 0)) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); if (use_system_spw_file) { SYSLOG(LOG_ERR, "failure while writing changes to %s", spw_dbname()); } - fail_exit (E_CANTUPDATE, process_selinux); + fail_exit(E_CANTUPDATE, process_selinux); } spw_opened = false; } @@ -348,10 +348,10 @@ static void close_files(bool changed, const struct option_flags *flags) * Don't be anti-social - unlock the files when you're done. */ if (spw_locked) { - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); if (use_system_spw_file) { SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); } @@ -381,8 +381,8 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags struct commonio_entry *pfe, *tpfe; struct passwd *pwd; const struct spwd *spw; - uid_t min_sys_id = getdef_ulong ("SYS_UID_MIN", 101UL); - uid_t max_sys_id = getdef_ulong ("SYS_UID_MAX", 999UL); + uid_t min_sys_id = getdef_ulong("SYS_UID_MIN", 101UL); + uid_t max_sys_id = getdef_ulong("SYS_UID_MAX", 999UL); bool process_selinux; process_selinux = !flags->chroot; @@ -390,7 +390,7 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags /* * Loop through the entire password file. */ - for (pfe = __pw_get_head (); NULL != pfe; pfe = pfe->next) { + for (pfe = __pw_get_head(); NULL != pfe; pfe = pfe->next) { /* * If this is a NIS line, skip it. You can't "know" what NIS * is going to do without directly asking NIS ... @@ -409,14 +409,14 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags * Tell the user this entire line is bogus and ask * them to delete it. */ - puts (_("invalid password file entry")); - printf (_("delete line '%s'? "), pfe->line); + puts(_("invalid password file entry")); + printf(_("delete line '%s'? "), pfe->line); *errors = true; /* * prompt the user to delete the entry or not */ - if (!yes_or_no (read_only)) { + if (!yes_or_no(read_only)) { continue; } @@ -433,7 +433,7 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags } *changed = true; - __pw_del_entry (pfe); + __pw_del_entry(pfe); continue; } @@ -445,7 +445,7 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags /* * Make sure this entry has a unique name. */ - for (tpfe = __pw_get_head (); NULL != tpfe; tpfe = tpfe->next) { + for (tpfe = __pw_get_head(); NULL != tpfe; tpfe = tpfe->next) { const struct passwd *ent = tpfe->eptr; /* @@ -470,14 +470,14 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags * Tell the user this entry is a duplicate of * another and ask them to delete it. */ - puts (_("duplicate password entry")); - printf (_("delete line '%s'? "), pfe->line); + puts(_("duplicate password entry")); + printf(_("delete line '%s'? "), pfe->line); *errors = true; /* * prompt the user to delete the entry or not */ - if (yes_or_no (read_only)) { + if (yes_or_no(read_only)) { goto delete_pw; } } @@ -501,7 +501,7 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags * Check for invalid user ID. */ if (pwd->pw_uid == (uid_t)-1) { - printf (_("invalid user ID '%lu'\n"), (long unsigned int)pwd->pw_uid); + printf(_("invalid user ID '%lu'\n"), (long unsigned int)pwd->pw_uid); *errors = true; } @@ -515,7 +515,7 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags * No primary group, just give a warning */ - printf (_("user '%s': no group %lu\n"), + printf(_("user '%s': no group %lu\n"), pwd->pw_name, (unsigned long) pwd->pw_gid); *errors = true; } @@ -527,14 +527,14 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags /* * Make sure the home directory exists */ - if (!quiet && (access (pwd->pw_dir, F_OK) != 0)) { + if (!quiet && (access(pwd->pw_dir, F_OK) != 0)) { const char *nonexistent = getdef_str("NONEXISTENT"); /* * Home directory does not exist, give a warning (unless intentional) */ if (NULL == nonexistent || !streq(pwd->pw_dir, nonexistent)) { - printf (_("user '%s': directory '%s' does not exist\n"), + printf(_("user '%s': directory '%s' does not exist\n"), pwd->pw_name, pwd->pw_dir); *errors = true; } @@ -546,12 +546,12 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags */ if ( !quiet && !streq(pwd->pw_shell, "") - && (access (pwd->pw_shell, F_OK) != 0)) { + && (access(pwd->pw_shell, F_OK) != 0)) { /* * Login shell doesn't exist, give a warning */ - printf (_("user '%s': program '%s' does not exist\n"), + printf(_("user '%s': program '%s' does not exist\n"), pwd->pw_name, pwd->pw_shell); *errors = true; } @@ -562,40 +562,40 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags if (is_shadow) { #ifdef WITH_TCB - if (getdef_bool ("USE_TCB")) { - if (shadowtcb_set_user (pwd->pw_name) == SHADOWTCB_FAILURE) { - printf (_("no tcb directory for %s\n"), + if (getdef_bool("USE_TCB")) { + if (shadowtcb_set_user(pwd->pw_name) == SHADOWTCB_FAILURE) { + printf(_("no tcb directory for %s\n"), pwd->pw_name); - printf (_("create tcb directory for %s?"), + printf(_("create tcb directory for %s?"), pwd->pw_name); *errors = true; - if (yes_or_no (read_only)) { - if (shadowtcb_create (pwd->pw_name, pwd->pw_uid) == SHADOWTCB_FAILURE) { + if (yes_or_no(read_only)) { + if (shadowtcb_create(pwd->pw_name, pwd->pw_uid) == SHADOWTCB_FAILURE) { *errors = true; - printf (_("failed to create tcb directory for %s\n"), pwd->pw_name); + printf(_("failed to create tcb directory for %s\n"), pwd->pw_name); continue; } } else { continue; } } - if (spw_lock () == 0) { + if (spw_lock() == 0) { *errors = true; - fprintf (stderr, + fprintf(stderr, _("%s: cannot lock %s.\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); continue; } spw_locked = true; - if (spw_open (read_only ? O_RDONLY : O_RDWR) == 0) { - fprintf (stderr, + if (spw_open(read_only ? O_RDONLY : O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); *errors = true; - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); if (use_system_spw_file) { SYSLOG(LOG_ERR, "failed to unlock %s", @@ -607,29 +607,29 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags spw_opened = true; } #endif /* WITH_TCB */ - spw = spw_locate (pwd->pw_name); + spw = spw_locate(pwd->pw_name); if (NULL == spw) { - printf (_("no matching password file entry in %s\n"), - spw_dbname ()); - printf (_("add user '%s' in %s? "), - pwd->pw_name, spw_dbname ()); + printf(_("no matching password file entry in %s\n"), + spw_dbname()); + printf(_("add user '%s' in %s? "), + pwd->pw_name, spw_dbname()); *errors = true; - if (yes_or_no (read_only)) { + if (yes_or_no(read_only)) { struct spwd sp; struct passwd pw; sp.sp_namp = pwd->pw_name; sp.sp_pwdp = pwd->pw_passwd; sp.sp_min = - getdef_num ("PASS_MIN_DAYS", -1); + getdef_num("PASS_MIN_DAYS", -1); sp.sp_max = - getdef_num ("PASS_MAX_DAYS", -1); + getdef_num("PASS_MAX_DAYS", -1); sp.sp_warn = - getdef_num ("PASS_WARN_AGE", -1); + getdef_num("PASS_WARN_AGE", -1); sp.sp_inact = -1; sp.sp_expire = -1; sp.sp_flag = SHADOW_SP_FLAG_UNSET; - sp.sp_lstchg = gettime () / DAY; + sp.sp_lstchg = gettime() / DAY; if (0 == sp.sp_lstchg) { /* Better disable aging than * requiring a password change @@ -638,20 +638,20 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags } *changed = true; - if (spw_update (&sp) == 0) { - fprintf (stderr, + if (spw_update(&sp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, spw_dbname (), sp.sp_namp); - fail_exit (E_CANTUPDATE, process_selinux); + Prog, spw_dbname(), sp.sp_namp); + fail_exit(E_CANTUPDATE, process_selinux); } /* remove password from /etc/passwd */ pw = *pwd; pw.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ - if (pw_update (&pw) == 0) { - fprintf (stderr, + if (pw_update(&pw) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, pw_dbname (), pw.pw_name); - fail_exit (E_CANTUPDATE, process_selinux); + Prog, pw_dbname(), pw.pw_name); + fail_exit(E_CANTUPDATE, process_selinux); } } } else { @@ -660,18 +660,18 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags */ if ( !quiet && !streq(pwd->pw_passwd, SHADOW_PASSWD_STRING)) { - printf (_("user %s has an entry in %s, but its password field in %s is not set to 'x'\n"), - pwd->pw_name, spw_dbname (), pw_dbname ()); + printf(_("user %s has an entry in %s, but its password field in %s is not set to 'x'\n"), + pwd->pw_name, spw_dbname(), pw_dbname()); *errors = true; } } } #ifdef WITH_TCB - if (getdef_bool ("USE_TCB") && spw_locked) { - if (spw_opened && (spw_close (process_selinux) == 0)) { - fprintf (stderr, + if (getdef_bool("USE_TCB") && spw_locked) { + if (spw_opened && (spw_close(process_selinux) == 0)) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); if (use_system_spw_file) { SYSLOG(LOG_ERR, "failure while writing changes to %s", @@ -680,10 +680,10 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags } else { spw_opened = false; } - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); if (use_system_spw_file) { SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); @@ -699,7 +699,7 @@ static void check_pw_file(bool *errors, bool *changed, const struct option_flags /* * check_spw_file - check the content of the shadowed password file (shadow) */ -static void check_spw_file (bool *errors, bool *changed) +static void check_spw_file(bool *errors, bool *changed) { struct commonio_entry *spe, *tspe; struct spwd *spw; @@ -707,7 +707,7 @@ static void check_spw_file (bool *errors, bool *changed) /* * Loop through the entire shadow password file. */ - for (spe = __spw_get_head (); NULL != spe; spe = spe->next) { + for (spe = __spw_get_head(); NULL != spe; spe = spe->next) { /* * Do not treat lines which were missing in shadow * and were added earlier. @@ -734,14 +734,14 @@ static void check_spw_file (bool *errors, bool *changed) * Tell the user this entire line is bogus and ask * them to delete it. */ - puts (_("invalid shadow password file entry")); - printf (_("delete line '%s'? "), spe->line); + puts(_("invalid shadow password file entry")); + printf(_("delete line '%s'? "), spe->line); *errors = true; /* * prompt the user to delete the entry or not */ - if (!yes_or_no (read_only)) { + if (!yes_or_no(read_only)) { continue; } @@ -758,7 +758,7 @@ static void check_spw_file (bool *errors, bool *changed) } *changed = true; - __spw_del_entry (spe); + __spw_del_entry(spe); continue; } @@ -770,7 +770,7 @@ static void check_spw_file (bool *errors, bool *changed) /* * Make sure this entry has a unique name. */ - for (tspe = __spw_get_head (); NULL != tspe; tspe = tspe->next) { + for (tspe = __spw_get_head(); NULL != tspe; tspe = tspe->next) { const struct spwd *ent = tspe->eptr; /* @@ -795,14 +795,14 @@ static void check_spw_file (bool *errors, bool *changed) * Tell the user this entry is a duplicate of * another and ask them to delete it. */ - puts (_("duplicate shadow password entry")); - printf (_("delete line '%s'? "), spe->line); + puts(_("duplicate shadow password entry")); + printf(_("delete line '%s'? "), spe->line); *errors = true; /* * prompt the user to delete the entry or not */ - if (yes_or_no (read_only)) { + if (yes_or_no(read_only)) { goto delete_spw; } } @@ -811,20 +811,20 @@ static void check_spw_file (bool *errors, bool *changed) * Make sure this entry exists in the /etc/passwd * file. */ - if (pw_locate (spw->sp_namp) == NULL) { + if (pw_locate(spw->sp_namp) == NULL) { /* * Tell the user this entry has no matching * /etc/passwd entry and ask them to delete it. */ - printf (_("no matching password file entry in %s\n"), - pw_dbname ()); - printf (_("delete line '%s'? "), spe->line); + printf(_("no matching password file entry in %s\n"), + pw_dbname()); + printf(_("delete line '%s'? "), spe->line); *errors = true; /* * prompt the user to delete the entry or not */ - if (yes_or_no (read_only)) { + if (yes_or_no(read_only)) { goto delete_spw; } } @@ -833,10 +833,10 @@ static void check_spw_file (bool *errors, bool *changed) * Warn if last password change in the future. --marekm */ if (!quiet) { - time_t t = time (NULL); + time_t t = time(NULL); if ( (t != 0) && (spw->sp_lstchg > t / DAY)) { - printf (_("user %s: last password change in the future\n"), + printf(_("user %s: last password change in the future\n"), spw->sp_namp); *errors = true; } @@ -847,7 +847,7 @@ static void check_spw_file (bool *errors, bool *changed) /* * pwck - verify password file integrity */ -int main (int argc, char **argv) +int main(int argc, char **argv) { bool errors = false; bool changed = false; @@ -857,13 +857,13 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); /* Parse the command line arguments */ process_flags (argc, argv, &flags); @@ -906,12 +906,12 @@ int main (int argc, char **argv) * Tell the user what we did and exit. */ if (errors) { - printf (changed ? + printf(changed ? _("%s: the files have been updated\n") : _("%s: no changes\n"), Prog); } - closelog (); + closelog(); return (errors ? E_BADENTRY : E_OKAY); } diff --git a/src/pwconv.c b/src/pwconv.c index 5821d5a77b..8a6eb111d6 100644 --- a/src/pwconv.c +++ b/src/pwconv.c @@ -96,8 +96,8 @@ static void fail_exit (int status, bool process_selinux) } if (spw_locked) { - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); /* continue */ } @@ -125,7 +125,7 @@ static void usage (int status) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { /* * Parse the command line options. @@ -137,26 +137,26 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "hR:", + while ((c = getopt_long(argc, argv, "hR:", long_options, NULL)) != -1) { switch (c) { case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ flags->chroot = true; break; default: - usage (E_USAGE); + usage(E_USAGE); } } if (optind != argc) { - usage (E_USAGE); + usage(E_USAGE); } } -int main (int argc, char **argv) +int main(int argc, char **argv) { const struct passwd *pw; struct passwd pwent; @@ -168,67 +168,67 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); process_selinux = !flags.chroot; #ifdef WITH_TCB if (getdef_bool("USE_TCB")) { - fprintf (stderr, _("%s: can't work with tcb enabled\n"), Prog); - exit (E_FAILURE); + fprintf(stderr, _("%s: can't work with tcb enabled\n"), Prog); + exit(E_FAILURE); } #endif /* WITH_TCB */ - if (pw_lock () == 0) { - fprintf (stderr, + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - fail_exit (E_PWDBUSY, process_selinux); + Prog, pw_dbname()); + fail_exit(E_PWDBUSY, process_selinux); } pw_locked = true; - if (pw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, - _("%s: cannot open %s\n"), Prog, pw_dbname ()); - fail_exit (E_MISSING, process_selinux); + if (pw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, + _("%s: cannot open %s\n"), Prog, pw_dbname()); + fail_exit(E_MISSING, process_selinux); } - if (spw_lock () == 0) { - fprintf (stderr, + if (spw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, spw_dbname ()); - fail_exit (E_PWDBUSY, process_selinux); + Prog, spw_dbname()); + fail_exit(E_PWDBUSY, process_selinux); } spw_locked = true; - if (spw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, - _("%s: cannot open %s\n"), Prog, spw_dbname ()); - fail_exit (E_FAILURE, process_selinux); + if (spw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, + _("%s: cannot open %s\n"), Prog, spw_dbname()); + fail_exit(E_FAILURE, process_selinux); } /* * Remove /etc/shadow entries for users not in /etc/passwd. */ - (void) spw_rewind (); + (void) spw_rewind(); while (NULL != (sp = spw_next())) { - if (pw_locate (sp->sp_namp) != NULL) { + if (pw_locate(sp->sp_namp) != NULL) { continue; } - if (spw_remove (sp->sp_namp) == 0) { + if (spw_remove(sp->sp_namp) == 0) { /* * This shouldn't happen (the entry exists) but... */ - fprintf (stderr, + fprintf(stderr, _("%s: cannot remove entry '%s' from %s\n"), - Prog, sp->sp_namp, spw_dbname ()); - fail_exit (E_FAILURE, process_selinux); + Prog, sp->sp_namp, spw_dbname()); + fail_exit(E_FAILURE, process_selinux); } (void) spw_rewind(); } @@ -237,9 +237,9 @@ int main (int argc, char **argv) * Update shadow entries which don't have "x" as pw_passwd. Add any * missing shadow entries. */ - (void) pw_rewind (); + (void) pw_rewind(); while (NULL != (pw = pw_next())) { - sp = spw_locate (pw->pw_name); + sp = spw_locate(pw->pw_name); if (NULL != sp) { /* do we need to update this entry? */ if (streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) { @@ -265,37 +265,37 @@ int main (int argc, char **argv) * change */ spent.sp_lstchg = -1; } - if (spw_update (&spent) == 0) { - fprintf (stderr, + if (spw_update(&spent) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, spw_dbname (), spent.sp_namp); - fail_exit (E_FAILURE, process_selinux); + Prog, spw_dbname(), spent.sp_namp); + fail_exit(E_FAILURE, process_selinux); } /* remove password from /etc/passwd */ pwent = *pw; pwent.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ - if (pw_update (&pwent) == 0) { - fprintf (stderr, + if (pw_update(&pwent) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, pw_dbname (), pwent.pw_name); - fail_exit (E_FAILURE, process_selinux); + Prog, pw_dbname(), pwent.pw_name); + fail_exit(E_FAILURE, process_selinux); } } - if (spw_close (process_selinux) == 0) { - fprintf (stderr, + if (spw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", spw_dbname()); - fail_exit (E_FAILURE, process_selinux); + fail_exit(E_FAILURE, process_selinux); } - if (pw_close (process_selinux) == 0) { - fprintf (stderr, + if (pw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, pw_dbname ()); + Prog, pw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", pw_dbname()); - fail_exit (E_FAILURE, process_selinux); + fail_exit(E_FAILURE, process_selinux); } /* /etc/passwd- (backup file) */ @@ -308,8 +308,8 @@ int main (int argc, char **argv) /* continue */ } - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -320,8 +320,8 @@ int main (int argc, char **argv) /* continue */ } - nscd_flush_cache ("passwd"); - sssd_flush_cache (SSSD_DB_PASSWD); + nscd_flush_cache("passwd"); + sssd_flush_cache(SSSD_DB_PASSWD); return E_SUCCESS; } diff --git a/src/pwunconv.c b/src/pwunconv.c index a784174323..62f7e96db8 100644 --- a/src/pwunconv.c +++ b/src/pwunconv.c @@ -57,8 +57,8 @@ static void fail_exit (int status, bool process_selinux) } } if (pw_locked) { - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -85,7 +85,7 @@ static void usage (int status) * * It will not return if an error is encountered. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { /* * Parse the command line options. @@ -97,26 +97,26 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "hR:", + while ((c = getopt_long(argc, argv, "hR:", long_options, NULL)) != -1) { switch (c) { case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ flags->chroot = true; break; default: - usage (E_USAGE); + usage(E_USAGE); } } if (optind != argc) { - usage (E_USAGE); + usage(E_USAGE); } } -int main (int argc, char **argv) +int main(int argc, char **argv) { const struct passwd *pw; struct passwd pwent; @@ -127,25 +127,25 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); process_selinux = !flags.chroot; #ifdef WITH_TCB if (getdef_bool("USE_TCB")) { - fprintf (stderr, _("%s: can't work with tcb enabled\n"), Prog); - exit (1); + fprintf(stderr, _("%s: can't work with tcb enabled\n"), Prog); + exit(1); } #endif /* WITH_TCB */ - if (!spw_file_present ()) { + if (!spw_file_present()) { /* shadow not installed, do nothing */ exit (0); } @@ -194,11 +194,11 @@ int main (int argc, char **argv) pwent.pw_passwd = spwd->sp_pwdp; } - if (pw_update (&pwent) == 0) { - fprintf (stderr, + if (pw_update(&pwent) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, pw_dbname (), pwent.pw_name); - fail_exit (3, process_selinux); + Prog, pw_dbname(), pwent.pw_name); + fail_exit(3, process_selinux); } } @@ -224,8 +224,8 @@ int main (int argc, char **argv) SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); /* continue */ } - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } diff --git a/src/su.c b/src/su.c index 8f49ee6eca..8041b3b8aa 100644 --- a/src/su.c +++ b/src/su.c @@ -139,22 +139,22 @@ static void set_environment (struct passwd *pw); * with die() as the signal handler. If signal later calls die() with a * signal number, the terminal modes are then reset. */ -static void die (int killed) +static void die(int killed) { static TERMIO sgtty; if (killed != 0) { - STTY (0, &sgtty); + STTY(0, &sgtty); } else { - GTTY (0, &sgtty); + GTTY(0, &sgtty); } if (killed != 0) { - _exit (128+killed); + _exit(128+killed); } } -static bool iswheel (const char *username) +static bool iswheel(const char *username) { struct group *grp; @@ -183,7 +183,7 @@ set_timeout(int) #endif /* USE_PAM */ /* borrowed from GNU sh-utils' "su.c" */ -static bool restricted_shell (const char *shellname) +static bool restricted_shell(const char *shellname) { /*@observer@*/const char *line; @@ -203,17 +203,17 @@ static void su_failure (const char *tty, bool su_to_root) { sulog (tty, false, caller_name, name); /* log failed attempt */ - if (getdef_bool ("SYSLOG_SU_ENAB")) { + if (getdef_bool("SYSLOG_SU_ENAB")) { SYSLOG(su_to_root ? LOG_NOTICE : LOG_INFO, "- %s %s:%s", tty, ('\0' != caller_name[0]) ? caller_name : "???", ('\0' != name[0]) ? name : "???"); } - closelog (); + closelog(); #ifdef WITH_AUDIT - audit_fd = audit_open (); - audit_log_acct_message (audit_fd, + audit_fd = audit_open(); + audit_log_acct_message(audit_fd, AUDIT_USER_ROLE_CHANGE, NULL, /* Prog. name */ "su", @@ -233,15 +233,15 @@ su_failure (const char *tty, bool su_to_root) * execve_shell - Execute a shell with execve, or interpret it with * /bin/sh */ -static void execve_shell (const char *shellname, +static void execve_shell(const char *shellname, char *args[], char *const envp[]) { int err; - (void) execve (shellname, args, envp); + (void) execve(shellname, args, envp); err = errno; - if (access (shellname, R_OK|X_OK) == 0) { + if (access(shellname, R_OK|X_OK) == 0) { /* * Assume this is a shell script (with no shebang). * Interpret it with /bin/sh @@ -254,14 +254,14 @@ static void execve_shell (const char *shellname, targs = xmalloc_T(n_args + 3, char *); targs[0] = "sh"; targs[1] = "-"; - targs[2] = xstrdup (shellname); + targs[2] = xstrdup(shellname); targs[n_args+2] = NULL; while (1 != n_args) { targs[n_args+1] = args[n_args - 1]; n_args--; } - (void) execve (SHELL, targs, envp); + (void) execve(SHELL, targs, envp); } else { errno = err; } @@ -280,7 +280,7 @@ static void catch_signals (int sig) * Only the child returns. The parent will wait for the child to * terminate and exit. */ -static void prepare_pam_close_session (void) +static void prepare_pam_close_session(void) { sigset_t ourset; int status; @@ -302,48 +302,48 @@ static void prepare_pam_close_session (void) /* Only the child returns. See above. */ } - pid_child = fork (); + pid_child = fork(); if (pid_child == 0) { /* child shell */ return; /* Only the child will return from pam_create_session */ } else if ((pid_t)-1 == pid_child) { - (void) fprintf (stderr, + (void) fprintf(stderr, _("%s: Cannot fork user shell\n"), Prog); SYSLOG(LOG_WARN, "Cannot execute %s", shellstr); - closelog (); - exit (1); + closelog(); + exit(1); /* Only the child returns. See above. */ } /* parent only */ - sigfillset (&ourset); - if (sigprocmask (SIG_BLOCK, &ourset, NULL) != 0) { - (void) fprintf (stderr, + sigfillset(&ourset); + if (sigprocmask(SIG_BLOCK, &ourset, NULL) != 0) { + (void) fprintf(stderr, _("%s: signal malfunction\n"), Prog); caught = SIGTERM; } if (0 == caught) { action.sa_handler = catch_signals; - sigemptyset (&ourset); + sigemptyset(&ourset); - if ( (sigaddset (&ourset, SIGTERM) != 0) - || (sigaddset (&ourset, SIGALRM) != 0) - || (sigaction (SIGTERM, &action, NULL) != 0) + if ( (sigaddset(&ourset, SIGTERM) != 0) + || (sigaddset(&ourset, SIGALRM) != 0) + || (sigaction(SIGTERM, &action, NULL) != 0) || ( !doshell /* handle SIGINT (Ctrl-C), SIGQUIT * (Ctrl-\), and SIGTSTP (Ctrl-Z) * since the child will not control * the tty. */ - && ( (sigaddset (&ourset, SIGINT) != 0) - || (sigaddset (&ourset, SIGQUIT) != 0) - || (sigaddset (&ourset, SIGTSTP) != 0) - || (sigaction (SIGINT, &action, NULL) != 0) - || (sigaction (SIGQUIT, &action, NULL) != 0) - || (sigaction (SIGTSTP, &action, NULL) != 0))) - || (sigprocmask (SIG_UNBLOCK, &ourset, NULL) != 0) + && ( (sigaddset(&ourset, SIGINT) != 0) + || (sigaddset(&ourset, SIGQUIT) != 0) + || (sigaddset(&ourset, SIGTSTP) != 0) + || (sigaction(SIGINT, &action, NULL) != 0) + || (sigaction(SIGQUIT, &action, NULL) != 0) + || (sigaction(SIGTSTP, &action, NULL) != 0))) + || (sigprocmask(SIG_UNBLOCK, &ourset, NULL) != 0) ) { - fprintf (stderr, + fprintf(stderr, _("%s: signal masking malfunction\n"), Prog); caught = SIGTERM; @@ -358,7 +358,7 @@ static void prepare_pam_close_session (void) stop = true; do { - pid = waitpid (-1, &status, WUNTRACED); + pid = waitpid(-1, &status, WUNTRACED); } while (pid != -1 && pid != pid_child); /* When interrupted by signal, the signal will be @@ -374,13 +374,13 @@ static void prepare_pam_close_session (void) * We will SIGSTOP ourself on the next * waitpid round. */ - kill (pid_child, SIGSTOP); + kill(pid_child, SIGSTOP); stop = false; } else if ( ((pid_t)-1 != pid) - && (0 != WIFSTOPPED (status))) { + && (0 != WIFSTOPPED(status))) { /* The child (shell) was suspended. * Suspend su. */ - kill (getpid (), SIGSTOP); + kill(getpid(), SIGSTOP); /* wake child when resumed */ kill (pid, SIGCONT); stop = false; @@ -398,24 +398,24 @@ static void prepare_pam_close_session (void) /* Any signals other than SIGCHLD and SIGALRM will no longer have any effect, * so it's time to block all of them. */ - sigfillset (&ourset); - if (sigprocmask (SIG_BLOCK, &ourset, NULL) != 0) { - fprintf (stderr, _("%s: signal masking malfunction\n"), Prog); + sigfillset(&ourset); + if (sigprocmask(SIG_BLOCK, &ourset, NULL) != 0) { + fprintf(stderr, _("%s: signal masking malfunction\n"), Prog); kill_child(pid_child); /* Never reached (exit called). */ } /* Send SIGKILL to the child if it doesn't * exit within 2 seconds (after SIGTERM) */ - (void) signal (SIGALRM, set_timeout); - (void) signal (SIGCHLD, catch_signals); - (void) alarm (2); + (void) signal(SIGALRM, set_timeout); + (void) signal(SIGCHLD, catch_signals); + (void) alarm(2); - (void) sigdelset (&ourset, SIGALRM); - (void) sigdelset (&ourset, SIGCHLD); + (void) sigdelset(&ourset, SIGALRM); + (void) sigdelset(&ourset, SIGCHLD); - while (0 == waitpid (pid_child, &status, WNOHANG)) { - sigsuspend (&ourset); + while (0 == waitpid(pid_child, &status, WNOHANG)) { + sigsuspend(&ourset); if (timeout) { kill_child(pid_child); /* Never reached (exit called). */ @@ -445,10 +445,10 @@ static void prepare_pam_close_session (void) * usage - print command line syntax and exit */ NORETURN -static void usage (int status) +static void usage(int status) { (void) - fputs (_("Usage: su [options] [-] [username [args]]\n" + fputs(_("Usage: su [options] [-] [username [args]]\n" "\n" "Options:\n" " -c, --command COMMAND pass COMMAND to the invoked shell\n" @@ -460,51 +460,51 @@ static void usage (int status) " -s, --shell SHELL use SHELL instead of the default in passwd\n" "\n" "If no username is given, assume root.\n"), (E_SUCCESS != status) ? stderr : stdout); - exit (status); + exit(status); } #ifdef USE_PAM -static void check_perms_pam (const struct passwd *pw) +static void check_perms_pam(const struct passwd *pw) { int ret; - ret = pam_authenticate (pamh, 0); + ret = pam_authenticate(pamh, 0); if (PAM_SUCCESS != ret) { SYSLOG(pw->pw_uid ? LOG_NOTICE : LOG_WARN, "pam_authenticate: %s", pam_strerror(pamh, ret)); - fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret)); - (void) pam_end (pamh, ret); - su_failure (caller_tty, 0 == pw->pw_uid); + fprintf(stderr, _("%s: %s\n"), Prog, pam_strerror(pamh, ret)); + (void) pam_end(pamh, ret); + su_failure(caller_tty, 0 == pw->pw_uid); } - ret = pam_acct_mgmt (pamh, 0); + ret = pam_acct_mgmt(pamh, 0); if (PAM_SUCCESS != ret) { if (caller_is_root) { - fprintf (stderr, + fprintf(stderr, _("%s: %s\n(Ignored)\n"), - Prog, pam_strerror (pamh, ret)); + Prog, pam_strerror(pamh, ret)); } else if (PAM_NEW_AUTHTOK_REQD == ret) { - ret = pam_chauthtok (pamh, PAM_CHANGE_EXPIRED_AUTHTOK); + ret = pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK); if (PAM_SUCCESS != ret) { SYSLOG(LOG_ERR, "pam_chauthtok: %s", pam_strerror(pamh, ret)); - fprintf (stderr, + fprintf(stderr, _("%s: %s\n"), - Prog, pam_strerror (pamh, ret)); - (void) pam_end (pamh, ret); - su_failure (caller_tty, 0 == pw->pw_uid); + Prog, pam_strerror(pamh, ret)); + (void) pam_end(pamh, ret); + su_failure(caller_tty, 0 == pw->pw_uid); } } else { SYSLOG(LOG_ERR, "pam_acct_mgmt: %s", pam_strerror(pamh, ret)); - fprintf (stderr, + fprintf(stderr, _("%s: %s\n"), - Prog, pam_strerror (pamh, ret)); - (void) pam_end (pamh, ret); - su_failure (caller_tty, 0 == pw->pw_uid); + Prog, pam_strerror(pamh, ret)); + (void) pam_end(pamh, ret); + su_failure(caller_tty, 0 == pw->pw_uid); } } } #else /* !USE_PAM */ -static void check_perms_nopam (const struct passwd *pw) +static void check_perms_nopam(const struct passwd *pw) { /*@observer@*/const struct spwd *spwd = NULL; /*@observer@*/const char *password = pw->pw_passwd; @@ -549,12 +549,12 @@ static void check_perms_nopam (const struct passwd *pw) */ if ( (0 == pw->pw_uid) - && getdef_bool ("SU_WHEEL_ONLY") - && !iswheel (caller_name)) { - fprintf (stderr, + && getdef_bool("SU_WHEEL_ONLY") + && !iswheel(caller_name)) { + fprintf(stderr, _("You are not authorized to su %s\n"), name); - exit (1); + exit(1); } spwd = getspnam (name); /* !USE_PAM, no need for xgetspnam */ #ifdef SU_ACCESS @@ -575,17 +575,17 @@ static void check_perms_nopam (const struct passwd *pw) password = caller_pass; break; default: /* access denied (-1) or unexpected value */ - fprintf (stderr, + fprintf(stderr, _("You are not authorized to su %s\n"), name); - exit (1); + exit(1); } #endif /* SU_ACCESS */ /* * Set up a signal handler in case the user types QUIT. */ - die (0); - oldsig = signal (SIGQUIT, die); + die(0); + oldsig = signal(SIGQUIT, die); /* * See if the system defined authentication method is being used. @@ -596,9 +596,9 @@ static void check_perms_nopam (const struct passwd *pw) SYSLOG(pw->pw_uid ? LOG_NOTICE : LOG_WARN, "Authentication failed for %s", name); fprintf(stderr, _("%s: Authentication failure\n"), Prog); - su_failure (caller_tty, 0 == pw->pw_uid); + su_failure(caller_tty, 0 == pw->pw_uid); } - (void) signal (SIGQUIT, oldsig); + (void) signal(SIGQUIT, oldsig); /* * Check to see if the account is expired. root gets to ignore any @@ -606,7 +606,7 @@ static void check_perms_nopam (const struct passwd *pw) * expired password. */ if (NULL != spwd) { - (void) expire (pw, spwd); + (void) expire(pw, spwd); } /* @@ -615,13 +615,13 @@ static void check_perms_nopam (const struct passwd *pw) * there is a "SU" entry in the /etc/porttime file denying access to * the account. */ - if (!isttytime (name, "SU", time (NULL))) { + if (!isttytime(name, "SU", time(NULL))) { SYSLOG(pw->pw_uid ? LOG_WARN : LOG_CRIT, "SU by %s to restricted account %s", caller_name, name); - fprintf (stderr, + fprintf(stderr, _("%s: You are not authorized to su at that time\n"), Prog); - su_failure (caller_tty, 0 == pw->pw_uid); + su_failure(caller_tty, 0 == pw->pw_uid); } } #endif /* !USE_PAM */ @@ -658,19 +658,19 @@ static /*@only@*/struct passwd * do_check_perms (void) * The password file entries for the user is gotten and the account * validated. */ - struct passwd *pw = xgetpwnam (name); + struct passwd *pw = xgetpwnam(name); if (NULL == pw) { - (void) fprintf (stderr, + (void) fprintf(stderr, _("No passwd entry for user '%s'\n"), name); SYSLOG(LOG_NOTICE, "No passwd entry for user '%s'", name); - su_failure (caller_tty, true); + su_failure(caller_tty, true); } - (void) signal (SIGINT, SIG_IGN); - (void) signal (SIGQUIT, SIG_IGN); + (void) signal(SIGINT, SIG_IGN); + (void) signal(SIGQUIT, SIG_IGN); #ifdef USE_PAM - check_perms_pam (pw); + check_perms_pam(pw); /* PAM authentication can request a change of account */ ret = pam_get_item(pamh, PAM_USER, &item); if (ret != PAM_SUCCESS) { @@ -745,27 +745,27 @@ save_caller_context(void) log_set_progname(Prog); log_set_logfd(stderr); - caller_uid = getuid (); + caller_uid = getuid(); caller_is_root = (caller_uid == 0); /* * Get the tty name. Entries will be logged indicating that the user * tried to change to the named new user from the current terminal. */ - caller_tty = ttyname (0); - if ((isatty (0) != 0) && (NULL != caller_tty)) { + caller_tty = ttyname(0); + if ((isatty(0) != 0) && (NULL != caller_tty)) { #ifndef USE_PAM - caller_on_console = console (caller_tty); + caller_on_console = console(caller_tty); #endif /* !USE_PAM */ } else { /* * Be more paranoid, like su from SimplePAMApps. --marekm */ if (!caller_is_root) { - fprintf (stderr, + fprintf(stderr, _("%s: must be run from a terminal\n"), Prog); - exit (1); + exit(1); } caller_tty = "???"; } @@ -774,12 +774,12 @@ save_caller_context(void) * Get the user's real name. The current UID is used to determine * who has executed su. That user ID must exist. */ - pw = get_my_pwent (); + pw = get_my_pwent(); if (NULL == pw) { - fprintf (stderr, + fprintf(stderr, _("%s: Cannot determine your user name.\n"), Prog); - SYSLOG(LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", + SYSLOG(LOG_WARN, "Cannot determine the user name of the caller(UID %lu)", (unsigned long) caller_uid); su_failure (caller_tty, true); /* unknown target UID*/ } @@ -793,16 +793,16 @@ save_caller_context(void) */ password = pw->pw_passwd; if (streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) { - const struct spwd *spwd = getspnam (caller_name); + const struct spwd *spwd = getspnam(caller_name); if (NULL != spwd) { password = spwd->sp_pwdp; } } - free (caller_pass); - caller_pass = xstrdup (password); + free(caller_pass); + caller_pass = xstrdup(password); #endif /* SU_ACCESS */ #endif /* !USE_PAM */ - pw_free (pw); + pw_free(pw); } @@ -813,7 +813,7 @@ save_caller_context(void) * the values that the user will be created with accordingly. The * values are checked for sanity. */ -static void process_flags (int argc, char **argv) +static void process_flags(int argc, char **argv) { int c; static struct option long_options[] = { @@ -825,14 +825,14 @@ static void process_flags (int argc, char **argv) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "c:hlmps:", + while ((c = getopt_long(argc, argv, "c:hlmps:", long_options, NULL)) != -1) { switch (c) { case 'c': command = optarg; break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); break; case 'l': fakelogin = true; @@ -881,7 +881,7 @@ static void process_flags (int argc, char **argv) } } -static void set_environment (struct passwd *pw) +static void set_environment(struct passwd *pw) { const char *cp; /* @@ -893,9 +893,9 @@ static void set_environment (struct passwd *pw) * The terminal type will be left alone if it is present in * the environment already. */ - cp = getenv ("TERM"); + cp = getenv("TERM"); if (NULL != cp) { - addenv ("TERM", cp); + addenv("TERM", cp); } /* @@ -906,13 +906,13 @@ static void set_environment (struct passwd *pw) * is also of use when running GNU screen since it sets * TERM to "screen" but doesn't touch COLORTERM. */ - cp = getenv ("COLORTERM"); + cp = getenv("COLORTERM"); if (NULL != cp) { - addenv ("COLORTERM", cp); + addenv("COLORTERM", cp); } #ifndef USE_PAM - cp = getdef_str ("ENV_TZ"); + cp = getdef_str("ENV_TZ"); if (NULL != cp) { addenv(strprefix(cp, "/") ? tz(cp) : cp, NULL); } @@ -920,7 +920,7 @@ static void set_environment (struct passwd *pw) /* * The clock frequency will be reset to the login value if required */ - cp = getdef_str ("ENV_HZ"); + cp = getdef_str("ENV_HZ"); if (NULL != cp) { addenv (cp, NULL); /* set the default $HZ, if one */ } @@ -930,29 +930,29 @@ static void set_environment (struct passwd *pw) * Also leave DISPLAY and XAUTHORITY if present, else * pam_xauth will not work. */ - cp = getenv ("DISPLAY"); + cp = getenv("DISPLAY"); if (NULL != cp) { - addenv ("DISPLAY", cp); + addenv("DISPLAY", cp); } - cp = getenv ("XAUTHORITY"); + cp = getenv("XAUTHORITY"); if (NULL != cp) { - addenv ("XAUTHORITY", cp); + addenv("XAUTHORITY", cp); } } else { char **envp = environ; while (NULL != *envp) { - addenv (*envp, NULL); + addenv(*envp, NULL); envp++; } } - cp = getdef_str ((pw->pw_uid == 0) ? "ENV_SUPATH" : "ENV_PATH"); + cp = getdef_str((pw->pw_uid == 0) ? "ENV_SUPATH" : "ENV_PATH"); if (NULL == cp) { - addenv ((pw->pw_uid == 0) ? "PATH=/sbin:/bin:/usr/sbin:/usr/bin" : "PATH=/bin:/usr/bin", NULL); + addenv((pw->pw_uid == 0) ? "PATH=/sbin:/bin:/usr/sbin:/usr/bin" : "PATH=/bin:/usr/bin", NULL); } else if (strchr(cp, '=')) { - addenv (cp, NULL); + addenv(cp, NULL); } else { - addenv ("PATH", cp); + addenv("PATH", cp); } if (getenv ("IFS") != NULL) { /* don't export user IFS ... */ @@ -1003,7 +1003,7 @@ static void set_environment (struct passwd *pw) * particular, the argument "-c" will cause the next argument to be * interpreted as a command by the common shell programs. */ -int main (int argc, char **argv) +int main(int argc, char **argv) { const char *cp; struct passwd *pw = NULL; @@ -1012,48 +1012,48 @@ int main (int argc, char **argv) int ret; #endif /* USE_PAM */ - check_fds (); + check_fds(); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); save_caller_context(); - OPENLOG (Prog); + OPENLOG(Prog); - process_flags (argc, argv); + process_flags(argc, argv); - initenv (); + initenv(); #ifdef USE_PAM - ret = pam_start (Prog, name, &conv, &pamh); + ret = pam_start(Prog, name, &conv, &pamh); if (PAM_SUCCESS != ret) { SYSLOG(LOG_ERR, "pam_start: error %d", ret); fprintf(stderr, _("%s: pam_start: error %d\n"), Prog, ret); - exit (1); + exit(1); } - ret = pam_set_item (pamh, PAM_TTY, caller_tty); + ret = pam_set_item(pamh, PAM_TTY, caller_tty); if (PAM_SUCCESS == ret) { - ret = pam_set_item (pamh, PAM_RUSER, caller_name); + ret = pam_set_item(pamh, PAM_RUSER, caller_name); } if (PAM_SUCCESS != ret) { SYSLOG(LOG_ERR, "pam_set_item: %s", pam_strerror(pamh, ret)); - fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret)); - pam_end (pamh, ret); - exit (1); + fprintf(stderr, _("%s: %s\n"), Prog, pam_strerror(pamh, ret)); + pam_end(pamh, ret); + exit(1); } #endif /* USE_PAM */ - pw = check_perms (); + pw = check_perms(); /* If the user does not want to change the environment, * use the current SHELL. * (unless another shell is required by the command line) */ if ((NULL == shellstr) && !change_environment) { - shellstr = getenv ("SHELL"); + shellstr = getenv("SHELL"); } /* If su is not called by root, and the target user has a @@ -1061,7 +1061,7 @@ int main (int argc, char **argv) * must be the one specified in /etc/passwd. */ if ( !caller_is_root - && restricted_shell (pw->pw_shell)) { + && restricted_shell(pw->pw_shell)) { shellstr = NULL; change_environment = true; } @@ -1089,33 +1089,33 @@ int main (int argc, char **argv) #ifdef USE_PAM /* set primary group id and supplementary groups */ - if (setup_groups (pw) != 0) { - pam_end (pamh, PAM_ABORT); - exit (1); + if (setup_groups(pw) != 0) { + pam_end(pamh, PAM_ABORT); + exit(1); } /* * pam_setcred() may do things like resource limits, console groups, * and much more, depending on the configured modules */ - ret = pam_setcred (pamh, PAM_ESTABLISH_CRED); + ret = pam_setcred(pamh, PAM_ESTABLISH_CRED); if (PAM_SUCCESS != ret) { SYSLOG(LOG_ERR, "pam_setcred: %s", pam_strerror(pamh, ret)); - fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret)); - (void) pam_end (pamh, ret); - exit (1); + fprintf(stderr, _("%s: %s\n"), Prog, pam_strerror(pamh, ret)); + (void) pam_end(pamh, ret); + exit(1); } - ret = pam_open_session (pamh, 0); + ret = pam_open_session(pamh, 0); if (PAM_SUCCESS != ret) { SYSLOG(LOG_ERR, "pam_open_session: %s", pam_strerror(pamh, ret)); - fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret)); - pam_setcred (pamh, PAM_DELETE_CRED); - (void) pam_end (pamh, ret); - exit (1); + fprintf(stderr, _("%s: %s\n"), Prog, pam_strerror(pamh, ret)); + pam_setcred(pamh, PAM_DELETE_CRED); + (void) pam_end(pamh, ret); + exit(1); } - prepare_pam_close_session (); + prepare_pam_close_session(); /* become the new user */ if (change_uid (pw) != 0) { @@ -1124,17 +1124,17 @@ int main (int argc, char **argv) #else /* !USE_PAM */ /* no limits if su from root (unless su must fake login's behavior) */ if (!caller_is_root || fakelogin) { - setup_limits (pw); + setup_limits(pw); } - if (setup_uid_gid (pw, caller_on_console) != 0) { - exit (1); + if (setup_uid_gid(pw, caller_on_console) != 0) { + exit(1); } #endif /* !USE_PAM */ #ifdef WITH_AUDIT - audit_fd = audit_open (); - audit_log_acct_message (audit_fd, + audit_fd = audit_open(); + audit_log_acct_message(audit_fd, AUDIT_USER_ROLE_CHANGE, NULL, /* Prog. name */ "su", @@ -1160,11 +1160,11 @@ int main (int argc, char **argv) err = setsid (); #else /* Otherwise, we cannot use setsid */ - int fd = open ("/dev/tty", O_RDWR); + int fd = open("/dev/tty", O_RDWR); if (fd >= 0) { - err = ioctl (fd, TIOCNOTTY, (char *) NULL); - (void) close (fd); + err = ioctl(fd, TIOCNOTTY, (char *) NULL); + (void) close(fd); } else if (ENXIO == errno) { /* There are no controlling terminal already */ err = 0; @@ -1192,21 +1192,21 @@ int main (int argc, char **argv) * F_SETFD, 1)" in libc/misc/syslog.c, but it is commented out (at * least in 5.4.33). Why? --marekm */ - closelog (); + closelog(); /* * See if the user has extra arguments on the command line. In that * case they will be provided to the new user's shell as arguments. */ if (fakelogin) { - cp = getdef_str ("SU_NAME"); + cp = getdef_str("SU_NAME"); if (NULL == cp) { - cp = Basename (shellstr); + cp = Basename(shellstr); } cp = xaprintf("-%s", cp); } else { - cp = Basename (shellstr); + cp = Basename(shellstr); } if (!doshell) { @@ -1223,16 +1223,16 @@ int main (int argc, char **argv) * with the rest of the command line included. */ argv[-1] = const_cast(char *, cp); - execve_shell (shellstr, &argv[-1], environ); + execve_shell(shellstr, &argv[-1], environ); err = errno; - (void) fprintf (stderr, + (void) fprintf(stderr, _("Cannot execute %s\n"), shellstr); errno = err; } else { - (void) shell (shellstr, cp, environ); + (void) shell(shellstr, cp, environ); } - pw_free (pw); + pw_free(pw); return (errno == ENOENT ? E_CMD_NOTFOUND : E_CMD_NOEXEC); } diff --git a/src/suauth.c b/src/suauth.c index 5d55484ce9..78709aba91 100644 --- a/src/suauth.c +++ b/src/suauth.c @@ -41,9 +41,9 @@ /* Really, I could do with a few const char's here defining all the * strings output to the user or the syslog. -- chris */ -static int applies (const char *, char *); +static int applies(const char *, char *); -static int isgrp (const char *, const char *); +static int isgrp(const char *, const char *); static intmax_t lines = 0; @@ -57,7 +57,7 @@ check_su_auth(const char *actual_id, const char *wanted_id, bool su_to_root) char *from_users; char *action; - if (!(authfile_fd = fopen (SUAUTHFILE, "r"))) { + if (!(authfile_fd = fopen(SUAUTHFILE, "r"))) { int err = errno; /* * If the file doesn't exist - default to the standard su @@ -100,39 +100,39 @@ check_su_auth(const char *actual_id, const char *wanted_id, bool su_to_root) continue; } - if (!applies (wanted_id, to_users)) + if (!applies(wanted_id, to_users)) continue; - if (!applies (actual_id, from_users)) + if (!applies(actual_id, from_users)) continue; if (streq(action, "DENY")) { SYSLOG(su_to_root ? LOG_WARN : LOG_NOTICE, "DENIED su from '%s' to '%s' (%s)\n", actual_id, wanted_id, SUAUTHFILE); - fputs (_("Access to su to that account DENIED.\n"), + fputs(_("Access to su to that account DENIED.\n"), stderr); - fclose (authfile_fd); + fclose(authfile_fd); return DENY; } else if (streq(action, "NOPASS")) { SYSLOG(su_to_root ? LOG_NOTICE : LOG_INFO, "NO password asked for su from '%s' to '%s' (%s)\n", actual_id, wanted_id, SUAUTHFILE); - fputs (_("Password authentication bypassed.\n"),stderr); - fclose (authfile_fd); + fputs(_("Password authentication bypassed.\n"),stderr); + fclose(authfile_fd); return NOPWORD; } else if (streq(action, "OWNPASS")) { SYSLOG(su_to_root ? LOG_NOTICE : LOG_INFO, - "su from '%s' to '%s': asking for user's own password (%s)\n", + "su from '%s' to '%s': asking for user's own password(%s)\n", actual_id, wanted_id, SUAUTHFILE); - fputs (_("Please enter your OWN password as authentication.\n"), + fputs(_("Please enter your OWN password as authentication.\n"), stderr); - fclose (authfile_fd); + fclose(authfile_fd); return OWNPWORD; } else { SYSLOG(LOG_ERR, "%s, line %jd: unrecognized action!\n", SUAUTHFILE, lines); } } - fclose (authfile_fd); + fclose(authfile_fd); return NOACTION; } @@ -182,7 +182,7 @@ applies(const char *single, char *list) return 0; break; case 3: /* Group */ - if (isgrp (single, tok)) + if (isgrp(single, tok)) return 1; break; case 4: /* All except group */ @@ -197,7 +197,7 @@ applies(const char *single, char *list) return 0; } -static int isgrp (const char *name, const char *group) +static int isgrp(const char *name, const char *group) { struct group *grp; diff --git a/src/sulogin.c b/src/sulogin.c index 3daee58b25..00a4ff1f57 100644 --- a/src/sulogin.c +++ b/src/sulogin.c @@ -45,14 +45,14 @@ extern char **newenvp; #endif -static void catch_signals (int); +static void catch_signals(int); static int pw_entry(const char *name, struct passwd *pwent); static void catch_signals(MAYBE_UNUSED int _1) { - _exit (1); + _exit(1); } @@ -69,17 +69,17 @@ main(int argc, char *argv[]) #endif - tcgetattr (0, &termio); + tcgetattr(0, &termio); termio.c_iflag |= (ICRNL | IXON); termio.c_oflag |= (CREAD); termio.c_lflag |= (ECHO | ECHOE | ECHOK | ICANON | ISIG); - tcsetattr (0, TCSANOW, &termio); + tcsetattr(0, TCSANOW, &termio); log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); initenv(); if (argc > 1) { @@ -98,17 +98,17 @@ main(int argc, char *argv[]) } #if !defined(DEBUG) && defined(SULOGIN_ONLY_INIT) if (getppid () != 1) { /* parent must be INIT */ - exit (1); + exit(1); } #endif - if ((isatty (0) == 0) || (isatty (1) == 0) || (isatty (2) == 0)) { + if ((isatty(0) == 0) || (isatty(1) == 0) || (isatty(2) == 0)) { exit (1); /* must be a terminal */ } /* If we were init, we need to start a new session */ if (getppid() == 1) { setsid(); if (ioctl(0, TIOCSCTTY, 1) != 0) { - (void) fputs (_("TIOCSCTTY failed"), stderr); + (void) fputs(_("TIOCSCTTY failed"), stderr); } } while (NULL != *envp) { /* add inherited environment, */ @@ -117,11 +117,11 @@ main(int argc, char *argv[]) } #ifndef USE_PAM - env = getdef_str ("ENV_TZ"); + env = getdef_str("ENV_TZ"); if (NULL != env) { addenv(strprefix(env, "/") ? tz(env) : env, NULL); } - env = getdef_str ("ENV_HZ"); + env = getdef_str("ENV_HZ"); if (NULL != env) { addenv (env, NULL); /* set the default $HZ, if one */ } @@ -157,31 +157,31 @@ main(int argc, char *argv[]) * --marekm */ if ((NULL == pass) || streq(pass, "")) { - erase_pass (pass); - (void) puts (""); + erase_pass(pass); + (void) puts(""); #ifdef TELINIT - execl (PATH_TELINIT, "telinit", RUNLEVEL, (char *) NULL); + execl(PATH_TELINIT, "telinit", RUNLEVEL, (char *) NULL); #endif - exit (0); + exit(0); } done = valid(pass, &pwent); - erase_pass (pass); + erase_pass(pass); if (!done) { /* check encrypted passwords ... */ /* ... encrypted passwords did not match */ - sleep (2); - (void) puts (_("Login incorrect")); + sleep(2); + (void) puts(_("Login incorrect")); } } while (!done); - (void) alarm (0); - (void) signal (SIGALRM, SIG_DFL); + (void) alarm(0); + (void) signal(SIGALRM, SIG_DFL); environ = newenvp; /* make new environment active */ (void) puts (_("Entering System Maintenance Mode")); /* exec the shell finally. */ - err = shell (pwent.pw_shell, NULL, environ); + err = shell(pwent.pw_shell, NULL, environ); return ((err == ENOENT) ? E_CMD_NOTFOUND : E_CMD_NOEXEC); } diff --git a/src/useradd.c b/src/useradd.c index 41ef076916..0318506574 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -224,31 +224,31 @@ static bool home_added = false; #define DLOG_INIT "LOG_INIT" /* local function prototypes */ -NORETURN static void fail_exit (int, bool); +NORETURN static void fail_exit(int, bool); static void get_defaults(const struct option_flags *); -static void show_defaults (void); -static int set_defaults (void); +static void show_defaults(void); +static int set_defaults(void); static int get_groups(char *, const struct option_flags *); -static struct group * get_local_group (char * grp_name, bool process_selinux); -NORETURN static void usage (int status); -static void new_pwent (struct passwd *); +static struct group * get_local_group(char * grp_name, bool process_selinux); +NORETURN static void usage(int status); +static void new_pwent(struct passwd *); -static void new_spent (struct spwd *); -static void grp_update (bool); +static void new_spent(struct spwd *); +static void grp_update(bool); -static void process_flags (int argc, char **argv, struct option_flags *flags); +static void process_flags(int argc, char **argv, struct option_flags *flags); static void close_files(const struct option_flags *flags); -static void close_group_files (bool process_selinux); -static void unlock_group_files (bool process_selinux); -static void open_files (bool process_selinux); -static void open_group_files (bool process_selinux); -static void open_shadow (bool process_selinux); -static void faillog_reset (uid_t); +static void close_group_files(bool process_selinux); +static void unlock_group_files(bool process_selinux); +static void open_files(bool process_selinux); +static void open_group_files(bool process_selinux); +static void open_shadow(bool process_selinux); +static void faillog_reset(uid_t); #ifdef ENABLE_LASTLOG -static void lastlog_reset (uid_t); +static void lastlog_reset(uid_t); #endif /* ENABLE_LASTLOG */ -static void tallylog_reset (const char *); -static void usr_update (unsigned long subuid_count, unsigned long subgid_count, +static void tallylog_reset(const char *); +static void usr_update(unsigned long subuid_count, unsigned long subgid_count, const struct option_flags *flags); static void create_home(const struct option_flags *flags); static void create_mail(const struct option_flags *flags); @@ -258,7 +258,7 @@ static void check_uid_range(int rflg, uid_t user_id); /* * fail_exit - undo as much as possible */ -static void fail_exit (int code, bool process_selinux) +static void fail_exit(int code, bool process_selinux) { #ifdef WITH_AUDIT int type; @@ -312,7 +312,7 @@ static void fail_exit (int code, bool process_selinux) else type = AUDIT_ADD_USER; - audit_logger (type, + audit_logger(type, "add-user", user_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); #endif @@ -346,7 +346,7 @@ get_defaults(const struct option_flags *flags) * Open the defaults file for reading. */ - fp = fopen (default_file, "r"); + fp = fopen(default_file, "r"); if (NULL == fp) { goto getdef_err; } @@ -366,31 +366,31 @@ get_defaults(const struct option_flags *flags) * Primary GROUP identifier */ if (streq(buf, DGROUP)) { - const struct group *grp = prefix_getgr_nam_gid (cp); + const struct group *grp = prefix_getgr_nam_gid(cp); if (NULL == grp) { - fprintf (stderr, + fprintf(stderr, _("%s: group '%s' does not exist\n"), Prog, cp); - fprintf (stderr, + fprintf(stderr, _("%s: the %s= configuration in %s will be ignored\n"), Prog, DGROUP, default_file); } else { def_group = grp->gr_gid; - def_gname = xstrdup (grp->gr_name); + def_gname = xstrdup(grp->gr_name); } } ccp = cp; if (streq(buf, DGROUPS)) { - if (get_groups (cp, flags) != 0) { - fprintf (stderr, + if (get_groups(cp, flags) != 0) { + fprintf(stderr, _("%s: the '%s=' configuration in %s has an invalid group, ignoring the bad group\n"), Prog, DGROUPS, default_file); } if (user_groups[0] != NULL) { do_grp_update = true; - def_groups = xstrdup (cp); + def_groups = xstrdup(cp); } } /* @@ -412,10 +412,10 @@ get_defaults(const struct option_flags *flags) */ else if (streq(buf, DINACT)) { if (a2sl(&def_inactive, ccp, NULL, 0, -1, LONG_MAX) == -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid numeric argument '%s'\n"), Prog, ccp); - fprintf (stderr, + fprintf(stderr, _("%s: the %s= configuration in %s will be ignored\n"), Prog, DINACT, default_file); def_inactive = -1; @@ -485,7 +485,7 @@ get_defaults(const struct option_flags *flags) def_log_init = xstrdup(ccp); } } - (void) fclose (fp); + (void) fclose(fp); getdef_err: if (prefix[0]) { free(default_file); @@ -498,19 +498,19 @@ get_defaults(const struct option_flags *flags) * show_defaults() displays the values that are used from the default * file and the built-in values. */ -static void show_defaults (void) +static void show_defaults(void) { - printf ("GROUP=%u\n", (unsigned int) def_group); - printf ("GROUPS=%s\n", def_groups); - printf ("HOME=%s\n", def_home); - printf ("INACTIVE=%ld\n", def_inactive); - printf ("EXPIRE=%s\n", def_expire); - printf ("SHELL=%s\n", def_shell); - printf ("SKEL=%s\n", def_template); - printf ("USRSKEL=%s\n", def_usrtemplate); - printf ("CREATE_MAIL_SPOOL=%s\n", def_create_mail_spool); - printf ("BTRFS_SUBVOLUME_HOME=%s\n", def_btrfs_subvolume_home); - printf ("LOG_INIT=%s\n", def_log_init); + printf("GROUP=%u\n", (unsigned int) def_group); + printf("GROUPS=%s\n", def_groups); + printf("HOME=%s\n", def_home); + printf("INACTIVE=%ld\n", def_inactive); + printf("EXPIRE=%s\n", def_expire); + printf("SHELL=%s\n", def_shell); + printf("SKEL=%s\n", def_template); + printf("USRSKEL=%s\n", def_usrtemplate); + printf("CREATE_MAIL_SPOOL=%s\n", def_create_mail_spool); + printf("BTRFS_SUBVOLUME_HOME=%s\n", def_btrfs_subvolume_home); + printf("LOG_INIT=%s\n", def_log_init); } /* @@ -562,7 +562,7 @@ set_defaults(void) new_file_dup = strdup(new_file); if (new_file_dup == NULL) { - fprintf (stderr, + fprintf(stderr, _("%s: cannot create directory for defaults file\n"), Prog); goto err_free_def; @@ -571,7 +571,7 @@ set_defaults(void) ret = mkdir(dirname(new_file_dup), 0755); free(new_file_dup); if (-1 == ret && EEXIST != errno) { - fprintf (stderr, + fprintf(stderr, _("%s: cannot create directory for defaults file\n"), Prog); goto err_free_def; @@ -582,7 +582,7 @@ set_defaults(void) */ ofp = fmkomstemp(new_file, 0, 0644); if (NULL == ofp) { - fprintf (stderr, + fprintf(stderr, _("%s: cannot open new defaults file\n"), Prog); goto err_free_def; @@ -593,9 +593,9 @@ set_defaults(void) * temporary file, using any new values. Each line is checked * to insure that it is not output more than once. */ - ifp = fopen (default_file, "r"); + ifp = fopen(default_file, "r"); if (NULL == ifp) { - fprintf (ofp, "# useradd defaults file\n"); + fprintf(ofp, "# useradd defaults file\n"); goto skip; } @@ -606,8 +606,8 @@ set_defaults(void) /* A line which does not end with \n is only valid * at the end of the file. */ - if (feof (ifp) == 0) { - fprintf (stderr, + if (feof(ifp) == 0) { + fprintf(stderr, _("%s: line too long in %s: %s..."), Prog, default_file, buf); fclose(ifp); @@ -662,7 +662,7 @@ set_defaults(void) fprintf(ofp, "%s=%s\n", buf, val); } } - (void) fclose (ifp); + (void) fclose(ifp); skip: /* @@ -671,38 +671,38 @@ set_defaults(void) * have an entry for that value. */ if (!out_group) - fprintf (ofp, DGROUP "=%u\n", (unsigned int) def_group); + fprintf(ofp, DGROUP "=%u\n", (unsigned int) def_group); if (!out_groups) - fprintf (ofp, DGROUPS "=%s\n", def_groups); + fprintf(ofp, DGROUPS "=%s\n", def_groups); if (!out_home) - fprintf (ofp, DHOME "=%s\n", def_home); + fprintf(ofp, DHOME "=%s\n", def_home); if (!out_inactive) - fprintf (ofp, DINACT "=%ld\n", def_inactive); + fprintf(ofp, DINACT "=%ld\n", def_inactive); if (!out_expire) - fprintf (ofp, DEXPIRE "=%s\n", def_expire); + fprintf(ofp, DEXPIRE "=%s\n", def_expire); if (!out_shell) - fprintf (ofp, DSHELL "=%s\n", def_shell); + fprintf(ofp, DSHELL "=%s\n", def_shell); if (!out_skel) - fprintf (ofp, DSKEL "=%s\n", def_template); + fprintf(ofp, DSKEL "=%s\n", def_template); if (!out_usrskel) - fprintf (ofp, DUSRSKEL "=%s\n", def_usrtemplate); + fprintf(ofp, DUSRSKEL "=%s\n", def_usrtemplate); if (!out_create_mail_spool) - fprintf (ofp, DCREATE_MAIL_SPOOL "=%s\n", def_create_mail_spool); + fprintf(ofp, DCREATE_MAIL_SPOOL "=%s\n", def_create_mail_spool); if (!out_btrfs_subvolume_home) - fprintf (ofp, DBTRFS_SUBVOLUME_HOME "=%s\n", def_btrfs_subvolume_home); + fprintf(ofp, DBTRFS_SUBVOLUME_HOME "=%s\n", def_btrfs_subvolume_home); if (!out_log_init) - fprintf (ofp, DLOG_INIT "=%s\n", def_log_init); + fprintf(ofp, DLOG_INIT "=%s\n", def_log_init); /* * Flush and close the file. Check for errors to make certain * the new file is intact. */ - (void) fflush (ofp); - if ( (ferror (ofp) != 0) - || (fsync (fileno (ofp)) != 0) - || (fclose (ofp) != 0)) + (void) fflush(ofp); + if ( (ferror(ofp) != 0) + || (fsync(fileno(ofp)) != 0) + || (fclose(ofp) != 0)) { - unlink (new_file); + unlink(new_file); goto err_free_def; } @@ -710,26 +710,26 @@ set_defaults(void) * Rename the current default file to its backup name. */ assert(stprintf_a(buf, "%s-", default_file) != -1); - unlink (buf); - if ((link (default_file, buf) != 0) && (ENOENT != errno)) { - fprintf (stderr, - _("%s: Cannot create backup file (%s): %s\n"), + unlink(buf); + if ((link(default_file, buf) != 0) && (ENOENT != errno)) { + fprintf(stderr, + _("%s: Cannot create backup file(%s): %s\n"), Prog, buf, strerrno()); - unlink (new_file); + unlink(new_file); goto err_free_def; } /* * Rename the new default file to its correct name. */ - if (rename (new_file, default_file) != 0) { - fprintf (stderr, + if (rename(new_file, default_file) != 0) { + fprintf(stderr, _("%s: rename: %s: %s\n"), Prog, new_file, strerrno()); goto err_free_def; } #ifdef WITH_AUDIT - audit_logger (AUDIT_USYS_CONFIG, + audit_logger(AUDIT_USYS_CONFIG, "changing-useradd-defaults", NULL, AUDIT_NO_ID, SHADOW_AUDIT_SUCCESS); @@ -779,7 +779,7 @@ static int get_groups(char *list, const struct option_flags *flags) /* * Open the group files */ - open_group_files (process_selinux); + open_group_files(process_selinux); /* * So long as there is some data to be converted, strip off @@ -807,7 +807,7 @@ static int get_groups(char *list, const struct option_flags *flags) * otherwise, we can't change its members */ if (NULL == grp) { - fprintf (stderr, + fprintf(stderr, _("%s: group '%s' does not exist\n"), Prog, g); errors = true; @@ -822,8 +822,8 @@ static int get_groups(char *list, const struct option_flags *flags) } if (ngroups == sys_ngroups) { - fprintf (stderr, - _("%s: too many groups specified (max %zu).\n"), + fprintf(stderr, + _("%s: too many groups specified(max %zu).\n"), Prog, ngroups); gr_free(grp); break; @@ -832,12 +832,12 @@ static int get_groups(char *list, const struct option_flags *flags) /* * Add the group name to the user's list of groups. */ - user_groups[ngroups++] = xstrdup (grp->gr_name); - gr_free (grp); + user_groups[ngroups++] = xstrdup(grp->gr_name); + gr_free(grp); } - close_group_files (process_selinux); - unlock_group_files (process_selinux); + close_group_files(process_selinux); + unlock_group_files(process_selinux); user_groups[ngroups] = NULL; @@ -870,12 +870,12 @@ static struct group * get_local_group(char * grp_name, bool process_selinux) grp = gr_locate(grp_name); if (grp != NULL) { - result_grp = __gr_dup (grp); + result_grp = __gr_dup(grp); if (NULL == result_grp) { - fprintf (stderr, + fprintf(stderr, _("%s: Out of memory. Cannot find group '%s'.\n"), Prog, grp_name); - fail_exit (E_GRP_UPDATE, process_selinux); + fail_exit(E_GRP_UPDATE, process_selinux); } } @@ -885,50 +885,50 @@ static struct group * get_local_group(char * grp_name, bool process_selinux) /* * usage - display usage message and exit */ -static void usage (int status) +static void usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] LOGIN\n" " %s -D\n" " %s -D [options]\n" "\n" "Options:\n"), Prog, Prog, Prog); - (void) fputs (_(" --badname do not check for bad names\n"), usageout); - (void) fputs (_(" -b, --base-dir BASE_DIR base directory for the home directory of the\n" + (void) fputs(_(" --badname do not check for bad names\n"), usageout); + (void) fputs(_(" -b, --base-dir BASE_DIR base directory for the home directory of the\n" " new account\n"), usageout); #ifdef WITH_BTRFS - (void) fputs (_(" --btrfs-subvolume-home use BTRFS subvolume for home directory\n"), usageout); + (void) fputs(_(" --btrfs-subvolume-home use BTRFS subvolume for home directory\n"), usageout); #endif - (void) fputs (_(" -c, --comment COMMENT GECOS field of the new account\n"), usageout); - (void) fputs (_(" -d, --home-dir HOME_DIR home directory of the new account\n"), usageout); - (void) fputs (_(" -D, --defaults print or change default useradd configuration\n"), usageout); - (void) fputs (_(" -e, --expiredate EXPIRE_DATE expiration date of the new account\n"), usageout); - (void) fputs (_(" -f, --inactive INACTIVE password inactivity period of the new account\n"), usageout); + (void) fputs(_(" -c, --comment COMMENT GECOS field of the new account\n"), usageout); + (void) fputs(_(" -d, --home-dir HOME_DIR home directory of the new account\n"), usageout); + (void) fputs(_(" -D, --defaults print or change default useradd configuration\n"), usageout); + (void) fputs(_(" -e, --expiredate EXPIRE_DATE expiration date of the new account\n"), usageout); + (void) fputs(_(" -f, --inactive INACTIVE password inactivity period of the new account\n"), usageout); #ifdef ENABLE_SUBIDS - (void) fputs (_(" -F, --add-subids-for-system add entries to sub[ud]id even when adding a system user\n"), usageout); + (void) fputs(_(" -F, --add-subids-for-system add entries to sub[ud]id even when adding a system user\n"), usageout); #endif - (void) fputs (_(" -g, --gid GROUP name or ID of the primary group of the new\n" + (void) fputs(_(" -g, --gid GROUP name or ID of the primary group of the new\n" " account\n"), usageout); - (void) fputs (_(" -G, --groups GROUPS list of supplementary groups of the new\n" + (void) fputs(_(" -G, --groups GROUPS list of supplementary groups of the new\n" " account\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -k, --skel SKEL_DIR use this alternative skeleton directory\n"), usageout); - (void) fputs (_(" -K, --key KEY=VALUE override /etc/login.defs defaults\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -k, --skel SKEL_DIR use this alternative skeleton directory\n"), usageout); + (void) fputs(_(" -K, --key KEY=VALUE override /etc/login.defs defaults\n"), usageout); #ifdef ENABLE_LASTLOG - (void) fputs (_(" -l, --no-log-init do not add the user to the lastlog and\n" + (void) fputs(_(" -l, --no-log-init do not add the user to the lastlog and\n" " faillog databases\n"), usageout); #endif /* ENABLE_LASTLOG */ - (void) fputs (_(" -m, --create-home create the user's home directory\n"), usageout); - (void) fputs (_(" -M, --no-create-home do not create the user's home directory\n"), usageout); - (void) fputs (_(" -N, --no-user-group do not create a group with the same name as\n" + (void) fputs(_(" -m, --create-home create the user's home directory\n"), usageout); + (void) fputs(_(" -M, --no-create-home do not create the user's home directory\n"), usageout); + (void) fputs(_(" -N, --no-user-group do not create a group with the same name as\n" " the user\n"), usageout); - (void) fputs (_(" -o, --non-unique allow to create users with duplicate\n" + (void) fputs(_(" -o, --non-unique allow to create users with duplicate\n" " (non-unique) UID\n"), usageout); - (void) fputs (_(" -p, --password PASSWORD encrypted password of the new account\n"), usageout); - (void) fputs (_(" -r, --system create a system account\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -p, --password PASSWORD encrypted password of the new account\n"), usageout); + (void) fputs(_(" -r, --system create a system account\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout); (void) fputs (_(" -s, --shell SHELL login shell of the new account\n"), usageout); (void) fputs (_(" -u, --uid UID user ID of the new account\n"), usageout); @@ -947,9 +947,9 @@ static void usage (int status) * new_pwent() takes all of the values that have been entered and * fills in a (struct passwd) with them. */ -static void new_pwent (struct passwd *pwent) +static void new_pwent(struct passwd *pwent) { - memzero(pwent, sizeof(*pwent)); + memzero(pwent, sizeof (*pwent)); pwent->pw_name = (char *) user_name; if (is_shadow_pwd) { pwent->pw_passwd = (char *) SHADOW_PASSWD_STRING; @@ -970,12 +970,12 @@ static void new_pwent (struct passwd *pwent) * new_spent() takes all of the values that have been entered and * fills in a (struct spwd) with them. */ -static void new_spent (struct spwd *spent) +static void new_spent(struct spwd *spent) { - memzero(spent, sizeof(*spent)); + memzero(spent, sizeof (*spent)); spent->sp_namp = (char *) user_name; spent->sp_pwdp = (char *) user_pass; - spent->sp_lstchg = gettime () / DAY; + spent->sp_lstchg = gettime() / DAY; if (0 == spent->sp_lstchg) { /* Better disable aging than requiring a password change */ spent->sp_lstchg = -1; @@ -1007,7 +1007,7 @@ static void new_spent (struct spwd *spent) * close_files() should be called afterwards to commit the changes * and unlocking the group files. */ -static void grp_update (bool process_selinux) +static void grp_update(bool process_selinux) { const struct group *grp; struct group *ngrp; @@ -1023,13 +1023,13 @@ static void grp_update (bool process_selinux) * FIXME: we currently do not check that all groups of user_groups * were completed with the new user. */ - for (gr_rewind (), grp = gr_next (); NULL != grp; grp = gr_next ()) { + for (gr_rewind(), grp = gr_next(); NULL != grp; grp = gr_next()) { /* * See if the user specified this group as one of their * concurrent groups. */ - if (!is_on_list (user_groups, grp->gr_name)) { + if (!is_on_list(user_groups, grp->gr_name)) { continue; } @@ -1037,11 +1037,11 @@ static void grp_update (bool process_selinux) * Make a copy - gr_update() will free() everything * from the old entry, and we need it later. */ - ngrp = __gr_dup (grp); + ngrp = __gr_dup(grp); if (NULL == ngrp) { - fprintf (stderr, + fprintf(stderr, _("%s: Out of memory. Cannot update %s.\n"), - Prog, gr_dbname ()); + Prog, gr_dbname()); SYSLOG(LOG_ERR, "failed to prepare the new %s entry '%s'", gr_dbname(), user_name); fail_exit (E_GRP_UPDATE, process_selinux); /* XXX */ } @@ -1050,16 +1050,16 @@ static void grp_update (bool process_selinux) * Add the username to the list of group members and * update the group entry to reflect the change. */ - ngrp->gr_mem = add_list (ngrp->gr_mem, user_name); - if (gr_update (ngrp) == 0) { - fprintf (stderr, + ngrp->gr_mem = add_list(ngrp->gr_mem, user_name); + if (gr_update(ngrp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), ngrp->gr_name); + Prog, gr_dbname(), ngrp->gr_name); SYSLOG(LOG_ERR, "failed to prepare the new %s entry '%s'", gr_dbname(), user_name); - fail_exit (E_GRP_UPDATE, process_selinux); + fail_exit(E_GRP_UPDATE, process_selinux); } #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "add-user-to-group", user_name, AUDIT_NO_ID, "grp", ngrp->gr_name, SHADOW_AUDIT_SUCCESS); @@ -1076,7 +1076,7 @@ static void grp_update (bool process_selinux) * that the user is a member of. The administrative list isn't * modified. */ - for (sgr_rewind (), sgrp = sgr_next (); NULL != sgrp; sgrp = sgr_next ()) { + for (sgr_rewind(), sgrp = sgr_next(); NULL != sgrp; sgrp = sgr_next()) { /* * See if the user specified this group as one of their @@ -1086,11 +1086,11 @@ static void grp_update (bool process_selinux) * user_groups. All these groups should be checked * for existence with gr_locate already. */ - if (gr_locate (sgrp->sg_namp) == NULL) { + if (gr_locate(sgrp->sg_namp) == NULL) { continue; } - if (!is_on_list (user_groups, sgrp->sg_namp)) { + if (!is_on_list(user_groups, sgrp->sg_namp)) { continue; } @@ -1098,11 +1098,11 @@ static void grp_update (bool process_selinux) * Make a copy - sgr_update() will free() everything * from the old entry, and we need it later. */ - nsgrp = __sgr_dup (sgrp); + nsgrp = __sgr_dup(sgrp); if (NULL == nsgrp) { - fprintf (stderr, + fprintf(stderr, _("%s: Out of memory. Cannot update %s.\n"), - Prog, sgr_dbname ()); + Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failed to prepare the new %s entry '%s'", sgr_dbname(), user_name); fail_exit (E_GRP_UPDATE, process_selinux); /* XXX */ } @@ -1111,17 +1111,17 @@ static void grp_update (bool process_selinux) * Add the username to the list of group members and * update the group entry to reflect the change. */ - nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_name); - if (sgr_update (nsgrp) == 0) { - fprintf (stderr, + nsgrp->sg_mem = add_list(nsgrp->sg_mem, user_name); + if (sgr_update(nsgrp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), nsgrp->sg_namp); + Prog, sgr_dbname(), nsgrp->sg_namp); SYSLOG(LOG_ERR, "failed to prepare the new %s entry '%s'", sgr_dbname(), user_name); - fail_exit (E_GRP_UPDATE, process_selinux); + fail_exit(E_GRP_UPDATE, process_selinux); } #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "add-to-shadow-group", user_name, AUDIT_NO_ID, "grp", nsgrp->sg_namp, SHADOW_AUDIT_SUCCESS); @@ -1139,7 +1139,7 @@ static void grp_update (bool process_selinux) * the values that the user will be created with accordingly. The * values are checked for sanity. */ -static void process_flags (int argc, char **argv, struct option_flags *flags) +static void process_flags(int argc, char **argv, struct option_flags *flags) { const struct group *grp; bool anyflag = false; @@ -1188,7 +1188,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) #endif /* WITH_SELINUX */ {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, + while ((c = getopt_long(argc, argv, "b:c:d:De:f:g:G:hk:K:lmMNop:rR:P:s:u:U" #ifdef WITH_SELINUX "Z:" @@ -1200,12 +1200,12 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) long_options, NULL)) != -1) { switch (c) { case 'b': - if ( ( !VALID (optarg) ) + if ( ( !VALID(optarg) ) || ( optarg[0] != '/' )) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid base directory '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } def_home = optarg; bflg = true; @@ -1217,40 +1217,40 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) allow_bad_names = true; break; case 'c': - if (!VALID (optarg)) { - fprintf (stderr, + if (!VALID(optarg)) { + fprintf(stderr, _("%s: invalid comment '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } user_comment = optarg; cflg = true; break; case 'd': - if ( ( !VALID (optarg) ) + if ( ( !VALID(optarg) ) || ( optarg[0] != '/' )) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid home directory '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } user_home = optarg; dflg = true; break; case 'D': if (anyflag) { - usage (E_USAGE); + usage(E_USAGE); } Dflg = true; break; case 'e': if (!streq(optarg, "")) { - user_expire = strtoday (optarg); + user_expire = strtoday(optarg); if (user_expire < -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid date '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } } else { user_expire = -1; @@ -1261,10 +1261,10 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * (it's a no-op in such case) */ if ((-1 != user_expire) && !is_shadow_pwd) { - fprintf (stderr, + fprintf(stderr, _("%s: shadow passwords required for -e\n"), Prog); - exit (E_USAGE); + exit(E_USAGE); } if (Dflg) { def_expire = optarg; @@ -1275,20 +1275,20 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) if (a2sl(&def_inactive, optarg, NULL, 0, -1, LONG_MAX) == -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } /* * -f -1 is allowed * it's a no-op without /etc/shadow */ if ((-1 != def_inactive) && !is_shadow_pwd) { - fprintf (stderr, + fprintf(stderr, _("%s: shadow passwords required for -f\n"), Prog); - exit (E_USAGE); + exit(E_USAGE); } fflg = true; break; @@ -1298,12 +1298,12 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) break; #endif case 'g': - grp = prefix_getgr_nam_gid (optarg); + grp = prefix_getgr_nam_gid(optarg); if (NULL == grp) { - fprintf (stderr, + fprintf(stderr, _("%s: group '%s' does not exist\n"), Prog, optarg); - exit (E_NOTFOUND); + exit(E_NOTFOUND); } if (Dflg) { def_group = grp->gr_gid; @@ -1314,8 +1314,8 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) gflg = true; break; case 'G': - if (get_groups (optarg, flags) != 0) { - exit (E_NOTFOUND); + if (get_groups(optarg, flags) != 0) { + exit(E_NOTFOUND); } if (NULL != user_groups[0]) { do_grp_update = true; @@ -1323,7 +1323,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) Gflg = true; break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); break; case 'k': def_template = optarg; @@ -1337,13 +1337,13 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) */ cp = stpsep(optarg, "="); if (NULL == cp) { - fprintf (stderr, + fprintf(stderr, _("%s: -K requires KEY=VALUE\n"), Prog); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } - if (putdef_str (optarg, cp, NULL) < 0) { - exit (E_BAD_ARG); + if (putdef_str(optarg, cp, NULL) < 0) { + exit(E_BAD_ARG); } break; case 'l': @@ -1451,7 +1451,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) if (!gflg && !Nflg && !Uflg) { /* Get the settings from login.defs */ - Uflg = getdef_bool ("USERGROUPS_ENAB"); + Uflg = getdef_bool("USERGROUPS_ENAB"); } /* @@ -1459,41 +1459,41 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) * Check it here so that they can be specified in any order. */ if (oflg && !uflg) { - fprintf (stderr, + fprintf(stderr, _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-o", "-u"); - usage (E_USAGE); + usage(E_USAGE); } if (kflg && !mflg) { - fprintf (stderr, + fprintf(stderr, _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-k", "-m"); - usage (E_USAGE); + usage(E_USAGE); } if (Uflg && gflg) { - fprintf (stderr, + fprintf(stderr, _("%s: options %s and %s conflict\n"), Prog, "-U", "-g"); - usage (E_USAGE); + usage(E_USAGE); } if (Uflg && Nflg) { - fprintf (stderr, + fprintf(stderr, _("%s: options %s and %s conflict\n"), Prog, "-U", "-N"); - usage (E_USAGE); + usage(E_USAGE); } if (mflg && Mflg) { - fprintf (stderr, + fprintf(stderr, _("%s: options %s and %s conflict\n"), Prog, "-m", "-M"); - usage (E_USAGE); + usage(E_USAGE); } #ifdef WITH_SELINUX if (user_selinux_range && !Zflg) { - fprintf (stderr, + fprintf(stderr, _("%s: %s flag is only allowed with the %s flag\n"), Prog, "--selinux-range", "--selinux-user"); - usage (E_USAGE); + usage(E_USAGE); } #endif /* WITH_SELINUX */ @@ -1503,15 +1503,15 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) */ if (Dflg) { if (optind != argc) { - usage (E_USAGE); + usage(E_USAGE); } if (uflg || Gflg || dflg || cflg || mflg) { - usage (E_USAGE); + usage(E_USAGE); } } else { if (optind != argc - 1) { - usage (E_USAGE); + usage(E_USAGE); } user_name = argv[optind]; @@ -1526,12 +1526,12 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) Prog, user_name); } #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_USER, + audit_logger(AUDIT_ADD_USER, "add-user", user_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); #endif - exit (E_BAD_NAME); + exit(E_BAD_NAME); } if (!dflg) { user_home = xaprintf("%s/%s", def_home, user_name); @@ -1544,7 +1544,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) } if (!eflg) { - user_expire = strtoday (def_expire); + user_expire = strtoday(def_expire); } if (!gflg) { @@ -1568,7 +1568,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags) if (!rflg) { /* for system accounts defaults are ignored and we * do not create a home dir */ - if (getdef_bool ("CREATE_HOME")) { + if (getdef_bool("CREATE_HOME")) { mflg = true; } } @@ -1597,40 +1597,40 @@ static void close_files(const struct option_flags *flags) process_selinux = !flags->chroot && !flags->prefix; - if (pw_close (process_selinux) == 0) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); + if (pw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", pw_dbname()); - fail_exit (E_PW_UPDATE, process_selinux); + fail_exit(E_PW_UPDATE, process_selinux); } - if (is_shadow_pwd && (spw_close (process_selinux) == 0)) { - fprintf (stderr, - _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ()); + if (is_shadow_pwd && (spw_close(process_selinux) == 0)) { + fprintf(stderr, + _("%s: failure while writing changes to %s\n"), Prog, spw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", spw_dbname()); - fail_exit (E_PW_UPDATE, process_selinux); + fail_exit(E_PW_UPDATE, process_selinux); } - close_group_files (process_selinux); + close_group_files(process_selinux); #ifdef ENABLE_SUBIDS - if (is_sub_uid && (sub_uid_close (process_selinux) == 0)) { - fprintf (stderr, - _("%s: failure while writing changes to %s\n"), Prog, sub_uid_dbname ()); + if (is_sub_uid && (sub_uid_close(process_selinux) == 0)) { + fprintf(stderr, + _("%s: failure while writing changes to %s\n"), Prog, sub_uid_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", sub_uid_dbname()); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } - if (is_sub_gid && (sub_gid_close (process_selinux) == 0)) { - fprintf (stderr, - _("%s: failure while writing changes to %s\n"), Prog, sub_gid_dbname ()); + if (is_sub_gid && (sub_gid_close(process_selinux) == 0)) { + fprintf(stderr, + _("%s: failure while writing changes to %s\n"), Prog, sub_gid_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", sub_gid_dbname()); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } #endif /* ENABLE_SUBIDS */ if (is_shadow_pwd) { - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_USER, + audit_logger(AUDIT_ADD_USER, "unlocking-shadow-file", user_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -1652,15 +1652,15 @@ static void close_files(const struct option_flags *flags) } pw_locked = false; - unlock_group_files (process_selinux); + unlock_group_files(process_selinux); #ifdef ENABLE_SUBIDS if (is_sub_uid) { - if (sub_uid_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname ()); + if (sub_uid_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sub_uid_dbname()); #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_USER, + audit_logger(AUDIT_ADD_USER, "unlocking-subordinate-user-file", user_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -1692,7 +1692,7 @@ static void close_files(const struct option_flags *flags) * close_group_files() closes all of the files that were opened related * with groups. This causes any modified entries to be written out. */ -static void close_group_files (bool process_selinux) +static void close_group_files(bool process_selinux) { if (!do_grp_update) return; @@ -1721,13 +1721,13 @@ static void close_group_files (bool process_selinux) * unlock_group_files() unlocks all of the files that were locked related * with groups. This causes any modified entries to be written out. */ -static void unlock_group_files (bool process_selinux) +static void unlock_group_files(bool process_selinux) { - if (gr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + if (gr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", gr_dbname()); #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_USER, + audit_logger(AUDIT_ADD_USER, "unlocking-group-file", user_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -1758,18 +1758,18 @@ static void unlock_group_files (bool process_selinux) * * open_files() opens the two password files. */ -static void open_files (bool process_selinux) +static void open_files(bool process_selinux) { - if (pw_lock () == 0) { - fprintf (stderr, + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - exit (E_PW_UPDATE); + Prog, pw_dbname()); + exit(E_PW_UPDATE); } pw_locked = true; - if (pw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + if (pw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, pw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } /* shadow file will be opened by open_shadow(); */ @@ -1872,9 +1872,9 @@ static char *empty_list = NULL; * in a (struct group) with them. */ -static void new_grent (struct group *grent) +static void new_grent(struct group *grent) { - memzero(grent, sizeof(*grent)); + memzero(grent, sizeof (*grent)); grent->gr_name = (char *) user_name; #ifdef SHADOWGRP if (is_shadow_grp) { @@ -1896,9 +1896,9 @@ static void new_grent (struct group *grent) * in a (struct sgrp) with them. */ -static void new_sgent (struct sgrp *sgent) +static void new_sgent(struct sgrp *sgent) { - memzero(sgent, sizeof(*sgent)); + memzero(sgent, sizeof (*sgent)); sgent->sg_namp = (char *) user_name; sgent->sg_passwd = "!"; /* XXX warning: const */ sgent->sg_adm = &empty_list; @@ -1913,7 +1913,7 @@ static void new_sgent (struct sgrp *sgent) * grp_add() writes the new records to the group files. */ -static void grp_add (bool process_selinux) +static void grp_add(bool process_selinux) { struct group grp; @@ -1924,46 +1924,46 @@ static void grp_add (bool process_selinux) /* * Create the initial entries for this new group. */ - new_grent (&grp); + new_grent(&grp); #ifdef SHADOWGRP - new_sgent (&sgrp); + new_sgent(&sgrp); #endif /* SHADOWGRP */ /* * Write out the new group file entry. */ - if (gr_update (&grp) == 0) { - fprintf (stderr, + if (gr_update(&grp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), grp.gr_name); + Prog, gr_dbname(), grp.gr_name); #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_GROUP, + audit_logger(AUDIT_ADD_GROUP, "add-group", grp.gr_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); #endif - fail_exit (E_GRP_UPDATE, process_selinux); + fail_exit(E_GRP_UPDATE, process_selinux); } #ifdef SHADOWGRP /* * Write out the new shadow group entries as well. */ - if (is_shadow_grp && (sgr_update (&sgrp) == 0)) { - fprintf (stderr, + if (is_shadow_grp && (sgr_update(&sgrp) == 0)) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), sgrp.sg_namp); + Prog, sgr_dbname(), sgrp.sg_namp); #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_GROUP, + audit_logger(AUDIT_ADD_GROUP, "add-group", grp.gr_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); #endif - fail_exit (E_GRP_UPDATE, process_selinux); + fail_exit(E_GRP_UPDATE, process_selinux); } #endif /* SHADOWGRP */ SYSLOG(LOG_INFO, "new group: name=%s, GID=%u", user_name, user_gid); #ifdef WITH_AUDIT - audit_logger (AUDIT_ADD_GROUP, + audit_logger(AUDIT_ADD_GROUP, "add-group", grp.gr_name, AUDIT_NO_ID, SHADOW_AUDIT_SUCCESS); @@ -1971,37 +1971,37 @@ static void grp_add (bool process_selinux) do_grp_update = true; } -static void faillog_reset (uid_t uid) +static void faillog_reset(uid_t uid) { struct faillog fl; int fd; - off_t offset_uid = (off_t) sizeof(fl) * uid; + off_t offset_uid = (off_t) sizeof (fl) * uid; struct stat st; - if (stat (FAILLOG_FILE, &st) != 0 || st.st_size <= offset_uid) { + if (stat(FAILLOG_FILE, &st) != 0 || st.st_size <= offset_uid) { return; } - memzero(&fl, sizeof(fl)); + memzero(&fl, sizeof (fl)); - fd = open (FAILLOG_FILE, O_RDWR); + fd = open(FAILLOG_FILE, O_RDWR); if (-1 == fd) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to open the faillog file for UID %lu: %s\n"), Prog, (unsigned long) uid, strerrno()); SYSLOG(LOG_WARN, "failed to open the faillog file for UID %lu", (unsigned long) uid); return; } - if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (write_full(fd, &fl, sizeof(fl)) == -1) - || (fsync (fd) != 0)) { - fprintf (stderr, + if ( (lseek(fd, offset_uid, SEEK_SET) != offset_uid) + || (write_full(fd, &fl, sizeof (fl)) == -1) + || (fsync(fd) != 0)) { + fprintf(stderr, _("%s: failed to reset the faillog entry of UID %lu: %s\n"), Prog, (unsigned long) uid, strerrno()); SYSLOG(LOG_WARN, "failed to reset the faillog entry of UID %lu", (unsigned long) uid); } - if (close (fd) != 0 && errno != EINTR) { - fprintf (stderr, + if (close(fd) != 0 && errno != EINTR) { + fprintf(stderr, _("%s: failed to close the faillog file for UID %lu: %s\n"), Prog, (unsigned long) uid, strerrno()); SYSLOG(LOG_WARN, "failed to close the faillog file for UID %lu", (unsigned long) uid); @@ -2009,11 +2009,11 @@ static void faillog_reset (uid_t uid) } #ifdef ENABLE_LASTLOG -static void lastlog_reset (uid_t uid) +static void lastlog_reset(uid_t uid) { struct lastlog ll; int fd; - off_t offset_uid = (off_t) sizeof(ll) * uid; + off_t offset_uid = (off_t) sizeof (ll) * uid; uid_t max_uid; struct stat st; @@ -2021,7 +2021,7 @@ static void lastlog_reset (uid_t uid) return; } - max_uid = getdef_ulong ("LASTLOG_UID_MAX", 0xFFFFFFFFUL); + max_uid = getdef_ulong("LASTLOG_UID_MAX", 0xFFFFFFFFUL); if (uid > max_uid) { /* do not touch lastlog for large uids */ return; @@ -2046,8 +2046,8 @@ static void lastlog_reset (uid_t uid) SYSLOG(LOG_WARN, "failed to reset the lastlog entry of UID %lu", (unsigned long) uid); /* continue */ } - if (close (fd) != 0 && errno != EINTR) { - fprintf (stderr, + if (close(fd) != 0 && errno != EINTR) { + fprintf(stderr, _("%s: failed to close the lastlog file for UID %lu: %s\n"), Prog, (unsigned long) uid, strerrno()); SYSLOG(LOG_WARN, "failed to close the lastlog file for UID %lu", (unsigned long) uid); @@ -2092,7 +2092,7 @@ static void tallylog_reset (const char *user_name) if (failed) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to reset the tallylog entry of user \"%s\"\n"), Prog, user_name); SYSLOG(LOG_WARN, "failed to reset the tallylog entry of user \"%s\"", user_name); @@ -2108,7 +2108,7 @@ static void tallylog_reset (const char *user_name) * and will update the group entries if required. */ static void -usr_update (unsigned long subuid_count, unsigned long subgid_count, +usr_update(unsigned long subuid_count, unsigned long subgid_count, const struct option_flags *flags) { struct passwd pwent; @@ -2122,14 +2122,14 @@ usr_update (unsigned long subuid_count, unsigned long subgid_count, * Fill in the password structure with any new fields, making * copies of strings. */ - new_pwent (&pwent); - new_spent (&spent); + new_pwent(&pwent); + new_spent(&spent); /* * Create a syslog entry. We need to do this now in case anything * happens so we know what we were trying to accomplish. */ - tty=ttyname (STDIN_FILENO); + tty=ttyname(STDIN_FILENO); SYSLOG(LOG_INFO, "new user: name=%s, UID=%u, GID=%u, home=%s, shell=%s, from=%s", user_name, (unsigned int) user_id, @@ -2153,36 +2153,36 @@ usr_update (unsigned long subuid_count, unsigned long subgid_count, /* * Put the new (struct passwd) in the table. */ - if (pw_update (&pwent) == 0) { - fprintf (stderr, + if (pw_update(&pwent) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, pw_dbname (), pwent.pw_name); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, pw_dbname(), pwent.pw_name); + fail_exit(E_PW_UPDATE, process_selinux); } /* * Put the new (struct spwd) in the table. */ - if (is_shadow_pwd && (spw_update (&spent) == 0)) { - fprintf (stderr, + if (is_shadow_pwd && (spw_update(&spent) == 0)) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, spw_dbname (), spent.sp_namp); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, spw_dbname(), spent.sp_namp); + fail_exit(E_PW_UPDATE, process_selinux); } #ifdef ENABLE_SUBIDS if (is_sub_uid && !local_sub_uid_assigned(user_name) && (sub_uid_add(user_name, sub_uid_start, subuid_count) == 0)) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to prepare the new %s entry\n"), - Prog, sub_uid_dbname ()); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + Prog, sub_uid_dbname()); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } if (is_sub_gid && !local_sub_gid_assigned(user_name) && (sub_gid_add(user_name, sub_gid_start, subgid_count) == 0)) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to prepare the new %s entry\n"), - Prog, sub_uid_dbname ()); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + Prog, sub_uid_dbname()); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } #endif /* ENABLE_SUBIDS */ @@ -2192,7 +2192,7 @@ usr_update (unsigned long subuid_count, unsigned long subgid_count, * because its not written to disk yet. After close_files it is * and we can use the real ID thereafter. */ - audit_logger (AUDIT_ADD_USER, + audit_logger(AUDIT_ADD_USER, "add-user", user_name, AUDIT_NO_ID, SHADOW_AUDIT_SUCCESS); @@ -2201,7 +2201,7 @@ usr_update (unsigned long subuid_count, unsigned long subgid_count, * Do any group file updates for this user. */ if (do_grp_update) { - grp_update (process_selinux); + grp_update(process_selinux); } } @@ -2221,7 +2221,7 @@ static void create_home(const struct option_flags *flags) process_selinux = !flags->chroot && !flags->prefix; - if (access (prefix_user_home, F_OK) == 0) + if (access(prefix_user_home, F_OK) == 0) return; strcpy(path, ""); @@ -2452,9 +2452,9 @@ should_assign_subuid(void) uid_t uid_max; unsigned long subuid_count; - uid_min = getdef_ulong ("UID_MIN", 1000UL); - uid_max = getdef_ulong ("UID_MAX", 60000UL); - subuid_count = getdef_ulong ("SUB_UID_COUNT", 65536); + uid_min = getdef_ulong("UID_MIN", 1000UL); + uid_max = getdef_ulong("UID_MAX", 60000UL); + subuid_count = getdef_ulong("SUB_UID_COUNT", 65536); if (!want_subuid_file()) return false; @@ -2482,9 +2482,9 @@ should_assign_subgid(void) uid_t uid_max; unsigned long subgid_count; - uid_min = getdef_ulong ("UID_MIN", 1000UL); - uid_max = getdef_ulong ("UID_MAX", 60000UL); - subgid_count = getdef_ulong ("SUB_GID_COUNT", 65536); + uid_min = getdef_ulong("UID_MIN", 1000UL); + uid_max = getdef_ulong("UID_MAX", 60000UL); + subgid_count = getdef_ulong("SUB_GID_COUNT", 65536); if (!want_subgid_file()) return false; @@ -2507,7 +2507,7 @@ should_assign_subgid(void) /* * main - useradd command */ -int main (int argc, char **argv) +int main(int argc, char **argv) { unsigned long subuid_count = 0; unsigned long subgid_count = 0; @@ -2517,17 +2517,17 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); + process_root_flag("-R", argc, argv); prefix = process_prefix_flag("-P", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); #ifdef WITH_AUDIT - audit_help_open (); + audit_help_open(); #endif sys_ngroups = ngroups_max_size(); @@ -2538,24 +2538,24 @@ int main (int argc, char **argv) user_groups[0] = NULL; - is_shadow_pwd = spw_file_present (); + is_shadow_pwd = spw_file_present(); #ifdef SHADOWGRP - is_shadow_grp = sgr_file_present (); + is_shadow_grp = sgr_file_present(); #endif - get_defaults (&flags); + get_defaults(&flags); - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); process_selinux = !flags.chroot && !flags.prefix; #ifdef ENABLE_SUBIDS - subuid_count = getdef_ulong ("SUB_UID_COUNT", 65536); - subgid_count = getdef_ulong ("SUB_GID_COUNT", 65536); + subuid_count = getdef_ulong("SUB_UID_COUNT", 65536); + subgid_count = getdef_ulong("SUB_GID_COUNT", 65536); is_sub_uid = should_assign_subuid(); is_sub_gid = should_assign_subgid(); #endif /* ENABLE_SUBIDS */ - if (run_parts ("/etc/shadow-maint/useradd-pre.d", user_name, + if (run_parts("/etc/shadow-maint/useradd-pre.d", user_name, "useradd")) { exit(1); } @@ -2566,11 +2566,11 @@ int main (int argc, char **argv) */ if (Dflg) { if (gflg || bflg || fflg || eflg || sflg) { - exit ((set_defaults () != 0) ? 1 : 0); + exit((set_defaults() != 0) ? 1 : 0); } - show_defaults (); - exit (E_SUCCESS); + show_defaults(); + exit(E_SUCCESS); } /* @@ -2606,23 +2606,23 @@ int main (int argc, char **argv) * - flush nscd caches for passwd and group services, * - then close and update the files. */ - open_files (process_selinux); + open_files(process_selinux); if (!oflg) { /* first, seek for a valid uid to use for this user. * We do this because later we can use the uid we found as * gid too ... --gafton */ if (!uflg) { - if (find_new_uid (rflg, &user_id, NULL) < 0) { - fprintf (stderr, _("%s: can't create user\n"), Prog); - fail_exit (E_UID_IN_USE, process_selinux); + if (find_new_uid(rflg, &user_id, NULL) < 0) { + fprintf(stderr, _("%s: can't create user\n"), Prog); + fail_exit(E_UID_IN_USE, process_selinux); } } else { - if (prefix_getpwuid (user_id) != NULL) { - fprintf (stderr, + if (prefix_getpwuid(user_id) != NULL) { + fprintf(stderr, _("%s: UID %lu is not unique\n"), Prog, (unsigned long) user_id); - fail_exit (E_UID_IN_USE, process_selinux); + fail_exit(E_UID_IN_USE, process_selinux); } } } @@ -2630,33 +2630,33 @@ int main (int argc, char **argv) if (uflg) check_uid_range(rflg,user_id); #ifdef WITH_TCB - if (getdef_bool ("USE_TCB")) { - if (shadowtcb_create (user_name, user_id) == SHADOWTCB_FAILURE) { - fprintf (stderr, + if (getdef_bool("USE_TCB")) { + if (shadowtcb_create(user_name, user_id) == SHADOWTCB_FAILURE) { + fprintf(stderr, _("%s: Failed to create tcb directory for %s\n"), Prog, user_name); - fail_exit (E_UID_IN_USE, process_selinux); + fail_exit(E_UID_IN_USE, process_selinux); } } #endif - open_shadow (process_selinux); + open_shadow(process_selinux); /* do we have to add a group for that user? This is why we need to * open the group files in the open_files() function --gafton */ if (Uflg) { - if (find_new_gid (rflg, &user_gid, &user_id) < 0) { - fprintf (stderr, + if (find_new_gid(rflg, &user_gid, &user_id) < 0) { + fprintf(stderr, _("%s: can't create group\n"), Prog); - fail_exit (4, process_selinux); + fail_exit(4, process_selinux); } - grp_add (process_selinux); + grp_add(process_selinux); } #ifdef ENABLE_SUBIDS if (is_sub_uid && subuid_count != 0) { if (find_new_sub_uids(&sub_uid_start, &subuid_count) < 0) { - fprintf (stderr, + fprintf(stderr, _("%s: can't create subordinate user IDs\n"), Prog); fail_exit(E_SUB_UID_UPDATE, process_selinux); @@ -2664,7 +2664,7 @@ int main (int argc, char **argv) } if (is_sub_gid && subgid_count != 0) { if (find_new_sub_gids(&sub_gid_start, &subgid_count) < 0) { - fprintf (stderr, + fprintf(stderr, _("%s: can't create subordinate group IDs\n"), Prog); fail_exit(E_SUB_GID_UPDATE, process_selinux); @@ -2672,48 +2672,48 @@ int main (int argc, char **argv) } #endif /* ENABLE_SUBIDS */ - usr_update (subuid_count, subgid_count, &flags); + usr_update(subuid_count, subgid_count, &flags); - close_files (&flags); + close_files(&flags); - nscd_flush_cache ("passwd"); - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP); + nscd_flush_cache("passwd"); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_PASSWD | SSSD_DB_GROUP); /* * tallylog_reset needs to be able to lookup * a valid existing user name, * so we cannot call it before close_files() */ - if (!lflg && getpwuid (user_id) != NULL) { - tallylog_reset (user_name); + if (!lflg && getpwuid(user_id) != NULL) { + tallylog_reset(user_name); } #ifdef WITH_SELINUX if (Zflg) { - if (set_seuser (user_name, user_selinux, user_selinux_range) != 0) { - fprintf (stderr, + if (set_seuser(user_name, user_selinux, user_selinux_range) != 0) { + fprintf(stderr, _("%s: warning: the user name %s to %s SELinux user mapping failed.\n"), Prog, user_name, user_selinux); #ifdef WITH_AUDIT - audit_logger (AUDIT_ROLE_ASSIGN, + audit_logger(AUDIT_ROLE_ASSIGN, "add-selinux-user-mapping", user_name, user_id, SHADOW_AUDIT_FAILURE); #endif /* WITH_AUDIT */ - fail_exit (E_SE_UPDATE, process_selinux); + fail_exit(E_SE_UPDATE, process_selinux); } } #endif /* WITH_SELINUX */ if (mflg) { - create_home (&flags); + create_home(&flags); if (home_added) { - copy_tree (def_template, prefix_user_home, false, + copy_tree(def_template, prefix_user_home, false, (uid_t)-1, user_id, (gid_t)-1, user_gid); - copy_tree (def_usrtemplate, prefix_user_home, false, + copy_tree(def_usrtemplate, prefix_user_home, false, (uid_t)-1, user_id, (gid_t)-1, user_gid); } else { - fprintf (stderr, + fprintf(stderr, _("%s: warning: the home directory %s already exists.\n" "%s: Not copying any file from skel directory into it.\n"), Prog, user_home, Prog); diff --git a/src/userdel.c b/src/userdel.c index 9b7d81bedd..0e0cc55f85 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -132,21 +132,21 @@ static int remove_tcbdir (const char *user_name, uid_t user_id); /* * usage - display usage message and exit */ -static void usage (int status) +static void usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] LOGIN\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -f, --force force some actions that would fail otherwise\n" + (void) fputs(_(" -f, --force force some actions that would fail otherwise\n" " e.g. removal of user still logged in\n" " or files, even if not owned by the user\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -r, --remove remove home directory and mail spool\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -r, --remove remove home directory and mail spool\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout); #ifdef WITH_SELINUX (void) fputs (_(" -Z, --selinux-user remove any SELinux user mapping for the user\n"), usageout); @@ -165,7 +165,7 @@ static void usage (int status) * name is their user name) and delete them too (only if USERGROUPS_ENAB * is enabled). */ -static void update_groups (bool process_selinux) +static void update_groups(bool process_selinux) { const struct group *grp; struct group *ngrp; @@ -179,13 +179,13 @@ static void update_groups (bool process_selinux) * Scan through the entire group file looking for the groups that * the user is a member of. */ - for (gr_rewind (), grp = gr_next (); NULL != grp; grp = gr_next ()) { + for (gr_rewind(), grp = gr_next(); NULL != grp; grp = gr_next()) { /* * See if the user specified this group as one of their * concurrent groups. */ - if (!is_on_list (grp->gr_mem, user_name)) { + if (!is_on_list(grp->gr_mem, user_name)) { continue; } @@ -193,11 +193,11 @@ static void update_groups (bool process_selinux) * Delete the username from the list of group members and * update the group entry to reflect the change. */ - ngrp = __gr_dup (grp); + ngrp = __gr_dup(grp); if (NULL == ngrp) { - fprintf (stderr, + fprintf(stderr, _("%s: Out of memory. Cannot update %s.\n"), - Prog, gr_dbname ()); + Prog, gr_dbname()); exit (13); /* XXX */ } ngrp->gr_mem = del_list (ngrp->gr_mem, user_name); @@ -212,7 +212,7 @@ static void update_groups (bool process_selinux) * Update the DBM group file with the new entry as well. */ #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "deleting-user-from-group", user_name, user_id, "grp", ngrp->gr_name, SHADOW_AUDIT_SUCCESS); @@ -221,8 +221,8 @@ static void update_groups (bool process_selinux) user_name, ngrp->gr_name); } - if (getdef_bool ("USERGROUPS_ENAB")) { - remove_usergroup (process_selinux); + if (getdef_bool("USERGROUPS_ENAB")) { + remove_usergroup(process_selinux); } #ifdef SHADOWGRP @@ -235,27 +235,27 @@ static void update_groups (bool process_selinux) * that the user is a member of. Both the administrative list and * the ordinary membership list is checked. */ - for (sgr_rewind (), sgrp = sgr_next (); + for (sgr_rewind(), sgrp = sgr_next(); NULL != sgrp; - sgrp = sgr_next ()) { + sgrp = sgr_next()) { bool was_member, was_admin; /* * See if the user specified this group as one of their * concurrent groups. */ - was_member = is_on_list (sgrp->sg_mem, user_name); - was_admin = is_on_list (sgrp->sg_adm, user_name); + was_member = is_on_list(sgrp->sg_mem, user_name); + was_admin = is_on_list(sgrp->sg_adm, user_name); if (!was_member && !was_admin) { continue; } - nsgrp = __sgr_dup (sgrp); + nsgrp = __sgr_dup(sgrp); if (NULL == nsgrp) { - fprintf (stderr, + fprintf(stderr, _("%s: Out of memory. Cannot update %s.\n"), - Prog, sgr_dbname ()); + Prog, sgr_dbname()); exit (13); /* XXX */ } @@ -294,12 +294,12 @@ static void update_groups (bool process_selinux) * + it has no other members * + it is not the primary group of any other user */ -static void remove_usergroup (bool process_selinux) +static void remove_usergroup(bool process_selinux) { const struct group *grp; const struct passwd *pwd = NULL; - grp = gr_locate (user_name); + grp = gr_locate(user_name); if (NULL == grp) { /* This user has no usergroup. */ return; @@ -314,7 +314,7 @@ static void remove_usergroup (bool process_selinux) if (NULL != grp->gr_mem[0]) { /* The usergroup has other members. */ - fprintf (stderr, + fprintf(stderr, _("%s: group %s not removed because it has other members.\n"), Prog, grp->gr_name); return; @@ -325,19 +325,19 @@ static void remove_usergroup (bool process_selinux) * Scan the passwd file to check if this group is still * used as a primary group. */ - prefix_setpwent (); + prefix_setpwent(); while (NULL != (pwd = prefix_getpwent())) { if (streq(pwd->pw_name, user_name)) { continue; } if (pwd->pw_gid == grp->gr_gid) { - fprintf (stderr, + fprintf(stderr, _("%s: group %s is the primary group of another user and is not removed.\n"), Prog, grp->gr_name); break; } } - prefix_endpwent (); + prefix_endpwent(); } if (NULL == pwd) { @@ -345,15 +345,15 @@ static void remove_usergroup (bool process_selinux) * We can remove this group, it is not the primary * group of any remaining user. */ - if (gr_remove (user_name) == 0) { - fprintf (stderr, + if (gr_remove(user_name) == 0) { + fprintf(stderr, _("%s: cannot remove entry '%s' from %s\n"), - Prog, user_name, gr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + Prog, user_name, gr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_DEL_GROUP, + audit_logger_with_group(AUDIT_DEL_GROUP, "delete-group", user_name, AUDIT_NO_ID, "grp", user_name, SHADOW_AUDIT_SUCCESS); @@ -362,15 +362,15 @@ static void remove_usergroup (bool process_selinux) user_name, user_name); #ifdef SHADOWGRP - if (sgr_locate (user_name) != NULL) { - if (sgr_remove (user_name) == 0) { - fprintf (stderr, + if (sgr_locate(user_name) != NULL) { + if (sgr_remove(user_name) == 0) { + fprintf(stderr, _("%s: cannot remove entry '%s' from %s\n"), - Prog, user_name, sgr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + Prog, user_name, sgr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_GRP_MGMT, + audit_logger_with_group(AUDIT_GRP_MGMT, "delete-shadow-group", user_name, AUDIT_NO_ID, "grp", user_name, SHADOW_AUDIT_SUCCESS); @@ -395,13 +395,13 @@ static void close_files(const struct option_flags *flags) process_selinux = !flags->chroot && !flags->prefix; - if (pw_close (process_selinux) == 0) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); + if (pw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", pw_dbname()); - fail_exit (E_PW_UPDATE, process_selinux); + fail_exit(E_PW_UPDATE, process_selinux); } - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -422,13 +422,13 @@ static void close_files(const struct option_flags *flags) spw_locked = false; } - if (gr_close (process_selinux) == 0) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); + if (gr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", gr_dbname()); - fail_exit (E_GRP_UPDATE, process_selinux); + fail_exit(E_GRP_UPDATE, process_selinux); } - if (gr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + if (gr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", gr_dbname()); /* continue */ } @@ -454,13 +454,13 @@ static void close_files(const struct option_flags *flags) #ifdef ENABLE_SUBIDS if (is_sub_uid) { - if (sub_uid_close (process_selinux) == 0) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sub_uid_dbname ()); + if (sub_uid_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, sub_uid_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", sub_uid_dbname()); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } - if (sub_uid_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname ()); + if (sub_uid_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sub_uid_dbname()); /* continue */ } @@ -486,11 +486,11 @@ static void close_files(const struct option_flags *flags) /* * fail_exit - exit with a failure code after unlocking the files */ -static void fail_exit (int code, bool process_selinux) +static void fail_exit(int code, bool process_selinux) { if (pw_locked) { - if (pw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + if (pw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", pw_dbname()); /* continue */ } @@ -503,8 +503,8 @@ static void fail_exit (int code, bool process_selinux) } } if (spw_locked) { - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); /* continue */ } @@ -520,8 +520,8 @@ static void fail_exit (int code, bool process_selinux) #endif /* SHADOWGRP */ #ifdef ENABLE_SUBIDS if (sub_uid_locked) { - if (sub_uid_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname ()); + if (sub_uid_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sub_uid_dbname()); /* continue */ } @@ -536,12 +536,12 @@ static void fail_exit (int code, bool process_selinux) #endif /* ENABLE_SUBIDS */ #ifdef WITH_AUDIT - audit_logger (AUDIT_DEL_USER, + audit_logger(AUDIT_DEL_USER, "delete-user", user_name, user_id, SHADOW_AUDIT_FAILURE); #endif /* WITH_AUDIT */ - exit (code); + exit(code); } /* @@ -550,89 +550,89 @@ static void fail_exit (int code, bool process_selinux) * open_files() opens the two password files. */ -static void open_files (bool process_selinux) +static void open_files(bool process_selinux) { - if (pw_lock () == 0) { - fprintf (stderr, + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, pw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } pw_locked = true; - if (pw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, - _("%s: cannot open %s\n"), Prog, pw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + if (pw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, + _("%s: cannot open %s\n"), Prog, pw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } if (is_shadow_pwd) { - if (spw_lock () == 0) { - fprintf (stderr, + if (spw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, spw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, spw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } spw_locked = true; - if (spw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (spw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, spw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, spw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } } - if (gr_lock () == 0) { - fprintf (stderr, + if (gr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, gr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + Prog, gr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } gr_locked = true; - if (gr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + if (gr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), Prog, gr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } #ifdef SHADOWGRP if (is_shadow_grp) { - if (sgr_lock () == 0) { - fprintf (stderr, + if (sgr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sgr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + Prog, sgr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } sgr_locked= true; - if (sgr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), - Prog, sgr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + if (sgr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), + Prog, sgr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } } #endif /* SHADOWGRP */ #ifdef ENABLE_SUBIDS if (is_sub_uid) { - if (sub_uid_lock () == 0) { - fprintf (stderr, + if (sub_uid_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sub_uid_dbname ()); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + Prog, sub_uid_dbname()); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } sub_uid_locked = true; - if (sub_uid_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, - _("%s: cannot open %s\n"), Prog, sub_uid_dbname ()); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + if (sub_uid_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, + _("%s: cannot open %s\n"), Prog, sub_uid_dbname()); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } } if (is_sub_gid) { - if (sub_gid_lock () == 0) { - fprintf (stderr, + if (sub_gid_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sub_gid_dbname ()); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + Prog, sub_gid_dbname()); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } sub_gid_locked = true; - if (sub_gid_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, - _("%s: cannot open %s\n"), Prog, sub_gid_dbname ()); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + if (sub_gid_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, + _("%s: cannot open %s\n"), Prog, sub_gid_dbname()); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } } #endif /* ENABLE_SUBIDS */ @@ -644,38 +644,38 @@ static void open_files (bool process_selinux) * update_user() deletes the password file entries for this user * and will update the group entries as required. */ -static void update_user (bool process_selinux) +static void update_user(bool process_selinux) { - if (pw_remove (user_name) == 0) { - fprintf (stderr, + if (pw_remove(user_name) == 0) { + fprintf(stderr, _("%s: cannot remove entry '%s' from %s\n"), - Prog, user_name, pw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, user_name, pw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } if ( is_shadow_pwd - && (spw_locate (user_name) != NULL) - && (spw_remove (user_name) == 0)) { - fprintf (stderr, + && (spw_locate(user_name) != NULL) + && (spw_remove(user_name) == 0)) { + fprintf(stderr, _("%s: cannot remove entry '%s' from %s\n"), - Prog, user_name, spw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, user_name, spw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } #ifdef ENABLE_SUBIDS if (is_sub_uid && sub_uid_remove(user_name, 0, ULONG_MAX) == 0) { - fprintf (stderr, + fprintf(stderr, _("%s: cannot remove entry %lu from %s\n"), - Prog, (unsigned long)user_id, sub_uid_dbname ()); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + Prog, (unsigned long)user_id, sub_uid_dbname()); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } if (is_sub_gid && sub_gid_remove(user_name, 0, ULONG_MAX) == 0) { - fprintf (stderr, + fprintf(stderr, _("%s: cannot remove entry %lu from %s\n"), - Prog, (unsigned long)user_id, sub_gid_dbname ()); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + Prog, (unsigned long)user_id, sub_gid_dbname()); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } #endif /* ENABLE_SUBIDS */ #ifdef WITH_AUDIT - audit_logger (AUDIT_DEL_USER, + audit_logger(AUDIT_DEL_USER, "delete-user", user_name, user_id, SHADOW_AUDIT_SUCCESS); #endif /* WITH_AUDIT */ @@ -689,28 +689,28 @@ static void update_user (bool process_selinux) * cron, at, or print jobs. */ -static void user_cancel (const char *user) +static void user_cancel(const char *user) { const char *cmd; const char *argv[3]; int status; - cmd = getdef_str ("USERDEL_CMD"); + cmd = getdef_str("USERDEL_CMD"); if (NULL == cmd) { return; } argv[0] = cmd; argv[1] = user; argv[2] = NULL; - (void) run_command (cmd, argv, NULL, &status); + (void) run_command(cmd, argv, NULL, &status); } #ifdef EXTRA_CHECK_HOME_DIR -static bool path_prefix (const char *s1, const char *s2) +static bool path_prefix(const char *s1, const char *s2) { return ( strprefix(s2, s1) - && ( ('\0' == s2[strlen (s1)]) - || ('/' == s2[strlen (s1)]))); + && ( ('\0' == s2[strlen(s1)]) + || ('/' == s2[strlen(s1)]))); } #endif /* EXTRA_CHECK_HOME_DIR */ @@ -722,12 +722,12 @@ static bool path_prefix (const char *s1, const char *s2) * 0: path is not owned by uid, or a failure occurred * -1: path does not exist */ -static int is_owner (uid_t uid, const char *path) +static int is_owner(uid_t uid, const char *path) { struct stat st; errno = 0; - if (stat (path, &st) != 0) { + if (stat(path, &st) != 0) { if ((ENOENT == errno) || (ENOTDIR == errno)) { /* The file or directory does not exist */ return -1; @@ -800,7 +800,7 @@ static bool remove_mailbox (void) #ifdef WITH_AUDIT else { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "delete-mail-file", user_name, user_id, SHADOW_AUDIT_SUCCESS); } @@ -808,14 +808,14 @@ static bool remove_mailbox (void) free(mailfile); return errors; } - i = is_owner (user_id, mailfile); + i = is_owner(user_id, mailfile); if (i == 0) { - fprintf (stderr, + fprintf(stderr, _("%s: %s not owned by %s, not removing\n"), Prog, mailfile, user_name); SYSLOG(LOG_ERR, "%s not owned by %s, not removed", mailfile, user_name); #ifdef WITH_AUDIT - audit_logger (AUDIT_DEL_USER, + audit_logger(AUDIT_DEL_USER, "delete-mail-file", user_name, user_id, SHADOW_AUDIT_FAILURE); #endif /* WITH_AUDIT */ @@ -841,7 +841,7 @@ static bool remove_mailbox (void) #ifdef WITH_AUDIT else { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "delete-mail-file", user_name, user_id, SHADOW_AUDIT_SUCCESS); } @@ -851,12 +851,12 @@ static bool remove_mailbox (void) } #ifdef WITH_TCB -static int remove_tcbdir (const char *user_name, uid_t user_id) +static int remove_tcbdir(const char *user_name, uid_t user_id) { int ret = 0; char *buf; - if (!getdef_bool ("USE_TCB")) { + if (!getdef_bool("USE_TCB")) { return 0; } @@ -867,27 +867,27 @@ static int remove_tcbdir (const char *user_name, uid_t user_id) Prog, user_name); return 1; } - if (shadowtcb_drop_priv () == SHADOWTCB_FAILURE) { - fprintf (stderr, _("%s: Cannot drop privileges: %s\n"), + if (shadowtcb_drop_priv() == SHADOWTCB_FAILURE) { + fprintf(stderr, _("%s: Cannot drop privileges: %s\n"), Prog, strerrno()); - shadowtcb_gain_priv (); - free (buf); + shadowtcb_gain_priv(); + free(buf); return 1; } /* Only remove directory contents with dropped privileges. * We will regain them and remove the user's tcb directory afterwards. */ - if (remove_tree (buf, false) != 0) { - fprintf (stderr, _("%s: Cannot remove the content of %s: %s\n"), + if (remove_tree(buf, false) != 0) { + fprintf(stderr, _("%s: Cannot remove the content of %s: %s\n"), Prog, buf, strerrno()); - shadowtcb_gain_priv (); - free (buf); + shadowtcb_gain_priv(); + free(buf); return 1; } - shadowtcb_gain_priv (); - free (buf); - if (shadowtcb_remove (user_name) == SHADOWTCB_FAILURE) { - fprintf (stderr, _("%s: Cannot remove tcb files for %s: %s\n"), + shadowtcb_gain_priv(); + free(buf); + if (shadowtcb_remove(user_name) == SHADOWTCB_FAILURE) { + fprintf(stderr, _("%s: Cannot remove tcb files for %s: %s\n"), Prog, user_name, strerrno()); ret = 1; } @@ -898,7 +898,7 @@ static int remove_tcbdir (const char *user_name, uid_t user_id) /* * main - userdel command */ -int main (int argc, char **argv) +int main(int argc, char **argv) { bool errors = false; /* Error in the removal of the home directory */ @@ -935,7 +935,7 @@ int main (int argc, char **argv) #endif /* WITH_SELINUX */ {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, + while ((c = getopt_long(argc, argv, #ifdef WITH_SELINUX "fhrR:P:Z", #else /* !WITH_SELINUX */ @@ -961,36 +961,36 @@ int main (int argc, char **argv) #ifdef WITH_SELINUX case 'Z': if (prefix[0]) { - fprintf (stderr, + fprintf(stderr, _("%s: -Z cannot be used with --prefix\n"), Prog); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } - if (is_selinux_enabled () > 0) { + if (is_selinux_enabled() > 0) { Zflg = true; } else { - fprintf (stderr, + fprintf(stderr, _("%s: -Z requires SELinux enabled kernel\n"), Prog); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } break; #endif /* WITH_SELINUX */ default: - usage (E_USAGE); + usage(E_USAGE); } } } process_selinux = !flags.chroot && !flags.prefix; if ((optind + 1) != argc) { - usage (E_USAGE); + usage(E_USAGE); } - is_shadow_pwd = spw_file_present (); + is_shadow_pwd = spw_file_present(); #ifdef SHADOWGRP - is_shadow_grp = sgr_file_present (); + is_shadow_grp = sgr_file_present(); #endif /* SHADOWGRP */ #ifdef ENABLE_SUBIDS is_sub_uid = want_subuid_file() && sub_uid_file_present(); @@ -1004,7 +1004,7 @@ int main (int argc, char **argv) { const struct passwd *pwd; - if (run_parts ("/etc/shadow-maint/userdel-pre.d", user_name, + if (run_parts("/etc/shadow-maint/userdel-pre.d", user_name, "userdel")) { exit(1); } @@ -1045,12 +1045,12 @@ int main (int argc, char **argv) if (streq(prefix, "") && !flags.chroot && user_busy(user_name, user_id) != 0) { if (!fflg) { #ifdef WITH_AUDIT - audit_logger (AUDIT_DEL_USER, + audit_logger(AUDIT_DEL_USER, "deleting-user-logged-in", user_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); #endif /* WITH_AUDIT */ - exit (E_USER_BUSY); + exit(E_USER_BUSY); } } @@ -1058,24 +1058,24 @@ int main (int argc, char **argv) * Do the hard stuff - open the files, create the user entries, * create the home directory, then close and update the files. */ - open_files (process_selinux); - update_user (process_selinux); - update_groups (process_selinux); + open_files(process_selinux); + update_user(process_selinux); + update_groups(process_selinux); if (rflg) { - if (remove_mailbox ()) { + if (remove_mailbox()) { errors = true; } } if (rflg) { - int home_owned = is_owner (user_id, user_home); + int home_owned = is_owner(user_id, user_home); if (-1 == home_owned) { - fprintf (stderr, - _("%s: %s home directory (%s) not found\n"), + fprintf(stderr, + _("%s: %s home directory(%s) not found\n"), Prog, user_name, user_home); rflg = 0; } else if ((0 == home_owned) && !fflg) { - fprintf (stderr, + fprintf(stderr, _("%s: %s not owned by %s, not removing\n"), Prog, user_home, user_name); rflg = 0; @@ -1095,14 +1095,14 @@ int main (int argc, char **argv) * prevent accidents if someone has /home or / as home * directory... --marekm */ - prefix_setpwent (); - while ((pwd = prefix_getpwent ())) { + prefix_setpwent(); + while ((pwd = prefix_getpwent())) { if (streq(pwd->pw_name, user_name)) { continue; } - if (path_prefix (user_home, pwd->pw_dir)) { - fprintf (stderr, - _("%s: not removing directory %s (would remove home of user %s)\n"), + if (path_prefix(user_home, pwd->pw_dir)) { + fprintf(stderr, + _("%s: not removing directory %s(would remove home of user %s)\n"), Prog, user_home, pwd->pw_name); rflg = false; errors = true; @@ -1122,8 +1122,8 @@ int main (int argc, char **argv) /* continue */ } else if (is_subvolume > 0) { - if (btrfs_remove_subvolume (user_home)) { - fprintf (stderr, + if (btrfs_remove_subvolume(user_home)) { + fprintf(stderr, _("%s: error removing subvolume %s\n"), Prog, user_home); errors = true; @@ -1142,7 +1142,7 @@ int main (int argc, char **argv) #ifdef WITH_AUDIT else { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "deleting-home-directory", user_name, user_id, SHADOW_AUDIT_SUCCESS); } @@ -1150,7 +1150,7 @@ int main (int argc, char **argv) } #ifdef WITH_AUDIT if (errors) { - audit_logger (AUDIT_DEL_USER, + audit_logger(AUDIT_DEL_USER, "deleting-home-directory", user_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); @@ -1159,16 +1159,16 @@ int main (int argc, char **argv) #ifdef WITH_SELINUX if (Zflg) { - if (del_seuser (user_name) != 0) { - fprintf (stderr, + if (del_seuser(user_name) != 0) { + fprintf(stderr, _("%s: warning: the user name %s to SELinux user mapping removal failed.\n"), Prog, user_name); #ifdef WITH_AUDIT - audit_logger (AUDIT_ROLE_REMOVE, + audit_logger(AUDIT_ROLE_REMOVE, "delete-selinux-user-mapping", user_name, user_id, SHADOW_AUDIT_FAILURE); #endif /* WITH_AUDIT */ - fail_exit (E_SE_UPDATE, process_selinux); + fail_exit(E_SE_UPDATE, process_selinux); } } #endif /* WITH_SELINUX */ @@ -1178,22 +1178,22 @@ int main (int argc, char **argv) * the entry from /etc/passwd. */ if (streq(prefix, "")) - user_cancel (user_name); - close_files (&flags); + user_cancel(user_name); + close_files(&flags); - if (run_parts ("/etc/shadow-maint/userdel-post.d", user_name, "userdel")) { + if (run_parts("/etc/shadow-maint/userdel-post.d", user_name, "userdel")) { exit(1); } #ifdef WITH_TCB - if (remove_tcbdir (user_name, user_id)) { + if (remove_tcbdir(user_name, user_id)) { errors = true; } #endif /* WITH_TCB */ - nscd_flush_cache ("passwd"); - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP); + nscd_flush_cache("passwd"); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_PASSWD | SSSD_DB_GROUP); return (errors ? E_HOMEDIR : E_SUCCESS); } diff --git a/src/usermod.c b/src/usermod.c index ba01186227..2c1634290a 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -196,11 +196,11 @@ static bool sub_gid_locked = false; /* local function prototypes */ -static int get_groups (char *); -NORETURN static void usage (int status); -static void new_pwent (struct passwd *, bool); -static void new_spent (struct spwd *, bool); -NORETURN static void fail_exit (int, bool); +static int get_groups(char *); +NORETURN static void usage(int status); +static void new_pwent(struct passwd *, bool); +static void new_spent(struct spwd *, bool); +NORETURN static void fail_exit(int, bool); static void update_group_file(bool); static void update_group(const struct group *grp, bool process_selinux); @@ -208,20 +208,20 @@ static void update_group(const struct group *grp, bool process_selinux); static void update_gshadow_file(bool process_selinux); static void update_gshadow(const struct sgrp *sgrp, bool process_selinux); #endif -static void grp_update (bool process_selinux); +static void grp_update(bool process_selinux); -static void process_flags (int, char **, struct option_flags *); +static void process_flags(int, char **, struct option_flags *); static void close_files(const struct option_flags *); -static void open_files (bool process_selinux); +static void open_files(bool process_selinux); static void usr_update(const struct option_flags *flags); -static void move_home (bool process_selinux); +static void move_home(bool process_selinux); #ifdef ENABLE_LASTLOG -static void update_lastlog (void); +static void update_lastlog(void); #endif /* ENABLE_LASTLOG */ -static void update_faillog (void); +static void update_faillog(void); #ifndef NO_MOVE_MAILBOX -static void move_mailbox (void); +static void move_mailbox(void); #endif extern int allow_bad_names; @@ -233,7 +233,7 @@ extern int allow_bad_names; * converts it to a NULL-terminated array. Any unknown group names are * reported as errors. */ -static int get_groups (char *list) +static int get_groups(char *list) { struct group *grp; bool errors = false; @@ -272,7 +272,7 @@ static int get_groups (char *list) * string name. */ if (NULL == grp) { - fprintf (stderr, _("%s: group '%s' does not exist\n"), + fprintf(stderr, _("%s: group '%s' does not exist\n"), Prog, g); errors = true; } @@ -286,18 +286,18 @@ static int get_groups (char *list) } if (ngroups == sys_ngroups) { - fprintf (stderr, - _("%s: too many groups specified (max %zu).\n"), + fprintf(stderr, + _("%s: too many groups specified(max %zu).\n"), Prog, ngroups); - gr_free (grp); + gr_free(grp); break; } /* * Add the group name to the user's list of groups. */ - user_groups[ngroups++] = xstrdup (grp->gr_name); - gr_free (grp); + user_groups[ngroups++] = xstrdup(grp->gr_name); + gr_free(grp); } user_groups[ngroups] = NULL; @@ -372,7 +372,7 @@ prepend_range(const char *str, struct id_range_list_entry **head) entry = malloc_T(1, struct id_range_list_entry); if (!entry) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to allocate memory: %s\n"), Prog, strerrno()); return 0; @@ -385,7 +385,7 @@ prepend_range(const char *str, struct id_range_list_entry **head) static int find_range(struct id_range_list_entry **head, - int (*find_fn)(id_t *range_start, unsigned long *range_count)) + int(*find_fn)(id_t *range_start, unsigned long *range_count)) { struct id_range_list_entry *entry; struct id_range range; @@ -415,32 +415,32 @@ find_range(struct id_range_list_entry **head, */ NORETURN static void -usage (int status) +usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options] LOGIN\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -a, --append append the user to the supplemental GROUPS\n" + (void) fputs(_(" -a, --append append the user to the supplemental GROUPS\n" " mentioned by the -G option without removing\n" " the user from other groups\n"), usageout); - (void) fputs (_(" -b, --badname allow bad names\n"), usageout); - (void) fputs (_(" -c, --comment COMMENT new value of the GECOS field\n"), usageout); - (void) fputs (_(" -d, --home HOME_DIR new home directory for the user account\n"), usageout); - (void) fputs (_(" -e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"), usageout); - (void) fputs (_(" -f, --inactive INACTIVE set password inactive after expiration\n" + (void) fputs(_(" -b, --badname allow bad names\n"), usageout); + (void) fputs(_(" -c, --comment COMMENT new value of the GECOS field\n"), usageout); + (void) fputs(_(" -d, --home HOME_DIR new home directory for the user account\n"), usageout); + (void) fputs(_(" -e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"), usageout); + (void) fputs(_(" -f, --inactive INACTIVE set password inactive after expiration\n" " to INACTIVE\n"), usageout); - (void) fputs (_(" -g, --gid GROUP force use GROUP as new primary group\n"), usageout); - (void) fputs (_(" -G, --groups GROUPS new list of supplementary GROUPS\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -l, --login NEW_LOGIN new value of the login name\n"), usageout); - (void) fputs (_(" -L, --lock lock the user account\n"), usageout); - (void) fputs (_(" -m, --move-home move contents of the home directory to the\n" - " new location (use only with -d)\n"), usageout); - (void) fputs (_(" -o, --non-unique allow using duplicate (non-unique) UID\n"), usageout); - (void) fputs (_(" -p, --password PASSWORD use encrypted password for the new password\n"), usageout); + (void) fputs(_(" -g, --gid GROUP force use GROUP as new primary group\n"), usageout); + (void) fputs(_(" -G, --groups GROUPS new list of supplementary GROUPS\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -l, --login NEW_LOGIN new value of the login name\n"), usageout); + (void) fputs(_(" -L, --lock lock the user account\n"), usageout); + (void) fputs(_(" -m, --move-home move contents of the home directory to the\n" + " new location(use only with -d)\n"), usageout); + (void) fputs(_(" -o, --non-unique allow using duplicate(non-unique) UID\n"), usageout); + (void) fputs(_(" -p, --password PASSWORD use encrypted password for the new password\n"), usageout); (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout); (void) fputs (_(" -r, --remove remove the user from only the supplemental GROUPS\n" " mentioned by the -G option without removing\n" @@ -473,14 +473,14 @@ new_pw_passwd(char *pw_pass, bool process_selinux) { if (Lflg && ('!' != pw_pass[0])) { #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_CHAUTHTOK, + audit_logger(AUDIT_USER_CHAUTHTOK, "updating-passwd", user_newname, user_newid, 1); #endif SYSLOG(LOG_INFO, "lock user '%s' password", user_newname); pw_pass = xaprintf("!%s", pw_pass); } else if (Uflg && strprefix(pw_pass, "!")) { if (pw_pass[1] == '\0') { - fprintf (stderr, + fprintf(stderr, _("%s: unlocking the user's password would result in a passwordless account.\n" "You should set a password with usermod -p to unlock this user's password.\n"), Prog); @@ -488,18 +488,18 @@ new_pw_passwd(char *pw_pass, bool process_selinux) } #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_CHAUTHTOK, + audit_logger(AUDIT_USER_CHAUTHTOK, "updating-password", user_newname, user_newid, 1); #endif SYSLOG(LOG_INFO, "unlock user '%s' password", user_newname); memmove(pw_pass, pw_pass + 1, strlen(pw_pass)); } else if (pflg) { #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_CHAUTHTOK, + audit_logger(AUDIT_USER_CHAUTHTOK, "updating-password", user_newname, user_newid, 1); #endif SYSLOG(LOG_INFO, "change user '%s' password", user_newname); - pw_pass = xstrdup (user_pass); + pw_pass = xstrdup(user_pass); } return pw_pass; } @@ -510,26 +510,26 @@ new_pw_passwd(char *pw_pass, bool process_selinux) * new_pwent() takes all of the values that have been entered and fills * in a (struct passwd) with them. */ -static void new_pwent (struct passwd *pwent, bool process_selinux) +static void new_pwent(struct passwd *pwent, bool process_selinux) { if (lflg) { - if (pw_locate (user_newname) != NULL) { + if (pw_locate(user_newname) != NULL) { /* This should never happen. * It was already checked that the user doesn't * exist on the system. */ - fprintf (stderr, + fprintf(stderr, _("%s: user '%s' already exists in %s\n"), - Prog, user_newname, pw_dbname ()); - fail_exit (E_NAME_IN_USE, process_selinux); + Prog, user_newname, pw_dbname()); + fail_exit(E_NAME_IN_USE, process_selinux); } #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "changing-name", user_newname, user_newid, 1); #endif SYSLOG(LOG_INFO, "change user name '%s' to '%s'", pwent->pw_name, user_newname); - pwent->pw_name = xstrdup (user_newname); + pwent->pw_name = xstrdup(user_newname); } /* Update the password in passwd if there is no shadow file or if * the password is currently in passwd (pw_passwd != "x"). @@ -543,7 +543,7 @@ static void new_pwent (struct passwd *pwent, bool process_selinux) if (uflg) { #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "changing-uid", user_newname, user_newid, 1); #endif SYSLOG(LOG_INFO, "change user '%s' UID from '%d' to '%d'", @@ -552,7 +552,7 @@ static void new_pwent (struct passwd *pwent, bool process_selinux) } if (gflg) { #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "changing-primary-group", user_newname, user_newid, 1); #endif @@ -562,7 +562,7 @@ static void new_pwent (struct passwd *pwent, bool process_selinux) } if (cflg) { #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "changing-comment", user_newname, user_newid, 1); #endif pwent->pw_gecos = user_newcomment; @@ -570,7 +570,7 @@ static void new_pwent (struct passwd *pwent, bool process_selinux) if (dflg) { #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "changing-home-dir", user_newname, user_newid, 1); #endif @@ -584,7 +584,7 @@ static void new_pwent (struct passwd *pwent, bool process_selinux) } if (sflg) { #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "changing-shell", user_newname, user_newid, 1); #endif @@ -600,21 +600,21 @@ static void new_pwent (struct passwd *pwent, bool process_selinux) * new_spent() takes all of the values that have been entered and fills * in a (struct spwd) with them. */ -static void new_spent (struct spwd *spent, bool process_selinux) +static void new_spent(struct spwd *spent, bool process_selinux) { if (lflg) { - if (spw_locate (user_newname) != NULL) { - fprintf (stderr, + if (spw_locate(user_newname) != NULL) { + fprintf(stderr, _("%s: user '%s' already exists in %s\n"), - Prog, user_newname, spw_dbname ()); - fail_exit (E_NAME_IN_USE, process_selinux); + Prog, user_newname, spw_dbname()); + fail_exit(E_NAME_IN_USE, process_selinux); } - spent->sp_namp = xstrdup (user_newname); + spent->sp_namp = xstrdup(user_newname); } if (fflg) { #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "changing-inactive-days", user_newname, user_newid, 1); #endif @@ -650,7 +650,7 @@ static void new_spent (struct spwd *spent, bool process_selinux) spent->sp_pwdp = new_pw_passwd(spent->sp_pwdp, process_selinux); if (pflg) { - spent->sp_lstchg = gettime () / DAY; + spent->sp_lstchg = gettime() / DAY; if (0 == spent->sp_lstchg) { /* Better disable aging than requiring a password * change. */ @@ -664,12 +664,12 @@ static void new_spent (struct spwd *spent, bool process_selinux) */ NORETURN static void -fail_exit (int code, bool process_selinux) +fail_exit(int code, bool process_selinux) { #ifdef ENABLE_SUBIDS if (sub_gid_locked) { - if (sub_gid_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_gid_dbname ()); + if (sub_gid_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sub_gid_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sub_gid_dbname()); /* continue */ } @@ -684,8 +684,8 @@ fail_exit (int code, bool process_selinux) #endif /* ENABLE_SUBIDS */ #ifdef SHADOWGRP if (sgr_locked) { - if (sgr_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + if (sgr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sgr_dbname()); /* continue */ } @@ -699,8 +699,8 @@ fail_exit (int code, bool process_selinux) } } if (spw_locked) { - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); /* continue */ } @@ -714,11 +714,11 @@ fail_exit (int code, bool process_selinux) } #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "modify-account", user_name, AUDIT_NO_ID, SHADOW_AUDIT_FAILURE); #endif - exit (code); + exit(code); } @@ -750,9 +750,9 @@ update_group(const struct group *grp, bool process_selinux) * See if the user specified this group as one of their * concurrent groups. */ - was_member = is_on_list (grp->gr_mem, user_name); + was_member = is_on_list(grp->gr_mem, user_name); is_member = Gflg && ( (was_member && aflg) - || is_on_list (user_groups, grp->gr_name)); + || is_on_list(user_groups, grp->gr_name)); if (!was_member && !is_member) return; @@ -765,12 +765,12 @@ update_group(const struct group *grp, bool process_selinux) is_member = !is_member; } - ngrp = __gr_dup (grp); + ngrp = __gr_dup(grp); if (NULL == ngrp) { - fprintf (stderr, + fprintf(stderr, _("%s: Out of memory. Cannot update %s.\n"), - Prog, gr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + Prog, gr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } if (was_member) { @@ -780,13 +780,13 @@ update_group(const struct group *grp, bool process_selinux) * But the user might have been renamed. */ if (lflg) { - ngrp->gr_mem = del_list (ngrp->gr_mem, + ngrp->gr_mem = del_list(ngrp->gr_mem, user_name); - ngrp->gr_mem = add_list (ngrp->gr_mem, + ngrp->gr_mem = add_list(ngrp->gr_mem, user_newname); changed = true; #ifdef WITH_AUDIT - audit_logger_with_group ( + audit_logger_with_group( AUDIT_USER_MGMT, "update-member-in-group", user_newname, AUDIT_NO_ID, "grp", @@ -802,10 +802,10 @@ update_group(const struct group *grp, bool process_selinux) /* User was a member but is no more a * member of this group. */ - ngrp->gr_mem = del_list (ngrp->gr_mem, user_name); + ngrp->gr_mem = del_list(ngrp->gr_mem, user_name); changed = true; #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "delete-user-from-group", user_name, AUDIT_NO_ID, "grp", ngrp->gr_name, @@ -818,10 +818,10 @@ update_group(const struct group *grp, bool process_selinux) /* User was not a member but is now a member this * group. */ - ngrp->gr_mem = add_list (ngrp->gr_mem, user_newname); + ngrp->gr_mem = add_list(ngrp->gr_mem, user_newname); changed = true; #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "add-user-to-group", user_name, AUDIT_NO_ID, "grp", ngrp->gr_name, @@ -833,12 +833,12 @@ update_group(const struct group *grp, bool process_selinux) if (!changed) goto free_ngrp; - if (gr_update (ngrp) == 0) { - fprintf (stderr, + if (gr_update(ngrp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, gr_dbname (), ngrp->gr_name); + Prog, gr_dbname(), ngrp->gr_name); SYSLOG(LOG_WARN, "failed to prepare the new %s entry '%s'", gr_dbname(), ngrp->gr_name); - fail_exit (E_GRP_UPDATE, process_selinux); + fail_exit(E_GRP_UPDATE, process_selinux); } free_ngrp: @@ -877,19 +877,19 @@ update_gshadow(const struct sgrp *sgrp, bool process_selinux) /* * See if the user was a member of this group */ - was_member = is_on_list (sgrp->sg_mem, user_name); + was_member = is_on_list(sgrp->sg_mem, user_name); /* * See if the user was an administrator of this group */ - was_admin = is_on_list (sgrp->sg_adm, user_name); + was_admin = is_on_list(sgrp->sg_adm, user_name); /* * See if the user specified this group as one of their * concurrent groups. */ is_member = Gflg && ( (was_member && aflg) - || is_on_list (user_groups, sgrp->sg_namp)); + || is_on_list(user_groups, sgrp->sg_namp)); if (!was_member && !was_admin && !is_member) return; @@ -902,23 +902,23 @@ update_gshadow(const struct sgrp *sgrp, bool process_selinux) is_member = !is_member; } - nsgrp = __sgr_dup (sgrp); + nsgrp = __sgr_dup(sgrp); if (NULL == nsgrp) { - fprintf (stderr, + fprintf(stderr, _("%s: Out of memory. Cannot update %s.\n"), - Prog, sgr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + Prog, sgr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } if (was_admin && lflg) { /* User was an admin of this group but the user * has been renamed. */ - nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name); - nsgrp->sg_adm = add_list (nsgrp->sg_adm, user_newname); + nsgrp->sg_adm = del_list(nsgrp->sg_adm, user_name); + nsgrp->sg_adm = add_list(nsgrp->sg_adm, user_newname); changed = true; #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_GRP_MGMT, + audit_logger_with_group(AUDIT_GRP_MGMT, "update-admin-name-in-shadow-group", user_name, AUDIT_NO_ID, "grp", nsgrp->sg_namp, SHADOW_AUDIT_SUCCESS); @@ -934,13 +934,13 @@ update_gshadow(const struct sgrp *sgrp, bool process_selinux) * But the user might have been renamed. */ if (lflg) { - nsgrp->sg_mem = del_list (nsgrp->sg_mem, + nsgrp->sg_mem = del_list(nsgrp->sg_mem, user_name); - nsgrp->sg_mem = add_list (nsgrp->sg_mem, + nsgrp->sg_mem = add_list(nsgrp->sg_mem, user_newname); changed = true; #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "update-member-in-shadow-group", user_name, AUDIT_NO_ID, "grp", nsgrp->sg_namp, 1); @@ -953,10 +953,10 @@ update_gshadow(const struct sgrp *sgrp, bool process_selinux) /* User was a member but is no more a * member of this group. */ - nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name); + nsgrp->sg_mem = del_list(nsgrp->sg_mem, user_name); changed = true; #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "delete-user-from-shadow-group", user_name, AUDIT_NO_ID, "grp", nsgrp->sg_namp, 1); @@ -968,10 +968,10 @@ update_gshadow(const struct sgrp *sgrp, bool process_selinux) /* User was not a member but is now a member this * group. */ - nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_newname); + nsgrp->sg_mem = add_list(nsgrp->sg_mem, user_newname); changed = true; #ifdef WITH_AUDIT - audit_logger_with_group (AUDIT_USER_MGMT, + audit_logger_with_group(AUDIT_USER_MGMT, "add-user-to-shadow-group", user_newname, AUDIT_NO_ID, "grp", nsgrp->sg_namp, 1); @@ -985,17 +985,17 @@ update_gshadow(const struct sgrp *sgrp, bool process_selinux) /* * Update the group entry to reflect the changes. */ - if (sgr_update (nsgrp) == 0) { - fprintf (stderr, + if (sgr_update(nsgrp) == 0) { + fprintf(stderr, _("%s: failed to prepare the new %s entry '%s'\n"), - Prog, sgr_dbname (), nsgrp->sg_namp); + Prog, sgr_dbname(), nsgrp->sg_namp); SYSLOG(LOG_WARN, "failed to prepare the new %s entry '%s'", sgr_dbname(), nsgrp->sg_namp); - fail_exit (E_GRP_UPDATE, process_selinux); + fail_exit(E_GRP_UPDATE, process_selinux); } free_nsgrp: - free (nsgrp); + free(nsgrp); } #endif /* SHADOWGRP */ @@ -1006,7 +1006,7 @@ update_gshadow(const struct sgrp *sgrp, bool process_selinux) * grp_update() takes the secondary group set given in user_groups and * adds the user to each group given by that set. */ -static void grp_update (bool process_selinux) +static void grp_update(bool process_selinux) { update_group_file(process_selinux); #ifdef SHADOWGRP @@ -1069,7 +1069,7 @@ process_flags(int argc, char **argv, struct option_flags *flags) #endif /* WITH_SELINUX */ {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, + while ((c = getopt_long(argc, argv, "abc:d:e:f:g:G:hl:Lmop:rR:s:u:UP:" #ifdef ENABLE_SUBIDS "v:w:V:W:S" @@ -1086,38 +1086,38 @@ process_flags(int argc, char **argv, struct option_flags *flags) allow_bad_names = true; break; case 'c': - if (!VALID (optarg)) { - fprintf (stderr, + if (!VALID(optarg)) { + fprintf(stderr, _("%s: invalid field '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } user_newcomment = optarg; cflg = true; break; case 'd': - if (!VALID (optarg)) { - fprintf (stderr, + if (!VALID(optarg)) { + fprintf(stderr, _("%s: invalid field '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } dflg = true; user_newhome = optarg; if ((user_newhome[0] != '/') && !streq(user_newhome, "")) { - fprintf (stderr, + fprintf(stderr, _("%s: homedir must be an absolute path\n"), Prog); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } break; case 'e': - user_newexpire = strtoday (optarg); + user_newexpire = strtoday(optarg); if (user_newexpire < -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid date '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } eflg = true; break; @@ -1125,10 +1125,10 @@ process_flags(int argc, char **argv, struct option_flags *flags) if (a2sl(&user_newinactive, optarg, NULL, 0, -1, LONG_MAX) == -1) { - fprintf (stderr, + fprintf(stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } fflg = true; break; @@ -1136,26 +1136,26 @@ process_flags(int argc, char **argv, struct option_flags *flags) { struct group *grp; - grp = prefix_getgr_nam_gid (optarg); + grp = prefix_getgr_nam_gid(optarg); if (NULL == grp) { - fprintf (stderr, + fprintf(stderr, _("%s: group '%s' does not exist\n"), Prog, optarg); - exit (E_NOTFOUND); + exit(E_NOTFOUND); } user_newgid = grp->gr_gid; gflg = true; - gr_free (grp); + gr_free(grp); break; } case 'G': - if (get_groups (optarg) != 0) { - exit (E_NOTFOUND); + if (get_groups(optarg) != 0) { + exit(E_NOTFOUND); } Gflg = true; break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); /*@notreached@*/break; case 'l': if (!is_valid_user_name(optarg)) { @@ -1279,19 +1279,19 @@ process_flags(int argc, char **argv, struct option_flags *flags) #ifdef WITH_SELINUX case 'Z': if (prefix[0]) { - fprintf (stderr, + fprintf(stderr, _("%s: -Z cannot be used with --prefix\n"), Prog); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } - if (is_selinux_enabled () > 0) { + if (is_selinux_enabled() > 0) { user_selinux = optarg; Zflg = true; } else { - fprintf (stderr, + fprintf(stderr, _("%s: -Z requires SELinux enabled kernel\n"), Prog); - exit (E_BAD_ARG); + exit(E_BAD_ARG); } break; case 202: @@ -1299,14 +1299,14 @@ process_flags(int argc, char **argv, struct option_flags *flags) break; #endif /* WITH_SELINUX */ default: - usage (E_USAGE); + usage(E_USAGE); } anyflag = true; } } if (optind != argc - 1) { - usage (E_USAGE); + usage(E_USAGE); } user_name = argv[argc - 1]; @@ -1466,11 +1466,11 @@ process_flags(int argc, char **argv, struct option_flags *flags) } /* local, no need for xgetpwnam */ - if (lflg && (prefix_getpwnam (user_newname) != NULL)) { - fprintf (stderr, + if (lflg && (prefix_getpwnam(user_newname) != NULL)) { + fprintf(stderr, _("%s: user '%s' already exists\n"), Prog, user_newname); - exit (E_NAME_IN_USE); + exit(E_NAME_IN_USE); } /* local, no need for xgetpwuid */ @@ -1514,13 +1514,13 @@ static void close_files(const struct option_flags *flags) #ifdef ENABLE_SUBIDS if (sub_gid_locked) { - if (sub_gid_close (process_selinux) == 0) { - fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sub_gid_dbname ()); + if (sub_gid_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), Prog, sub_gid_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", sub_gid_dbname()); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } - if (sub_gid_unlock (process_selinux) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_gid_dbname ()); + if (sub_gid_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, sub_gid_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sub_gid_dbname()); /* continue */ } @@ -1544,18 +1544,18 @@ static void close_files(const struct option_flags *flags) if (gr_locked) { #ifdef SHADOWGRP if (is_shadow_grp) { - if (sgr_close (process_selinux) == 0) { - fprintf (stderr, + if (sgr_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, sgr_dbname ()); + Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", sgr_dbname()); - fail_exit (E_GRP_UPDATE, process_selinux); + fail_exit(E_GRP_UPDATE, process_selinux); } - if (sgr_unlock (process_selinux) == 0) { - fprintf (stderr, + if (sgr_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), - Prog, sgr_dbname ()); + Prog, sgr_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", sgr_dbname()); /* continue */ } @@ -1580,17 +1580,17 @@ static void close_files(const struct option_flags *flags) gr_locked = false; } if (spw_locked) { - if (spw_close (process_selinux) == 0) { - fprintf (stderr, + if (spw_close(process_selinux) == 0) { + fprintf(stderr, _("%s: failure while writing changes to %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); SYSLOG(LOG_ERR, "failure while writing changes to %s", spw_dbname()); - fail_exit (E_PW_UPDATE, process_selinux); + fail_exit(E_PW_UPDATE, process_selinux); } - if (spw_unlock (process_selinux) == 0) { - fprintf (stderr, + if (spw_unlock(process_selinux) == 0) { + fprintf(stderr, _("%s: failed to unlock %s\n"), - Prog, spw_dbname ()); + Prog, spw_dbname()); SYSLOG(LOG_ERR, "failed to unlock %s", spw_dbname()); /* continue */ } @@ -1616,11 +1616,11 @@ static void close_files(const struct option_flags *flags) * Close the DBM and/or flat files */ #ifdef SHADOWGRP - endsgent (); + endsgent(); #endif - endgrent (); - endspent (); - endpwent (); + endgrent(); + endspent(); + endpwent(); } /* @@ -1628,34 +1628,34 @@ static void close_files(const struct option_flags *flags) * * open_files() opens the two password files. */ -static void open_files (bool process_selinux) +static void open_files(bool process_selinux) { - if (pw_lock () == 0) { - fprintf (stderr, + if (pw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, pw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, pw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } pw_locked = true; - if (pw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (pw_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, pw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, pw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } if (is_shadow_pwd && (lflg || pflg || eflg || fflg || Lflg || Uflg)) { - if (spw_lock () == 0) { - fprintf (stderr, + if (spw_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, spw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, spw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } spw_locked = true; - if (is_shadow_pwd && (spw_open (O_CREAT | O_RDWR) == 0)) { - fprintf (stderr, + if (is_shadow_pwd && (spw_open(O_CREAT | O_RDWR) == 0)) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, spw_dbname ()); - fail_exit (E_PW_UPDATE, process_selinux); + Prog, spw_dbname()); + fail_exit(E_PW_UPDATE, process_selinux); } } @@ -1664,64 +1664,64 @@ static void open_files (bool process_selinux) * Lock and open the group file. This will load all of the * group entries. */ - if (gr_lock () == 0) { - fprintf (stderr, + if (gr_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, gr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + Prog, gr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } gr_locked = true; - if (gr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (gr_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, gr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + Prog, gr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } #ifdef SHADOWGRP - if (is_shadow_grp && (sgr_lock () == 0)) { - fprintf (stderr, + if (is_shadow_grp && (sgr_lock() == 0)) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sgr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + Prog, sgr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } sgr_locked = true; - if (is_shadow_grp && (sgr_open (O_CREAT | O_RDWR) == 0)) { - fprintf (stderr, + if (is_shadow_grp && (sgr_open(O_CREAT | O_RDWR) == 0)) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, sgr_dbname ()); - fail_exit (E_GRP_UPDATE, process_selinux); + Prog, sgr_dbname()); + fail_exit(E_GRP_UPDATE, process_selinux); } #endif } #ifdef ENABLE_SUBIDS if (vflg || Vflg) { - if (sub_uid_lock () == 0) { - fprintf (stderr, + if (sub_uid_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sub_uid_dbname ()); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + Prog, sub_uid_dbname()); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } sub_uid_locked = true; - if (sub_uid_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (sub_uid_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, sub_uid_dbname ()); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + Prog, sub_uid_dbname()); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } } if (wflg || Wflg) { - if (sub_gid_lock () == 0) { - fprintf (stderr, + if (sub_gid_lock() == 0) { + fprintf(stderr, _("%s: cannot lock %s; try again later.\n"), - Prog, sub_gid_dbname ()); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + Prog, sub_gid_dbname()); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } sub_gid_locked = true; - if (sub_gid_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, + if (sub_gid_open(O_CREAT | O_RDWR) == 0) { + fprintf(stderr, _("%s: cannot open %s\n"), - Prog, sub_gid_dbname ()); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + Prog, sub_gid_dbname()); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } } #endif /* ENABLE_SUBIDS */ @@ -1746,15 +1746,15 @@ static void usr_update(const struct option_flags *flags) /* * Locate the entry in /etc/passwd, which MUST exist. */ - pwd = pw_locate (user_name); + pwd = pw_locate(user_name); if (NULL == pwd) { - fprintf (stderr, + fprintf(stderr, _("%s: user '%s' does not exist in %s\n"), - Prog, user_name, pw_dbname ()); - fail_exit (E_NOTFOUND, process_selinux); + Prog, user_name, pw_dbname()); + fail_exit(E_NOTFOUND, process_selinux); } pwent = *pwd; - new_pwent (&pwent, process_selinux); + new_pwent(&pwent, process_selinux); /* If the shadow file does not exist, it won't be created */ @@ -1763,7 +1763,7 @@ static void usr_update(const struct option_flags *flags) if (NULL != spwd) { /* Update the shadow entry if it exists */ spent = *spwd; - new_spent (&spent, process_selinux); + new_spent(&spent, process_selinux); } else if ( ( pflg && streq(pwent.pw_passwd, SHADOW_PASSWD_STRING)) || eflg || fflg) { @@ -1773,28 +1773,28 @@ static void usr_update(const struct option_flags *flags) * a shadowed password * + aging information is requested */ - bzero(&spent, sizeof(spent)); + bzero(&spent, sizeof (spent)); spent.sp_namp = user_name; /* The user explicitly asked for a shadow feature. * Enable shadowed passwords for this new account. */ - spent.sp_pwdp = xstrdup (pwent.pw_passwd); - pwent.pw_passwd = xstrdup (SHADOW_PASSWD_STRING); + spent.sp_pwdp = xstrdup(pwent.pw_passwd); + pwent.pw_passwd = xstrdup(SHADOW_PASSWD_STRING); - spent.sp_lstchg = gettime () / DAY; + spent.sp_lstchg = gettime() / DAY; if (0 == spent.sp_lstchg) { /* Better disable aging than * requiring a password change */ spent.sp_lstchg = -1; } - spent.sp_min = getdef_num ("PASS_MIN_DAYS", -1); - spent.sp_max = getdef_num ("PASS_MAX_DAYS", -1); - spent.sp_warn = getdef_num ("PASS_WARN_AGE", -1); + spent.sp_min = getdef_num("PASS_MIN_DAYS", -1); + spent.sp_max = getdef_num("PASS_MAX_DAYS", -1); + spent.sp_warn = getdef_num("PASS_WARN_AGE", -1); spent.sp_inact = -1; spent.sp_expire = -1; spent.sp_flag = SHADOW_SP_FLAG_UNSET; - new_spent (&spent, process_selinux); + new_spent(&spent, process_selinux); spwd = &spent; /* entry needs to be committed */ } } @@ -1836,57 +1836,57 @@ static void usr_update(const struct option_flags *flags) * move_home() moves the user's home directory to a new location. The * files will be copied if the directory cannot simply be renamed. */ -static void move_home (bool process_selinux) +static void move_home(bool process_selinux) { struct stat sb; - if (access (prefix_user_newhome, F_OK) == 0) { + if (access(prefix_user_newhome, F_OK) == 0) { /* * If the new home directory already exists, the user * should not use -m. */ - fprintf (stderr, + fprintf(stderr, _("%s: directory %s exists\n"), Prog, user_newhome); - fail_exit (E_HOMEDIR, process_selinux); + fail_exit(E_HOMEDIR, process_selinux); } - if (stat (prefix_user_home, &sb) == 0) { + if (stat(prefix_user_home, &sb) == 0) { /* * Don't try to move it if it is not a directory * (but /dev/null for example). --marekm */ - if (!S_ISDIR (sb.st_mode)) { - fprintf (stderr, - _("%s: The previous home directory (%s) was " + if (!S_ISDIR(sb.st_mode)) { + fprintf(stderr, + _("%s: The previous home directory(%s) was " "not a directory. It is not removed and no " "home directories are created.\n"), Prog, user_home); - fail_exit (E_HOMEDIR, process_selinux); + fail_exit(E_HOMEDIR, process_selinux); } #ifdef WITH_AUDIT if (uflg || gflg) { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "updating-home-dir-owner", user_newname, user_newid, 1); } #endif - if (rename (prefix_user_home, prefix_user_newhome) == 0) { + if (rename(prefix_user_home, prefix_user_newhome) == 0) { /* FIXME: rename above may have broken symlinks * pointing to the user's home directory * with an absolute path. */ - if (chown_tree (prefix_user_newhome, + if (chown_tree(prefix_user_newhome, user_id, uflg ? user_newid : (uid_t)-1, user_gid, gflg ? user_newgid : (gid_t)-1) != 0) { - fprintf (stderr, + fprintf(stderr, _("%s: Failed to change ownership of the home directory"), Prog); - fail_exit (E_HOMEDIR, process_selinux); + fail_exit(E_HOMEDIR, process_selinux); } #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "moving-home-dir", user_newname, user_newid, 1); #endif @@ -1894,26 +1894,26 @@ static void move_home (bool process_selinux) } else { if (EXDEV == errno) { #ifdef WITH_BTRFS - if (btrfs_is_subvolume (prefix_user_home) > 0) { - fprintf (stderr, + if (btrfs_is_subvolume(prefix_user_home) > 0) { + fprintf(stderr, _("%s: error: cannot move subvolume from %s to %s - different device\n"), Prog, prefix_user_home, prefix_user_newhome); - fail_exit (E_HOMEDIR, process_selinux); + fail_exit(E_HOMEDIR, process_selinux); } #endif - if (copy_tree (prefix_user_home, prefix_user_newhome, true, + if (copy_tree(prefix_user_home, prefix_user_newhome, true, user_id, uflg ? user_newid : (uid_t)-1, user_gid, gflg ? user_newgid : (gid_t)-1) == 0) { - if (remove_tree (prefix_user_home, true) != 0) { - fprintf (stderr, + if (remove_tree(prefix_user_home, true) != 0) { + fprintf(stderr, _("%s: warning: failed to completely remove old home directory %s"), Prog, prefix_user_home); } #ifdef WITH_AUDIT - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "moving-home-dir", user_newname, user_newid, @@ -1922,16 +1922,16 @@ static void move_home (bool process_selinux) return; } - (void) remove_tree (prefix_user_newhome, true); + (void) remove_tree(prefix_user_newhome, true); } - fprintf (stderr, + fprintf(stderr, _("%s: cannot rename directory %s to %s\n"), Prog, prefix_user_home, prefix_user_newhome); - fail_exit (E_HOMEDIR, process_selinux); + fail_exit(E_HOMEDIR, process_selinux); } } else { - fprintf (stderr, - _("%s: The previous home directory (%s) does not " + fprintf(stderr, + _("%s: The previous home directory(%s) does not " "exist or is inaccessible. Move cannot be completed.\n"), Prog, prefix_user_home); } @@ -1945,19 +1945,19 @@ static void move_home (bool process_selinux) * to just leave it be. */ #ifdef ENABLE_LASTLOG -static void update_lastlog (void) +static void update_lastlog(void) { struct lastlog ll; int fd; - off_t off_uid = (off_t) user_id * sizeof(ll); - off_t off_newuid = (off_t) user_newid * sizeof(ll); + off_t off_uid = (off_t) user_id * sizeof (ll); + off_t off_newuid = (off_t) user_newid * sizeof (ll); uid_t max_uid; if (access(_PATH_LASTLOG, F_OK) != 0) { return; } - max_uid = getdef_ulong ("LASTLOG_UID_MAX", 0xFFFFFFFFUL); + max_uid = getdef_ulong("LASTLOG_UID_MAX", 0xFFFFFFFFUL); if (user_newid > max_uid) { /* do not touch lastlog for large uids */ return; @@ -1975,10 +1975,10 @@ static void update_lastlog (void) if ( (lseek (fd, off_uid, SEEK_SET) == off_uid) && (read(fd, &ll, sizeof(ll)) == (ssize_t) sizeof(ll))) { /* Copy the old entry to its new location */ - if ( (lseek (fd, off_newuid, SEEK_SET) != off_newuid) - || (write_full(fd, &ll, sizeof(ll)) == -1) - || (fsync (fd) != 0)) { - fprintf (stderr, + if ( (lseek(fd, off_newuid, SEEK_SET) != off_newuid) + || (write_full(fd, &ll, sizeof (ll)) == -1) + || (fsync(fd) != 0)) { + fprintf(stderr, _("%s: failed to copy the lastlog entry of user %lu to user %lu: %s\n"), Prog, (unsigned long) user_id, (unsigned long) user_newid, strerrno()); } @@ -1990,19 +1990,19 @@ static void update_lastlog (void) if ( (lseek (fd, off_newuid, SEEK_SET) == off_newuid) && (read(fd, &ll, sizeof(ll)) == (ssize_t) sizeof(ll))) { /* Reset the new uid's lastlog entry */ - memzero(&ll, sizeof(ll)); - if ( (lseek (fd, off_newuid, SEEK_SET) != off_newuid) - || (write_full(fd, &ll, sizeof(ll)) == -1) - || (fsync (fd) != 0)) { - fprintf (stderr, + memzero(&ll, sizeof (ll)); + if ( (lseek(fd, off_newuid, SEEK_SET) != off_newuid) + || (write_full(fd, &ll, sizeof (ll)) == -1) + || (fsync(fd) != 0)) { + fprintf(stderr, _("%s: failed to copy the lastlog entry of user %lu to user %lu: %s\n"), Prog, (unsigned long) user_id, (unsigned long) user_newid, strerrno()); } } } - if (close (fd) != 0 && errno != EINTR) { - fprintf (stderr, + if (close(fd) != 0 && errno != EINTR) { + fprintf(stderr, _("%s: failed to copy the lastlog entry of user %ju to user %ju: %s\n"), Prog, (uintmax_t) user_id, (uintmax_t) user_newid, strerrno()); } @@ -2016,28 +2016,28 @@ static void update_lastlog (void) * left alone in case the UID was shared. It doesn't hurt anything * to just leave it be. */ -static void update_faillog (void) +static void update_faillog(void) { struct faillog fl; int fd; - off_t off_uid = (off_t) user_id * sizeof(fl); - off_t off_newuid = (off_t) user_newid * sizeof(fl); + off_t off_uid = (off_t) user_id * sizeof (fl); + off_t off_newuid = (off_t) user_newid * sizeof (fl); - if (access (FAILLOG_FILE, F_OK) != 0) { + if (access(FAILLOG_FILE, F_OK) != 0) { return; } - fd = open (FAILLOG_FILE, O_RDWR); + fd = open(FAILLOG_FILE, O_RDWR); if (-1 == fd) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to copy the faillog entry of user %lu to user %lu: %s\n"), Prog, (unsigned long) user_id, (unsigned long) user_newid, strerrno()); return; } - if ( (lseek (fd, off_uid, SEEK_SET) == off_uid) - && (read(fd, &fl, sizeof(fl)) == (ssize_t) sizeof(fl))) { + if ( (lseek(fd, off_uid, SEEK_SET) == off_uid) + && (read(fd, &fl, sizeof (fl)) == (ssize_t) sizeof (fl))) { /* Copy the old entry to its new location */ if ( (lseek (fd, off_newuid, SEEK_SET) != off_newuid) || (write_full(fd, &fl, sizeof(fl)) == -1) @@ -2054,19 +2054,19 @@ static void update_faillog (void) if ( (lseek (fd, off_newuid, SEEK_SET) == off_newuid) && (read(fd, &fl, sizeof(fl)) == (ssize_t) sizeof(fl))) { /* Reset the new uid's faillog entry */ - memzero(&fl, sizeof(fl)); - if ( (lseek (fd, off_newuid, SEEK_SET) != off_newuid) - || (write_full(fd, &fl, sizeof(fl)) == -1)) + memzero(&fl, sizeof (fl)); + if ( (lseek(fd, off_newuid, SEEK_SET) != off_newuid) + || (write_full(fd, &fl, sizeof (fl)) == -1)) { - fprintf (stderr, + fprintf(stderr, _("%s: failed to copy the faillog entry of user %lu to user %lu: %s\n"), Prog, (unsigned long) user_id, (unsigned long) user_newid, strerrno()); } } } - if (close (fd) != 0 && errno != EINTR) { - fprintf (stderr, + if (close(fd) != 0 && errno != EINTR) { + fprintf(stderr, _("%s: failed to copy the faillog entry of user %ju to user %ju: %s\n"), Prog, (uintmax_t) user_id, (uintmax_t) user_newid, strerrno()); } @@ -2080,16 +2080,16 @@ static void update_faillog (void) * being setgid mail, but is NOT recommended; they all should be fixed * to use movemail). --marekm */ -static void move_mailbox (void) +static void move_mailbox(void) { int fd; char *mailfile; const char *maildir; struct stat st; - maildir = getdef_str ("MAIL_DIR"); + maildir = getdef_str("MAIL_DIR"); #ifdef MAIL_SPOOL_DIR - if ((NULL == maildir) && (getdef_str ("MAIL_FILE") == NULL)) { + if ((NULL == maildir) && (getdef_str("MAIL_FILE") == NULL)) { maildir = MAIL_SPOOL_DIR; } #endif @@ -2109,7 +2109,7 @@ static void move_mailbox (void) mailfile = xaprintf("%s/%s", maildir, user_name); } - fd = open (mailfile, O_RDONLY | O_NONBLOCK, 0); + fd = open(mailfile, O_RDONLY | O_NONBLOCK, 0); if (fd < 0) { /* no need for warnings if the mailbox doesn't exist */ if (errno != ENOENT) { @@ -2126,26 +2126,26 @@ static void move_mailbox (void) } if (st.st_uid != user_id) { /* better leave it alone */ - fprintf (stderr, _("%s: warning: %s not owned by %s\n"), + fprintf(stderr, _("%s: warning: %s not owned by %s\n"), Prog, mailfile, user_name); - (void) close (fd); + (void) close(fd); free(mailfile); return; } if (uflg) { - if (fchown (fd, user_newid, (gid_t) -1) < 0) { - perror (_("failed to change mailbox owner")); + if (fchown(fd, user_newid, (gid_t) -1) < 0) { + perror(_("failed to change mailbox owner")); } #ifdef WITH_AUDIT else { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "updating-mail-file-owner", user_newname, user_newid, 1); } #endif } - (void) close (fd); + (void) close(fd); if (lflg) { char *newmailfile; @@ -2156,13 +2156,13 @@ static void move_mailbox (void) } else { newmailfile = xaprintf("%s/%s", maildir, user_newname); } - if ( (link (mailfile, newmailfile) != 0) - || (unlink (mailfile) != 0)) { - perror (_("failed to rename mailbox")); + if ( (link(mailfile, newmailfile) != 0) + || (unlink(mailfile) != 0)) { + perror(_("failed to rename mailbox")); } #ifdef WITH_AUDIT else { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "updating-mail-file-name", user_newname, user_newid, 1); } @@ -2178,7 +2178,7 @@ static void move_mailbox (void) /* * main - usermod command */ -int main (int argc, char **argv) +int main(int argc, char **argv) { struct option_flags flags = {.chroot = false, .prefix = false}; bool process_selinux; @@ -2186,32 +2186,32 @@ int main (int argc, char **argv) log_set_progname(Prog); log_set_logfd(stderr); - (void) setlocale (LC_ALL, ""); - (void) bindtextdomain (PACKAGE, LOCALEDIR); - (void) textdomain (PACKAGE); + (void) setlocale(LC_ALL, ""); + (void) bindtextdomain(PACKAGE, LOCALEDIR); + (void) textdomain(PACKAGE); - process_root_flag ("-R", argc, argv); - prefix = process_prefix_flag ("-P", argc, argv); + process_root_flag("-R", argc, argv); + prefix = process_prefix_flag("-P", argc, argv); - OPENLOG (Prog); + OPENLOG(Prog); #ifdef WITH_AUDIT - audit_help_open (); + audit_help_open(); #endif sys_ngroups = ngroups_max_size(); user_groups = xmalloc_T(sys_ngroups + 1, char *); user_groups[0] = NULL; - is_shadow_pwd = spw_file_present (); + is_shadow_pwd = spw_file_present(); #ifdef SHADOWGRP - is_shadow_grp = sgr_file_present (); + is_shadow_grp = sgr_file_present(); #endif #ifdef ENABLE_SUBIDS is_sub_uid = want_subuid_file() && sub_uid_file_present(); is_sub_gid = want_subgid_file() && sub_gid_file_present(); #endif /* ENABLE_SUBIDS */ - process_flags (argc, argv, &flags); + process_flags(argc, argv, &flags); process_selinux = !flags.chroot && !flags.prefix; /* @@ -2224,13 +2224,13 @@ int main (int argc, char **argv) || Vflg || Wflg #endif /* ENABLE_SUBIDS */ ) - && (user_busy (user_name, user_id) != 0)) { - exit (E_USER_BUSY); + && (user_busy(user_name, user_id) != 0)) { + exit(E_USER_BUSY); } #ifdef WITH_TCB - if (shadowtcb_set_user (user_name) == SHADOWTCB_FAILURE) { - exit (E_PW_UPDATE); + if (shadowtcb_set_user(user_name) == SHADOWTCB_FAILURE) { + exit(E_PW_UPDATE); } #endif @@ -2238,27 +2238,27 @@ int main (int argc, char **argv) * Do the hard stuff - open the files, change the user entries, * change the home directory, then close and update the files. */ - open_files (process_selinux); + open_files(process_selinux); if ( cflg || dflg || eflg || fflg || gflg || Lflg || lflg || pflg || sflg || uflg || Uflg) { - usr_update (&flags); + usr_update(&flags); } if (Gflg || lflg) { - grp_update (process_selinux); + grp_update(process_selinux); } #ifdef ENABLE_SUBIDS if (Sflg) { - if (find_range (&add_sub_uids, find_new_sub_uids) == 0) { - fprintf (stderr, + if (find_range(&add_sub_uids, find_new_sub_uids) == 0) { + fprintf(stderr, _("%s: unable to find new subordinate uid range\n"), Prog); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } - if (find_range (&add_sub_gids, find_new_sub_gids) == 0) { - fprintf (stderr, + if (find_range(&add_sub_gids, find_new_sub_gids) == 0) { + fprintf(stderr, _("%s: unable to find new subordinate gid range\n"), Prog); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } } @@ -2275,7 +2275,7 @@ int main (int argc, char **argv) (uintmax_t) ptr->range.first, (uintmax_t) ptr->range.last, sub_uid_dbname()); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } } } @@ -2292,7 +2292,7 @@ int main (int argc, char **argv) (uintmax_t) ptr->range.first, (uintmax_t) ptr->range.last, sub_uid_dbname()); - fail_exit (E_SUB_UID_UPDATE, process_selinux); + fail_exit(E_SUB_UID_UPDATE, process_selinux); } } } @@ -2309,7 +2309,7 @@ int main (int argc, char **argv) (uintmax_t) ptr->range.first, (uintmax_t) ptr->range.last, sub_gid_dbname()); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } } } @@ -2326,77 +2326,77 @@ int main (int argc, char **argv) (uintmax_t) ptr->range.first, (uintmax_t) ptr->range.last, sub_gid_dbname()); - fail_exit (E_SUB_GID_UPDATE, process_selinux); + fail_exit(E_SUB_GID_UPDATE, process_selinux); } } } #endif /* ENABLE_SUBIDS */ - close_files (&flags); + close_files(&flags); #ifdef WITH_TCB if ( (lflg || uflg) - && (shadowtcb_move (user_newname, user_newid) == SHADOWTCB_FAILURE) ) { - exit (E_PW_UPDATE); + && (shadowtcb_move(user_newname, user_newid) == SHADOWTCB_FAILURE) ) { + exit(E_PW_UPDATE); } #endif - nscd_flush_cache ("passwd"); - nscd_flush_cache ("group"); - sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP); + nscd_flush_cache("passwd"); + nscd_flush_cache("group"); + sssd_flush_cache(SSSD_DB_PASSWD | SSSD_DB_GROUP); #ifdef WITH_SELINUX if (Zflg) { if (!streq(user_selinux, "")) { - if (set_seuser (user_name, user_selinux, user_selinux_range) != 0) { - fprintf (stderr, + if (set_seuser(user_name, user_selinux, user_selinux_range) != 0) { + fprintf(stderr, _("%s: warning: the user name %s to %s SELinux user mapping failed.\n"), Prog, user_name, user_selinux); #ifdef WITH_AUDIT - audit_logger (AUDIT_ROLE_ASSIGN, + audit_logger(AUDIT_ROLE_ASSIGN, "changing-selinux-user-mapping ", user_name, user_id, SHADOW_AUDIT_FAILURE); #endif /* WITH_AUDIT */ - fail_exit (E_SE_UPDATE, process_selinux); + fail_exit(E_SE_UPDATE, process_selinux); } } else { - if (del_seuser (user_name) != 0) { - fprintf (stderr, + if (del_seuser(user_name) != 0) { + fprintf(stderr, _("%s: warning: the user name %s to SELinux user mapping removal failed.\n"), Prog, user_name); #ifdef WITH_AUDIT - audit_logger (AUDIT_ROLE_REMOVE, + audit_logger(AUDIT_ROLE_REMOVE, "delete-selinux-user-mapping", user_name, user_id, SHADOW_AUDIT_FAILURE); #endif /* WITH_AUDIT */ - fail_exit (E_SE_UPDATE, process_selinux); + fail_exit(E_SE_UPDATE, process_selinux); } } } #endif /* WITH_SELINUX */ if (mflg) { - move_home (process_selinux); + move_home(process_selinux); } #ifndef NO_MOVE_MAILBOX if (lflg || uflg) { - move_mailbox (); + move_mailbox(); } #endif /* NO_MOVE_MAILBOX */ if (uflg) { #ifdef ENABLE_LASTLOG - update_lastlog (); + update_lastlog(); #endif /* ENABLE_LASTLOG */ - update_faillog (); + update_faillog(); } if (!mflg && (uflg || gflg)) { struct stat sb; - if (stat (dflg ? prefix_user_newhome : prefix_user_home, &sb) == 0 && + if (stat(dflg ? prefix_user_newhome : prefix_user_home, &sb) == 0 && ((uflg && sb.st_uid == user_newid) || sb.st_uid == user_id)) { /* * Change the UID on all of the files owned by @@ -2409,20 +2409,20 @@ int main (int argc, char **argv) */ #ifdef WITH_AUDIT if (uflg || gflg) { - audit_logger (AUDIT_USER_MGMT, + audit_logger(AUDIT_USER_MGMT, "updating-home-dir-owner", user_newname, user_newid, 1); } #endif - if (chown_tree (dflg ? prefix_user_newhome : prefix_user_home, + if (chown_tree(dflg ? prefix_user_newhome : prefix_user_home, user_id, uflg ? user_newid : (uid_t)-1, user_gid, gflg ? user_newgid : (gid_t)-1) != 0) { - fprintf (stderr, + fprintf(stderr, _("%s: Failed to change ownership of the home directory"), Prog); - fail_exit (E_HOMEDIR, process_selinux); + fail_exit(E_HOMEDIR, process_selinux); } } } diff --git a/src/vipw.c b/src/vipw.c index f6a3b72eee..dc9817d446 100644 --- a/src/vipw.c +++ b/src/vipw.c @@ -63,7 +63,7 @@ static const char *Prog; static const char *filename, *fileeditname; static bool filelocked = false; static bool createedit = false; -static int (*unlock) (bool); +static int(*unlock) (bool); static bool quiet = false; #ifdef WITH_TCB static const char *user = NULL; @@ -80,31 +80,31 @@ static void vipwedit (const char *, int (*)(void), int (*)(bool)); /* * usage - display usage message and exit */ -static void usage (int status) +static void usage(int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; - (void) fprintf (usageout, + (void) fprintf(usageout, _("Usage: %s [options]\n" "\n" "Options:\n"), Prog); - (void) fputs (_(" -g, --group edit group database\n"), usageout); - (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); - (void) fputs (_(" -p, --passwd edit passwd database\n"), usageout); - (void) fputs (_(" -q, --quiet quiet mode\n"), usageout); - (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -s, --shadow edit shadow or gshadow database\n"), usageout); + (void) fputs(_(" -g, --group edit group database\n"), usageout); + (void) fputs(_(" -h, --help display this help message and exit\n"), usageout); + (void) fputs(_(" -p, --passwd edit passwd database\n"), usageout); + (void) fputs(_(" -q, --quiet quiet mode\n"), usageout); + (void) fputs(_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs(_(" -s, --shadow edit shadow or gshadow database\n"), usageout); #ifdef WITH_TCB - (void) fputs (_(" -u, --user which user's tcb shadow file to edit\n"), usageout); + (void) fputs(_(" -u, --user which user's tcb shadow file to edit\n"), usageout); #endif /* WITH_TCB */ - (void) fputs (_("\n"), usageout); - exit (status); + (void) fputs(_("\n"), usageout); + exit(status); } /* * */ -static int create_backup_file (FILE * fp, char *backup, struct stat *sb) +static int create_backup_file(FILE * fp, char *backup, struct stat *sb) { struct utimbuf ub; FILE *bkfp; @@ -116,35 +116,35 @@ static int create_backup_file (FILE * fp, char *backup, struct stat *sb) } c = 0; - if (fseeko (fp, 0, SEEK_SET) == 0) - while ((c = getc (fp)) != EOF) { - if (putc (c, bkfp) == EOF) { + if (fseeko(fp, 0, SEEK_SET) == 0) + while ((c = getc(fp)) != EOF) { + if (putc(c, bkfp) == EOF) { break; } } - if ((EOF != c) || (ferror (fp) != 0) || (fflush (bkfp) != 0)) { - fclose (bkfp); - unlink (backup); + if ((EOF != c) || (ferror(fp) != 0) || (fflush(bkfp) != 0)) { + fclose(bkfp); + unlink(backup); return -1; } - if (fsync (fileno (bkfp)) != 0) { - (void) fclose (bkfp); - unlink (backup); + if (fsync(fileno(bkfp)) != 0) { + (void) fclose(bkfp); + unlink(backup); return -1; } ub.actime = sb->st_atime; ub.modtime = sb->st_mtime; - if ( (utime (backup, &ub) != 0) + if ( (utime(backup, &ub) != 0) || (fchown(fileno(bkfp), sb->st_uid, sb->st_gid) != 0) || (fchmod(fileno(bkfp), sb->st_mode) != 0)) { fclose(bkfp); - unlink (backup); + unlink(backup); return -1; } - if (fclose (bkfp) != 0) { - unlink (backup); + if (fclose(bkfp) != 0) { + unlink(backup); return -1; } return 0; @@ -153,13 +153,13 @@ static int create_backup_file (FILE * fp, char *backup, struct stat *sb) /* * */ -static void vipwexit (const char *msg, int syserr, int ret) +static void vipwexit(const char *msg, int syserr, int ret) { int err = errno; if (createedit) { - if (unlink (fileeditname) != 0) { - fprintf (stderr, _("%s: failed to remove %s\n"), Prog, fileeditname); + if (unlink(fileeditname) != 0) { + fprintf(stderr, _("%s: failed to remove %s\n"), Prog, fileeditname); /* continue */ } } @@ -171,19 +171,19 @@ static void vipwexit (const char *msg, int syserr, int ret) } } if (NULL != msg) { - fprintf (stderr, "%s: %s", Prog, msg); + fprintf(stderr, "%s: %s", Prog, msg); } if (0 != syserr) { - fprintf (stderr, ": %s", strerror (err)); + fprintf(stderr, ": %s", strerror(err)); } if ( (NULL != msg) || (0 != syserr)) { - (void) fputs ("\n", stderr); + (void) fputs("\n", stderr); } if (!quiet) printf(_("%s: %s is unchanged\n"), Prog, filename); - exit (ret); + exit(ret); } #ifndef DEFAULT_EDITOR @@ -194,7 +194,7 @@ static void vipwexit (const char *msg, int syserr, int ret) * */ static void -vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) +vipwedit(const char *file, int(*file_lock) (void), int(*file_unlock) (bool)) { int status; char *to_rename; @@ -235,31 +235,31 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) #ifdef WITH_SELINUX /* if SE Linux is enabled then set the context of all new files to be the context of the file we are editing */ - if (is_selinux_enabled () != 0) { + if (is_selinux_enabled() != 0) { char *passwd_context_raw = NULL; int ret = 0; - if (getfilecon_raw (file, &passwd_context_raw) < 0) { - vipwexit (_("Couldn't get file context"), errno, 1); + if (getfilecon_raw(file, &passwd_context_raw) < 0) { + vipwexit(_("Couldn't get file context"), errno, 1); } - ret = setfscreatecon_raw (passwd_context_raw); - freecon (passwd_context_raw); + ret = setfscreatecon_raw(passwd_context_raw); + freecon(passwd_context_raw); if (0 != ret) { - vipwexit (_("setfscreatecon () failed"), errno, 1); + vipwexit(_("setfscreatecon() failed"), errno, 1); } } #endif /* WITH_SELINUX */ #ifdef WITH_TCB - if (tcb_mode && (shadowtcb_gain_priv () == SHADOWTCB_FAILURE)) { - vipwexit (_("failed to gain privileges"), errno, 1); + if (tcb_mode && (shadowtcb_gain_priv() == SHADOWTCB_FAILURE)) { + vipwexit(_("failed to gain privileges"), errno, 1); } #endif /* WITH_TCB */ - if (file_lock () == 0) { - vipwexit (_("Couldn't lock file"), errno, 5); + if (file_lock() == 0) { + vipwexit(_("Couldn't lock file"), errno, 5); } filelocked = true; #ifdef WITH_TCB - if (tcb_mode && (shadowtcb_drop_priv () == SHADOWTCB_FAILURE)) { - vipwexit (_("failed to drop privileges"), errno, 1); + if (tcb_mode && (shadowtcb_drop_priv() == SHADOWTCB_FAILURE)) { + vipwexit(_("failed to drop privileges"), errno, 1); } #endif /* WITH_TCB */ @@ -294,9 +294,9 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) /* set SIGCHLD to default for waitpid */ signal(SIGCHLD, SIG_DFL); - pid = fork (); + pid = fork(); if (-1 == pid) { - vipwexit ("fork", 1, 1); + vipwexit("fork", 1, 1); } else if (0 == pid) { /* use the system() call to invoke the editor so that it accepts command line args in the EDITOR and VISUAL environment vars */ @@ -349,15 +349,15 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) if (orig_pgrp != -1) { editor_pgrp = tcgetpgrp(STDIN_FILENO); if (editor_pgrp == -1) { - fprintf (stderr, "%s: %s: %s", Prog, + fprintf(stderr, "%s: %s: %s", Prog, "tcgetpgrp", strerrno()); } if (tcsetpgrp(STDIN_FILENO, orig_pgrp) == -1) { - fprintf (stderr, "%s: %s: %s", Prog, + fprintf(stderr, "%s: %s: %s", Prog, "tcsetpgrp", strerrno()); } } - kill (getpid (), SIGSTOP); + kill(getpid(), SIGSTOP); /* wake child when resumed */ if (editor_pgrp != -1) { if (tcsetpgrp(STDIN_FILENO, editor_pgrp) == -1) { @@ -380,18 +380,18 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) } if (-1 == pid) { - vipwexit (editor, 1, 1); - } else if ( WIFEXITED (status) - && (WEXITSTATUS (status) != 0)) { - vipwexit (NULL, 0, WEXITSTATUS (status)); - } else if (WIFSIGNALED (status)) { - fprintf (stderr, _("%s: %s killed by signal %d\n"), + vipwexit(editor, 1, 1); + } else if ( WIFEXITED(status) + && (WEXITSTATUS(status) != 0)) { + vipwexit(NULL, 0, WEXITSTATUS(status)); + } else if (WIFSIGNALED(status)) { + fprintf(stderr, _("%s: %s killed by signal %d\n"), Prog, editor, WTERMSIG(status)); - vipwexit (NULL, 0, 1); + vipwexit(NULL, 0, 1); } - if (stat (fileedit, &st2) != 0) { - vipwexit (fileedit, 1, 1); + if (stat(fileedit, &st2) != 0) { + vipwexit(fileedit, 1, 1); } if (st1.st_mtime == st2.st_mtime) { vipwexit(NULL, 0, 0); @@ -413,39 +413,39 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) createedit = false; #ifdef WITH_TCB if (tcb_mode) { - f = fopen (fileedit, "r"); + f = fopen(fileedit, "r"); if (NULL == f) { - vipwexit (_("failed to open scratch file"), errno, 1); + vipwexit(_("failed to open scratch file"), errno, 1); } - if (unlink (fileedit) != 0) { - vipwexit (_("failed to unlink scratch file"), errno, 1); + if (unlink(fileedit) != 0) { + vipwexit(_("failed to unlink scratch file"), errno, 1); } - if (shadowtcb_drop_priv () == SHADOWTCB_FAILURE) { - vipwexit (_("failed to drop privileges"), errno, 1); + if (shadowtcb_drop_priv() == SHADOWTCB_FAILURE) { + vipwexit(_("failed to drop privileges"), errno, 1); } - if (stat (file, &st1) != 0) { - vipwexit (_("failed to stat edited file"), errno, 1); + if (stat(file, &st1) != 0) { + vipwexit(_("failed to stat edited file"), errno, 1); } to_rename = aprintf("%s,XXXXXX", file); if (to_rename == NULL) - vipwexit (_("aprintf() failed"), errno, 1); + vipwexit(_("aprintf() failed"), errno, 1); - if (create_backup_file (f, to_rename, &st1) != 0) { + if (create_backup_file(f, to_rename, &st1) != 0) { free(to_rename); - vipwexit (_("failed to create backup file"), errno, 1); + vipwexit(_("failed to create backup file"), errno, 1); } - (void) fclose (f); + (void) fclose(f); } else { #endif /* WITH_TCB */ to_rename = fileedit; #ifdef WITH_TCB } #endif /* WITH_TCB */ - unlink (filebackup); - link (file, filebackup); - if (rename (to_rename, file) == -1) { - fprintf (stderr, - _("%s: can't restore %s: %s (your changes are in %s)\n"), + unlink(filebackup); + link(file, filebackup); + if (rename(to_rename, file) == -1) { + fprintf(stderr, + _("%s: can't restore %s: %s(your changes are in %s)\n"), Prog, file, strerrno(), to_rename); #ifdef WITH_TCB if (tcb_mode) { @@ -458,14 +458,14 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) #ifdef WITH_TCB if (tcb_mode) { free(to_rename); - if (shadowtcb_gain_priv () == SHADOWTCB_FAILURE) { - vipwexit (_("failed to gain privileges"), errno, 1); + if (shadowtcb_gain_priv() == SHADOWTCB_FAILURE) { + vipwexit(_("failed to gain privileges"), errno, 1); } } #endif /* WITH_TCB */ if ((*file_unlock) (true) == 0) { - fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, fileeditname); + fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, fileeditname); SYSLOG(LOG_ERR, "failed to unlock %s", fileeditname); /* continue */ } @@ -508,7 +508,7 @@ int main (int argc, char **argv) #endif /* WITH_TCB */ {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, + while ((c = getopt_long(argc, argv, #ifdef WITH_TCB "ghpqR:su:", #else /* !WITH_TCB */ @@ -520,7 +520,7 @@ int main (int argc, char **argv) do_vigr = true; break; case 'h': - usage (E_SUCCESS); + usage(E_SUCCESS); break; case 'p': do_vigr = false;