New upstream version 4.15.2

This commit is contained in:
Chris Hofstaedtler
2024-06-22 17:34:25 +02:00
parent f7f4fd7c05
commit 0fda4df4f1
10661 changed files with 382133 additions and 3243 deletions
+1
View File
@@ -489,6 +489,7 @@ EGREP = @EGREP@
ETAGS = @ETAGS@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
FILECMD = @FILECMD@
GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
GMSGFMT = @GMSGFMT@
GMSGFMT_015 = @GMSGFMT_015@
+9 -8
View File
@@ -27,6 +27,7 @@
#include <pwd.h>
#include "alloc.h"
#include "atoi/str2i.h"
#include "defines.h"
#include "memzero.h"
#include "prototypes.h"
@@ -170,14 +171,14 @@ static int new_fields (void)
SNPRINTF(buf, "%ld", mindays);
change_field (buf, sizeof buf, _("Minimum Password Age"));
if ( (getlong(buf, &mindays) == -1)
if ( (str2sl(&mindays, buf) == -1)
|| (mindays < -1)) {
return 0;
}
SNPRINTF(buf, "%ld", maxdays);
change_field (buf, sizeof buf, _("Maximum Password Age"));
if ( (getlong(buf, &maxdays) == -1)
if ( (str2sl(&maxdays, buf) == -1)
|| (maxdays < -1)) {
return 0;
}
@@ -200,14 +201,14 @@ static int new_fields (void)
SNPRINTF(buf, "%ld", warndays);
change_field (buf, sizeof buf, _("Password Expiration Warning"));
if ( (getlong(buf, &warndays) == -1)
if ( (str2sl(&warndays, buf) == -1)
|| (warndays < -1)) {
return 0;
}
SNPRINTF(buf, "%ld", inactdays);
change_field (buf, sizeof buf, _("Password Inactive"));
if ( (getlong(buf, &inactdays) == -1)
if ( (str2sl(&inactdays, buf) == -1)
|| (inactdays < -1)) {
return 0;
}
@@ -396,7 +397,7 @@ static void process_flags (int argc, char **argv)
break;
case 'I':
Iflg = true;
if ( (getlong(optarg, &inactdays) == -1)
if ( (str2sl(&inactdays, optarg) == -1)
|| (inactdays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
@@ -409,7 +410,7 @@ static void process_flags (int argc, char **argv)
break;
case 'm':
mflg = true;
if ( (getlong(optarg, &mindays) == -1)
if ( (str2sl(&mindays, optarg) == -1)
|| (mindays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
@@ -419,7 +420,7 @@ static void process_flags (int argc, char **argv)
break;
case 'M':
Mflg = true;
if ( (getlong(optarg, &maxdays) == -1)
if ( (str2sl(&maxdays, optarg) == -1)
|| (maxdays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
@@ -433,7 +434,7 @@ static void process_flags (int argc, char **argv)
break;
case 'W':
Wflg = true;
if ( (getlong(optarg, &warndays) == -1)
if ( (str2sl(&warndays, optarg) == -1)
|| (warndays < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
+3 -5
View File
@@ -13,7 +13,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "atoi/strtou_noneg.h"
#include "atoi/str2i.h"
#include "defines.h"
#include "prototypes.h"
#include "subordinateio.h"
@@ -36,11 +36,9 @@ int main(int argc, char **argv)
owner = argv[1];
check_uids = argv[2][0] == 'u';
errno = 0;
start = strtoul_noneg(argv[3], NULL, 10);
if (errno != 0)
if (str2ul(&start, argv[3]) == -1)
exit(1);
count = strtoul_noneg(argv[4], NULL, 10);
if (errno != 0)
if (str2ul(&count, argv[4]) == -1)
exit(1);
if (check_uids) {
if (have_sub_uids(owner, start, count))
+6 -3
View File
@@ -16,11 +16,13 @@
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
#include "pam_defs.h"
#endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */
#include "atoi/str2i.h"
#include "defines.h"
#include "nscd.h"
#include "sssd.h"
@@ -33,6 +35,7 @@
#include "exitcodes.h"
#include "shadowlog.h"
/*
* Global variables
*/
@@ -195,19 +198,19 @@ static void process_flags (int argc, char **argv)
}
#if defined(USE_SHA_CRYPT)
if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512")))
&& (-1 == getlong(optarg, &sha_rounds)))) {
&& (-1 == str2sl(&sha_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (( (0 == strcmp (crypt_method, "BCRYPT"))
&& (-1 == getlong(optarg, &bcrypt_rounds)))) {
&& (-1 == str2sl(&bcrypt_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
&& (-1 == getlong(optarg, &yescrypt_cost)))) {
&& (-1 == str2sl(&yescrypt_cost, optarg)))) {
bad_s = 1;
}
#endif /* USE_YESCRYPT */
+6 -3
View File
@@ -16,9 +16,11 @@
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef USE_PAM
#include "pam_defs.h"
#endif /* USE_PAM */
#include "atoi/str2i.h"
#include "defines.h"
#include "nscd.h"
#include "sssd.h"
@@ -30,6 +32,7 @@
#include "exitcodes.h"
#include "shadowlog.h"
#define IS_CRYPT_METHOD(str) ((crypt_method != NULL && strcmp(crypt_method, str) == 0) ? true : false)
/*
@@ -190,19 +193,19 @@ static void process_flags (int argc, char **argv)
bad_s = 0;
#if defined(USE_SHA_CRYPT)
if ((IS_CRYPT_METHOD("SHA256") || IS_CRYPT_METHOD("SHA512"))
&& (-1 == getlong(optarg, &sha_rounds))) {
&& (-1 == str2sl(&sha_rounds, optarg))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (IS_CRYPT_METHOD("BCRYPT")
&& (-1 == getlong(optarg, &bcrypt_rounds))) {
&& (-1 == str2sl(&bcrypt_rounds, optarg))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (IS_CRYPT_METHOD("YESCRYPT")
&& (-1 == getlong(optarg, &yescrypt_cost))) {
&& (-1 == str2sl(&yescrypt_cost, optarg))) {
bad_s = 1;
}
#endif /* USE_YESCRYPT */
+5 -3
View File
@@ -19,6 +19,7 @@
#include <time.h>
#include <assert.h>
#include "atoi/str2i.h"
#include "defines.h"
#include "faillog.h"
#include "memzero.h"
@@ -29,6 +30,7 @@
#include "string/strftime.h"
/* local function prototypes */
NORETURN static void usage (int status);
static void print_one (/*@null@*/const struct passwd *pw, bool force);
@@ -545,7 +547,7 @@ int main (int argc, char **argv)
usage (E_SUCCESS);
/*@notreached@*/break;
case 'l':
if (getlong(optarg, &fail_locktime) == -1) {
if (str2sl(&fail_locktime, optarg) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -557,7 +559,7 @@ int main (int argc, char **argv)
{
long lmax;
if ( (getlong(optarg, &lmax) == -1)
if ( (str2sl(&lmax, optarg) == -1)
|| ((long)(short) lmax != lmax)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
@@ -574,7 +576,7 @@ int main (int argc, char **argv)
case 'R': /* no-op, handled in process_root_flag () */
break;
case 't':
if (getlong(optarg, &days) == -1) {
if (str2sl(&days, optarg) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
+1
View File
@@ -44,5 +44,6 @@ int main(int argc, char *argv[])
printf("%d: %s %lu %lu\n", i, owner,
ranges[i].start, ranges[i].count);
}
free(ranges);
return 0;
}
-2
View File
@@ -250,8 +250,6 @@ static void grp_update (void)
if (!aflg) {
// requested to replace the existing groups
if (NULL != grp.gr_mem[0])
gr_free_members(&grp);
grp.gr_mem = XMALLOC(1, char *);
grp.gr_mem[0] = NULL;
} else {
+4 -2
View File
@@ -23,6 +23,7 @@
#include <net/if.h>
#endif
#include "atoi/str2i.h"
#include "defines.h"
#include "prototypes.h"
#include "getdef.h"
@@ -33,6 +34,7 @@
#include "string/strftime.h"
/*
* Needed for MkLinux DR1/2/2.1 - J.
*/
@@ -326,7 +328,7 @@ int main (int argc, char **argv)
case 'b':
{
unsigned long inverse_days;
if (getulong(optarg, &inverse_days) == -1) {
if (str2ul(&inverse_days, optarg) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -354,7 +356,7 @@ int main (int argc, char **argv)
case 't':
{
unsigned long days;
if (getulong(optarg, &days) == -1) {
if (str2ul(&days, optarg) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
+5 -2
View File
@@ -27,6 +27,7 @@
#include "alloc.h"
#include "attr.h"
#include "chkname.h"
#include "defines.h"
#include "faillog.h"
#include "failure.h"
@@ -573,8 +574,9 @@ int main (int argc, char **argv)
}
#ifdef RLOGIN
if (rflg) {
size_t max_size = sysconf(_SC_LOGIN_NAME_MAX);
size_t max_size;
max_size = login_name_max_size();
assert (NULL == username);
username = XMALLOC(max_size, char);
username[max_size - 1] = '\0';
@@ -882,8 +884,9 @@ int main (int argc, char **argv)
failed = false; /* haven't failed authentication yet */
if (NULL == username) { /* need to get a login id */
size_t max_size = sysconf(_SC_LOGIN_NAME_MAX);
size_t max_size;
max_size = login_name_max_size();
if (subroot) {
closelog ();
exit (1);
+4 -3
View File
@@ -31,6 +31,7 @@
#include <string.h>
#include "alloc.h"
#include "atoi/str2i.h"
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
#include "pam_defs.h"
@@ -673,19 +674,19 @@ static void process_flags (int argc, char **argv)
}
#if defined(USE_SHA_CRYPT)
if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512")))
&& (-1 == getlong(optarg, &sha_rounds)))) {
&& (-1 == str2sl(&sha_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (( (0 == strcmp (crypt_method, "BCRYPT"))
&& (-1 == getlong(optarg, &bcrypt_rounds)))) {
&& (-1 == str2sl(&bcrypt_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
&& (-1 == getlong(optarg, &yescrypt_cost)))) {
&& (-1 == str2sl(&yescrypt_cost, optarg)))) {
bad_s = 1;
}
#endif /* USE_YESCRYPT */
+6 -4
View File
@@ -22,6 +22,7 @@
#include "agetpass.h"
#include "alloc.h"
#include "atoi/str2i.h"
#include "defines.h"
#include "getdef.h"
#include "memzero.h"
@@ -36,6 +37,7 @@
#include "time/day_to_str.h"
/*
* exit status values
*/
@@ -799,7 +801,7 @@ int main (int argc, char **argv)
usage (E_SUCCESS);
/*@notreached@*/break;
case 'i':
if ( (getlong(optarg, &inact) == -1)
if ( (str2sl(&inact, optarg) == -1)
|| (inact < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
@@ -818,7 +820,7 @@ int main (int argc, char **argv)
anyflag = true;
break;
case 'n':
if ( (getlong(optarg, &age_min) == -1)
if ( (str2sl(&age_min, optarg) == -1)
|| (age_min < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
@@ -853,7 +855,7 @@ int main (int argc, char **argv)
anyflag = true;
break;
case 'w':
if ( (getlong(optarg, &warn) == -1)
if ( (str2sl(&warn, optarg) == -1)
|| (warn < -1)) {
(void) fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
@@ -864,7 +866,7 @@ int main (int argc, char **argv)
anyflag = true;
break;
case 'x':
if ( (getlong(optarg, &age_max) == -1)
if ( (str2sl(&age_max, optarg) == -1)
|| (age_max < -1)) {
(void) fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
+48 -31
View File
@@ -37,6 +37,7 @@
#include <unistd.h>
#include "alloc.h"
#include "atoi/str2i.h"
#include "chkname.h"
#include "defines.h"
#include "faillog.h"
@@ -237,6 +238,9 @@ static void create_home (void);
static void create_mail (void);
static void check_uid_range(int rflg, uid_t user_id);
static FILE *fmkstemp(char *template);
/*
* fail_exit - undo as much as possible
*/
@@ -415,7 +419,7 @@ static void get_defaults (void)
* Default Password Inactive value
*/
else if (MATCH (buf, DINACT)) {
if ( (getlong(ccp, &def_inactive) == -1)
if ( (str2sl(&def_inactive, ccp) == -1)
|| (def_inactive < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
@@ -523,7 +527,6 @@ static void show_defaults (void)
*/
static int set_defaults (void)
{
int ofd;
int ret = -1;
bool out_group = false;
bool out_groups = false;
@@ -557,7 +560,7 @@ static int set_defaults (void)
fprintf(stderr,
_("%s: cannot create new defaults file: %s\n"),
Prog, strerror(errno));
goto setdef_err;
goto err_free_new;
}
}
@@ -566,36 +569,27 @@ static int set_defaults (void)
fprintf (stderr,
_("%s: cannot create directory for defaults file\n"),
Prog);
goto setdef_err;
goto err_free_def;
}
ret = mkdir(dirname(new_file_dup), 0755);
free(new_file_dup);
if (-1 == ret && EEXIST != errno) {
fprintf (stderr,
_("%s: cannot create directory for defaults file\n"),
Prog);
free(new_file_dup);
goto setdef_err;
goto err_free_def;
}
free(new_file_dup);
/*
* Create a temporary file to copy the new output to.
*/
ofd = mkstemp (new_file);
if (-1 == ofd) {
fprintf (stderr,
_("%s: cannot create new defaults file\n"),
Prog);
goto setdef_err;
}
ofp = fdopen (ofd, "w");
ofp = fmkstemp(new_file);
if (NULL == ofp) {
fprintf (stderr,
_("%s: cannot open new defaults file\n"),
Prog);
goto setdef_err;
goto err_free_def;
}
/*
@@ -621,8 +615,9 @@ static int set_defaults (void)
fprintf (stderr,
_("%s: line too long in %s: %s..."),
Prog, default_file, buf);
(void) fclose (ifp);
goto setdef_err;
fclose(ifp);
fclose(ofp);
goto err_free_def;
}
}
@@ -701,9 +696,10 @@ static int set_defaults (void)
(void) fflush (ofp);
if ( (ferror (ofp) != 0)
|| (fsync (fileno (ofp)) != 0)
|| (fclose (ofp) != 0)) {
|| (fclose (ofp) != 0))
{
unlink (new_file);
goto setdef_err;
goto err_free_def;
}
/*
@@ -717,7 +713,7 @@ static int set_defaults (void)
_("%s: Cannot create backup file (%s): %s\n"),
Prog, buf, strerror (err));
unlink (new_file);
goto setdef_err;
goto err_free_def;
}
/*
@@ -728,7 +724,7 @@ static int set_defaults (void)
fprintf (stderr,
_("%s: rename: %s: %s\n"),
Prog, new_file, strerror (err));
goto setdef_err;
goto err_free_def;
}
#ifdef WITH_AUDIT
audit_logger (AUDIT_USYS_CONFIG, Prog,
@@ -743,11 +739,12 @@ static int set_defaults (void)
def_inactive, def_expire, def_template,
def_create_mail_spool, def_log_init));
ret = 0;
setdef_err:
free(new_file);
if (prefix[0]) {
err_free_def:
if (prefix[0])
free(default_file);
}
err_free_new:
free(new_file);
return ret;
}
@@ -856,14 +853,14 @@ static int get_groups (char *list)
*/
static struct group * get_local_group(char * grp_name)
{
char *end;
const struct group *grp;
struct group *result_grp = NULL;
long long gid;
char *endptr;
gid = strtoll (grp_name, &endptr, 10);
gid = strtoll(grp_name, &end, 10);
if ( ('\0' != *grp_name)
&& ('\0' == *endptr)
&& ('\0' == *end)
&& (ERANGE != errno)
&& (gid == (gid_t)gid)) {
grp = gr_locate_gid (gid);
@@ -1301,7 +1298,7 @@ static void process_flags (int argc, char **argv)
eflg = true;
break;
case 'f':
if ( (getlong(optarg, &def_inactive) == -1)
if ( (str2sl(&def_inactive, optarg) == -1)
|| (def_inactive < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
@@ -2750,3 +2747,23 @@ int main (int argc, char **argv)
return E_SUCCESS;
}
static FILE *
fmkstemp(char *template)
{
int fd;
FILE *fp;
fd = mkstemp(template);
if (fd == -1)
return NULL;
fp = fdopen(fd, "w");
if (fp == NULL) {
close(fd);
unlink(template);
return NULL;
}
return fp;
}
+227 -210
View File
@@ -33,6 +33,7 @@
#include <time.h>
#include "alloc.h"
#include "atoi/str2i.h"
#include "chkname.h"
#include "defines.h"
#include "faillog.h"
@@ -177,10 +178,12 @@ NORETURN static void usage (int status);
static void new_pwent (struct passwd *);
static void new_spent (struct spwd *);
NORETURN static void fail_exit (int);
static void update_group (void);
static void update_group_file(void);
static void update_group(const struct group *grp);
#ifdef SHADOWGRP
static void update_gshadow (void);
static void update_gshadow_file(void);
static void update_gshadow(const struct sgrp *sgrp);
#endif
static void grp_update (void);
@@ -684,263 +687,277 @@ fail_exit (int code)
}
static void update_group (void)
static void
update_group_file(void)
{
bool is_member;
bool was_member;
bool changed;
const struct group *grp;
struct group *ngrp;
changed = false;
const struct group *grp;
/*
* Scan through the entire group file looking for the groups that
* the user is a member of.
*/
while ((grp = gr_next ()) != NULL) {
/*
* See if the user specified this group as one of their
* concurrent groups.
*/
was_member = is_on_list (grp->gr_mem, user_name);
is_member = Gflg && ( (was_member && aflg)
|| is_on_list (user_groups, grp->gr_name));
while ((grp = gr_next()) != NULL)
update_group(grp);
}
if (!was_member && !is_member) {
continue;
}
/*
* If rflg+Gflg is passed in AKA -rG invert is_member flag, which removes
* mentioned groups while leaving the others.
*/
if (Gflg && rflg) {
is_member = !is_member;
}
static void
update_group(const struct group *grp)
{
bool changed;
bool is_member;
bool was_member;
struct group *ngrp;
ngrp = __gr_dup (grp);
if (NULL == ngrp) {
fprintf (stderr,
_("%s: Out of memory. Cannot update %s.\n"),
Prog, gr_dbname ());
fail_exit (E_GRP_UPDATE);
}
changed = false;
if (was_member) {
if ((!Gflg) || is_member) {
/* User was a member and is still a member
* of this group.
* But the user might have been renamed.
*/
if (lflg) {
ngrp->gr_mem = del_list (ngrp->gr_mem,
user_name);
ngrp->gr_mem = add_list (ngrp->gr_mem,
user_newname);
changed = true;
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"changing group member",
user_newname, AUDIT_NO_ID, 1);
#endif
SYSLOG ((LOG_INFO,
"change '%s' to '%s' in group '%s'",
user_name, user_newname,
ngrp->gr_name));
}
} else {
/* User was a member but is no more a
* member of this group.
*/
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
/*
* See if the user specified this group as one of their
* concurrent groups.
*/
was_member = is_on_list (grp->gr_mem, user_name);
is_member = Gflg && ( (was_member && aflg)
|| is_on_list (user_groups, grp->gr_name));
if (!was_member && !is_member)
return;
/*
* If rflg+Gflg is passed in AKA -rG invert is_member flag, which removes
* mentioned groups while leaving the others.
*/
if (Gflg && rflg) {
is_member = !is_member;
}
ngrp = __gr_dup (grp);
if (NULL == ngrp) {
fprintf (stderr,
_("%s: Out of memory. Cannot update %s.\n"),
Prog, gr_dbname ());
fail_exit (E_GRP_UPDATE);
}
if (was_member) {
if ((!Gflg) || is_member) {
/* User was a member and is still a member
* of this group.
* But the user might have been renamed.
*/
if (lflg) {
ngrp->gr_mem = del_list (ngrp->gr_mem,
user_name);
ngrp->gr_mem = add_list (ngrp->gr_mem,
user_newname);
changed = true;
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"removing group member",
user_name, AUDIT_NO_ID, 1);
"changing group member",
user_newname, AUDIT_NO_ID, 1);
#endif
SYSLOG ((LOG_INFO,
"delete '%s' from group '%s'",
user_name, ngrp->gr_name));
"change '%s' to '%s' in group '%s'",
user_name, user_newname,
ngrp->gr_name));
}
} else if (is_member) {
/* User was not a member but is now a member this
* group.
} else {
/* User was a member but is no more a
* member of this group.
*/
ngrp->gr_mem = add_list (ngrp->gr_mem, user_newname);
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
changed = true;
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"adding user to group",
user_name, AUDIT_NO_ID, 1);
"removing group member",
user_name, AUDIT_NO_ID, 1);
#endif
SYSLOG ((LOG_INFO, "add '%s' to group '%s'",
user_newname, ngrp->gr_name));
SYSLOG ((LOG_INFO,
"delete '%s' from group '%s'",
user_name, ngrp->gr_name));
}
if (!changed) {
continue;
}
changed = false;
if (gr_update (ngrp) == 0) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
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);
}
gr_free(ngrp);
} else if (is_member) {
/* User was not a member but is now a member this
* group.
*/
ngrp->gr_mem = add_list (ngrp->gr_mem, user_newname);
changed = true;
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"adding user to group",
user_name, AUDIT_NO_ID, 1);
#endif
SYSLOG ((LOG_INFO, "add '%s' to group '%s'",
user_newname, ngrp->gr_name));
}
if (!changed)
goto free_ngrp;
if (gr_update (ngrp) == 0) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
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);
}
free_ngrp:
gr_free(ngrp);
}
#ifdef SHADOWGRP
static void update_gshadow (void)
{
bool is_member;
bool was_member;
bool was_admin;
bool changed;
const struct sgrp *sgrp;
struct sgrp *nsgrp;
changed = false;
#ifdef SHADOWGRP
static void
update_gshadow_file(void)
{
const struct sgrp *sgrp;
/*
* Scan through the entire shadow group file looking for the groups
* that the user is a member of.
*/
while ((sgrp = sgr_next ()) != NULL) {
while ((sgrp = sgr_next()) != NULL)
update_gshadow(sgrp);
}
#endif /* SHADOWGRP */
/*
* See if the user was a member of this group
#ifdef SHADOWGRP
static void
update_gshadow(const struct sgrp *sgrp)
{
bool changed;
bool is_member;
bool was_member;
bool was_admin;
struct sgrp *nsgrp;
changed = false;
/*
* See if the user was a member of this group
*/
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);
/*
* 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_name));
if (!was_member && !was_admin && !is_member)
return;
/*
* If rflg+Gflg is passed in AKA -rG invert is_member, to remove targeted
* groups while leaving the user apart of groups not mentioned
*/
if (Gflg && rflg) {
is_member = !is_member;
}
nsgrp = __sgr_dup (sgrp);
if (NULL == nsgrp) {
fprintf (stderr,
_("%s: Out of memory. Cannot update %s.\n"),
Prog, sgr_dbname ());
fail_exit (E_GRP_UPDATE);
}
if (was_admin && lflg) {
/* User was an admin of this group but the user
* has been renamed.
*/
was_member = is_on_list (sgrp->sg_mem, user_name);
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 (AUDIT_USER_CHAUTHTOK, Prog,
"changing admin name in shadow group",
user_name, AUDIT_NO_ID, 1);
#endif
SYSLOG ((LOG_INFO,
"change admin '%s' to '%s' in shadow group '%s'",
user_name, user_newname, nsgrp->sg_name));
}
/*
* See if the user was an administrator of this group
*/
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_name));
if (!was_member && !was_admin && !is_member) {
continue;
}
/*
* If rflg+Gflg is passed in AKA -rG invert is_member, to remove targeted
* groups while leaving the user apart of groups not mentioned
*/
if (Gflg && rflg) {
is_member = !is_member;
}
nsgrp = __sgr_dup (sgrp);
if (NULL == nsgrp) {
fprintf (stderr,
_("%s: Out of memory. Cannot update %s.\n"),
Prog, sgr_dbname ());
fail_exit (E_GRP_UPDATE);
}
if (was_admin && lflg) {
/* User was an admin of this group but the user
* has been renamed.
if (was_member) {
if ((!Gflg) || is_member) {
/* User was a member and is still a member
* of this group.
* But the user might have been renamed.
*/
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 (AUDIT_USER_CHAUTHTOK, Prog,
"changing admin name in shadow group",
user_name, AUDIT_NO_ID, 1);
#endif
SYSLOG ((LOG_INFO,
"change admin '%s' to '%s' in shadow group '%s'",
user_name, user_newname, nsgrp->sg_name));
}
if (was_member) {
if ((!Gflg) || is_member) {
/* User was a member and is still a member
* of this group.
* But the user might have been renamed.
*/
if (lflg) {
nsgrp->sg_mem = del_list (nsgrp->sg_mem,
user_name);
nsgrp->sg_mem = add_list (nsgrp->sg_mem,
user_newname);
changed = true;
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"changing member in shadow group",
user_name, AUDIT_NO_ID, 1);
#endif
SYSLOG ((LOG_INFO,
"change '%s' to '%s' in shadow group '%s'",
user_name, user_newname,
nsgrp->sg_name));
}
} else {
/* User was a member but is no more a
* member of this group.
*/
nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name);
if (lflg) {
nsgrp->sg_mem = del_list (nsgrp->sg_mem,
user_name);
nsgrp->sg_mem = add_list (nsgrp->sg_mem,
user_newname);
changed = true;
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"removing user from shadow group",
user_name, AUDIT_NO_ID, 1);
"changing member in shadow group",
user_name, AUDIT_NO_ID, 1);
#endif
SYSLOG ((LOG_INFO,
"delete '%s' from shadow group '%s'",
user_name, nsgrp->sg_name));
"change '%s' to '%s' in shadow group '%s'",
user_name, user_newname,
nsgrp->sg_name));
}
} else if (is_member) {
/* User was not a member but is now a member this
* group.
} else {
/* User was a member but is no more a
* member of this group.
*/
nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_newname);
nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name);
changed = true;
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"adding user to shadow group",
user_newname, AUDIT_NO_ID, 1);
"removing user from shadow group",
user_name, AUDIT_NO_ID, 1);
#endif
SYSLOG ((LOG_INFO, "add '%s' to shadow group '%s'",
user_newname, nsgrp->sg_name));
SYSLOG ((LOG_INFO,
"delete '%s' from shadow group '%s'",
user_name, nsgrp->sg_name));
}
if (!changed) {
continue;
}
changed = false;
/*
* Update the group entry to reflect the changes.
} else if (is_member) {
/* User was not a member but is now a member this
* group.
*/
if (sgr_update (nsgrp) == 0) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, sgr_dbname (), nsgrp->sg_name);
SYSLOG ((LOG_WARN, "failed to prepare the new %s entry '%s'",
sgr_dbname (), nsgrp->sg_name));
fail_exit (E_GRP_UPDATE);
}
free (nsgrp);
nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_newname);
changed = true;
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"adding user to shadow group",
user_newname, AUDIT_NO_ID, 1);
#endif
SYSLOG ((LOG_INFO, "add '%s' to shadow group '%s'",
user_newname, nsgrp->sg_name));
}
if (!changed)
goto free_nsgrp;
/*
* Update the group entry to reflect the changes.
*/
if (sgr_update (nsgrp) == 0) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, sgr_dbname (), nsgrp->sg_name);
SYSLOG ((LOG_WARN, "failed to prepare the new %s entry '%s'",
sgr_dbname (), nsgrp->sg_name));
fail_exit (E_GRP_UPDATE);
}
free_nsgrp:
free (nsgrp);
}
#endif /* SHADOWGRP */
/*
* grp_update - add user to secondary group set
*
@@ -949,10 +966,10 @@ static void update_gshadow (void)
*/
static void grp_update (void)
{
update_group ();
update_group_file();
#ifdef SHADOWGRP
if (is_shadow_grp) {
update_gshadow ();
update_gshadow_file();
}
#endif
}
@@ -1061,7 +1078,7 @@ static void process_flags (int argc, char **argv)
eflg = true;
break;
case 'f':
if ( (getlong(optarg, &user_newinactive) == -1)
if ( (str2sl(&user_newinactive, optarg) == -1)
|| (user_newinactive < -1)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),