New upstream version 4.17.0~rc1

This commit is contained in:
Chris Hofstaedtler
2024-12-06 19:17:25 +01:00
parent 9f68246a01
commit f78a468368
858 changed files with 9076 additions and 13407 deletions
+3 -3
View File
@@ -26,7 +26,7 @@ AM_CFLAGS = $(LIBBSD_CFLAGS)
# and installation would be much simpler (just two directories,
# $prefix/bin and $prefix/sbin, no install-data hacks...)
bin_PROGRAMS = groups login
bin_PROGRAMS = login
sbin_PROGRAMS = nologin
ubin_PROGRAMS = faillog chage chfn chsh expiry gpasswd newgrp passwd
if ENABLE_SUBIDS
@@ -58,8 +58,8 @@ usbin_PROGRAMS = \
usermod \
vipw
# id and groups are from gnu, sulogin from sysvinit
noinst_PROGRAMS = id sulogin
# sulogin from sysvinit
noinst_PROGRAMS = sulogin
suidusbins =
suidbins =
+14 -40
View File
@@ -88,8 +88,7 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = groups$(EXEEXT) login$(EXEEXT) $(am__EXEEXT_1) \
$(am__EXEEXT_2)
bin_PROGRAMS = login$(EXEEXT) $(am__EXEEXT_1) $(am__EXEEXT_2)
sbin_PROGRAMS = nologin$(EXEEXT)
ubin_PROGRAMS = faillog$(EXEEXT) chage$(EXEEXT) chfn$(EXEEXT) \
chsh$(EXEEXT) expiry$(EXEEXT) gpasswd$(EXEEXT) newgrp$(EXEEXT) \
@@ -104,7 +103,7 @@ usbin_PROGRAMS = chgpasswd$(EXEEXT) chpasswd$(EXEEXT) \
pwck$(EXEEXT) pwconv$(EXEEXT) pwunconv$(EXEEXT) \
useradd$(EXEEXT) userdel$(EXEEXT) usermod$(EXEEXT) \
vipw$(EXEEXT)
noinst_PROGRAMS = id$(EXEEXT) sulogin$(EXEEXT) $(am__EXEEXT_3)
noinst_PROGRAMS = sulogin$(EXEEXT) $(am__EXEEXT_3)
@WITH_SU_TRUE@am__append_4 = su
@WITH_TCB_FALSE@am__append_5 = passwd
@ACCT_TOOLS_SETUID_TRUE@am__append_6 = chgpasswd chpasswd groupadd groupdel groupmod newusers useradd userdel usermod
@@ -250,11 +249,6 @@ groupmod_OBJECTS = groupmod.$(OBJEXT)
groupmod_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_3) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1)
groups_SOURCES = groups.c
groups_OBJECTS = groups.$(OBJEXT)
groups_LDADD = $(LDADD)
groups_DEPENDENCIES = $(am__DEPENDENCIES_1) \
$(top_builddir)/lib/libshadow.la $(am__DEPENDENCIES_1)
grpck_SOURCES = grpck.c
grpck_OBJECTS = grpck.$(OBJEXT)
grpck_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
@@ -267,11 +261,6 @@ grpunconv_SOURCES = grpunconv.c
grpunconv_OBJECTS = grpunconv.$(OBJEXT)
grpunconv_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
id_SOURCES = id.c
id_OBJECTS = id.$(OBJEXT)
id_LDADD = $(LDADD)
id_DEPENDENCIES = $(am__DEPENDENCIES_1) \
$(top_builddir)/lib/libshadow.la $(am__DEPENDENCIES_1)
lastlog_SOURCES = lastlog.c
lastlog_OBJECTS = lastlog.$(OBJEXT)
lastlog_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
@@ -386,10 +375,10 @@ am__depfiles_remade = ./$(DEPDIR)/chage.Po \
./$(DEPDIR)/getsubids-getsubids.Po ./$(DEPDIR)/gpasswd.Po \
./$(DEPDIR)/groupadd.Po ./$(DEPDIR)/groupdel.Po \
./$(DEPDIR)/groupmems.Po ./$(DEPDIR)/groupmod.Po \
./$(DEPDIR)/groups.Po ./$(DEPDIR)/grpck.Po \
./$(DEPDIR)/grpconv.Po ./$(DEPDIR)/grpunconv.Po \
./$(DEPDIR)/id.Po ./$(DEPDIR)/lastlog.Po ./$(DEPDIR)/login.Po \
./$(DEPDIR)/login_nopam.Po ./$(DEPDIR)/logoutd.Po \
./$(DEPDIR)/grpck.Po ./$(DEPDIR)/grpconv.Po \
./$(DEPDIR)/grpunconv.Po ./$(DEPDIR)/lastlog.Po \
./$(DEPDIR)/login.Po ./$(DEPDIR)/login_nopam.Po \
./$(DEPDIR)/logoutd.Po \
./$(DEPDIR)/new_subid_range-new_subid_range.Po \
./$(DEPDIR)/newgidmap.Po ./$(DEPDIR)/newgrp.Po \
./$(DEPDIR)/newuidmap.Po ./$(DEPDIR)/newusers.Po \
@@ -421,18 +410,18 @@ am__v_CCLD_1 =
SOURCES = chage.c check_subid_range.c chfn.c chgpasswd.c chpasswd.c \
chsh.c expiry.c faillog.c free_subid_range.c \
get_subid_owners.c getsubids.c gpasswd.c groupadd.c groupdel.c \
groupmems.c groupmod.c groups.c grpck.c grpconv.c grpunconv.c \
id.c lastlog.c $(login_SOURCES) logoutd.c new_subid_range.c \
newgidmap.c newgrp.c newuidmap.c newusers.c nologin.c passwd.c \
pwck.c pwconv.c pwunconv.c $(su_SOURCES) sulogin.c useradd.c \
groupmems.c groupmod.c grpck.c grpconv.c grpunconv.c lastlog.c \
$(login_SOURCES) logoutd.c new_subid_range.c newgidmap.c \
newgrp.c newuidmap.c newusers.c nologin.c passwd.c pwck.c \
pwconv.c pwunconv.c $(su_SOURCES) sulogin.c useradd.c \
userdel.c usermod.c vipw.c
DIST_SOURCES = chage.c check_subid_range.c chfn.c chgpasswd.c \
chpasswd.c chsh.c expiry.c faillog.c free_subid_range.c \
get_subid_owners.c getsubids.c gpasswd.c groupadd.c groupdel.c \
groupmems.c groupmod.c groups.c grpck.c grpconv.c grpunconv.c \
id.c lastlog.c $(login_SOURCES) logoutd.c new_subid_range.c \
newgidmap.c newgrp.c newuidmap.c newusers.c nologin.c passwd.c \
pwck.c pwconv.c pwunconv.c $(su_SOURCES) sulogin.c useradd.c \
groupmems.c groupmod.c grpck.c grpconv.c grpunconv.c lastlog.c \
$(login_SOURCES) logoutd.c new_subid_range.c newgidmap.c \
newgrp.c newuidmap.c newusers.c nologin.c passwd.c pwck.c \
pwconv.c pwunconv.c $(su_SOURCES) sulogin.c useradd.c \
userdel.c usermod.c vipw.c
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
@@ -489,7 +478,6 @@ EGREP = @EGREP@
ETAGS = @ETAGS@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
FILECMD = @FILECMD@
GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
GMSGFMT = @GMSGFMT@
GMSGFMT_015 = @GMSGFMT_015@
@@ -1064,10 +1052,6 @@ groupmod$(EXEEXT): $(groupmod_OBJECTS) $(groupmod_DEPENDENCIES) $(EXTRA_groupmod
@rm -f groupmod$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(groupmod_OBJECTS) $(groupmod_LDADD) $(LIBS)
groups$(EXEEXT): $(groups_OBJECTS) $(groups_DEPENDENCIES) $(EXTRA_groups_DEPENDENCIES)
@rm -f groups$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(groups_OBJECTS) $(groups_LDADD) $(LIBS)
grpck$(EXEEXT): $(grpck_OBJECTS) $(grpck_DEPENDENCIES) $(EXTRA_grpck_DEPENDENCIES)
@rm -f grpck$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(grpck_OBJECTS) $(grpck_LDADD) $(LIBS)
@@ -1080,10 +1064,6 @@ grpunconv$(EXEEXT): $(grpunconv_OBJECTS) $(grpunconv_DEPENDENCIES) $(EXTRA_grpun
@rm -f grpunconv$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(grpunconv_OBJECTS) $(grpunconv_LDADD) $(LIBS)
id$(EXEEXT): $(id_OBJECTS) $(id_DEPENDENCIES) $(EXTRA_id_DEPENDENCIES)
@rm -f id$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(id_OBJECTS) $(id_LDADD) $(LIBS)
lastlog$(EXEEXT): $(lastlog_OBJECTS) $(lastlog_DEPENDENCIES) $(EXTRA_lastlog_DEPENDENCIES)
@rm -f lastlog$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(lastlog_OBJECTS) $(lastlog_LDADD) $(LIBS)
@@ -1182,11 +1162,9 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/groupdel.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/groupmems.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/groupmod.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/groups.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grpck.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grpconv.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grpunconv.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/id.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lastlog.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/login.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/login_nopam.Po@am__quote@ # am--include-marker
@@ -1456,11 +1434,9 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/groupdel.Po
-rm -f ./$(DEPDIR)/groupmems.Po
-rm -f ./$(DEPDIR)/groupmod.Po
-rm -f ./$(DEPDIR)/groups.Po
-rm -f ./$(DEPDIR)/grpck.Po
-rm -f ./$(DEPDIR)/grpconv.Po
-rm -f ./$(DEPDIR)/grpunconv.Po
-rm -f ./$(DEPDIR)/id.Po
-rm -f ./$(DEPDIR)/lastlog.Po
-rm -f ./$(DEPDIR)/login.Po
-rm -f ./$(DEPDIR)/login_nopam.Po
@@ -1543,11 +1519,9 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/groupdel.Po
-rm -f ./$(DEPDIR)/groupmems.Po
-rm -f ./$(DEPDIR)/groupmod.Po
-rm -f ./$(DEPDIR)/groups.Po
-rm -f ./$(DEPDIR)/grpck.Po
-rm -f ./$(DEPDIR)/grpconv.Po
-rm -f ./$(DEPDIR)/grpunconv.Po
-rm -f ./$(DEPDIR)/id.Po
-rm -f ./$(DEPDIR)/lastlog.Po
-rm -f ./$(DEPDIR)/login.Po
-rm -f ./$(DEPDIR)/login_nopam.Po
+24 -31
View File
@@ -26,17 +26,18 @@
#endif /* ACCT_TOOLS_SETUID */
#include <pwd.h>
#include "alloc.h"
#include "atoi/str2i.h"
#include "atoi/a2i/a2s.h"
#include "defines.h"
#include "memzero.h"
#include "prototypes.h"
#include "pwio.h"
#include "shadowio.h"
#include "shadowlog.h"
#include "string/sprintf.h"
#include "string/memset/memzero.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
#include "string/strftime.h"
#include "string/strtcpy.h"
#include "time/day_to_str.h"
/*@-exitarg@*/
#include "exitcodes.h"
@@ -171,17 +172,13 @@ static int new_fields (void)
SNPRINTF(buf, "%ld", mindays);
change_field (buf, sizeof buf, _("Minimum Password Age"));
if ( (str2sl(&mindays, buf) == -1)
|| (mindays < -1)) {
if (a2sl(&mindays, buf, NULL, 0, -1, LONG_MAX) == -1)
return 0;
}
SNPRINTF(buf, "%ld", maxdays);
change_field (buf, sizeof buf, _("Maximum Password Age"));
if ( (str2sl(&maxdays, buf) == -1)
|| (maxdays < -1)) {
if (a2sl(&maxdays, buf, NULL, 0, -1, LONG_MAX) == -1)
return 0;
}
if (-1 == lstchgdate || lstchgdate > LONG_MAX / DAY)
strcpy(buf, "-1");
@@ -190,7 +187,7 @@ static int new_fields (void)
change_field (buf, sizeof buf, _("Last Password Change (YYYY-MM-DD)"));
if (strcmp (buf, "-1") == 0) {
if (streq(buf, "-1")) {
lstchgdate = -1;
} else {
lstchgdate = strtoday (buf);
@@ -201,17 +198,13 @@ static int new_fields (void)
SNPRINTF(buf, "%ld", warndays);
change_field (buf, sizeof buf, _("Password Expiration Warning"));
if ( (str2sl(&warndays, buf) == -1)
|| (warndays < -1)) {
if (a2sl(&warndays, buf, NULL, 0, -1, LONG_MAX) == -1)
return 0;
}
SNPRINTF(buf, "%ld", inactdays);
change_field (buf, sizeof buf, _("Password Inactive"));
if ( (str2sl(&inactdays, buf) == -1)
|| (inactdays < -1)) {
if (a2sl(&inactdays, buf, NULL, 0, -1, LONG_MAX) == -1)
return 0;
}
if (-1 == expdate || LONG_MAX / DAY < expdate)
strcpy(buf, "-1");
@@ -221,7 +214,7 @@ static int new_fields (void)
change_field (buf, sizeof buf,
_("Account Expiration Date (YYYY-MM-DD)"));
if (strcmp (buf, "-1") == 0) {
if (streq(buf, "-1")) {
expdate = -1;
} else {
expdate = strtoday (buf);
@@ -250,12 +243,16 @@ print_day_as_date(long day)
return;
}
if (gmtime_r(&date, &tm) == NULL) {
(void) printf ("time_t: %lu\n", (unsigned long)date);
if (localtime_r(&date, &tm) == NULL) {
puts(_("future"));
return;
}
if (STRFTIME(buf, iflg ? "%F" : "%b %d, %Y", &tm) == 0) {
puts(_("future"));
return;
}
STRFTIME(buf, iflg ? "%Y-%m-%d" : "%b %d, %Y", &tm);
(void) puts (buf);
}
@@ -397,8 +394,7 @@ static void process_flags (int argc, char **argv)
break;
case 'I':
Iflg = true;
if ( (str2sl(&inactdays, optarg) == -1)
|| (inactdays < -1)) {
if (a2sl(&inactdays, optarg, NULL, 0, -1, LONG_MAX) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -410,8 +406,7 @@ static void process_flags (int argc, char **argv)
break;
case 'm':
mflg = true;
if ( (str2sl(&mindays, optarg) == -1)
|| (mindays < -1)) {
if (a2sl(&mindays, optarg, NULL, 0, -1, LONG_MAX) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -420,8 +415,7 @@ static void process_flags (int argc, char **argv)
break;
case 'M':
Mflg = true;
if ( (str2sl(&maxdays, optarg) == -1)
|| (maxdays < -1)) {
if (a2sl(&maxdays, optarg, NULL, 0, -1, LONG_MAX) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -434,8 +428,7 @@ static void process_flags (int argc, char **argv)
break;
case 'W':
Wflg = true;
if ( (str2sl(&warndays, optarg) == -1)
|| (warndays < -1)) {
if (a2sl(&warndays, optarg, NULL, 0, -1, LONG_MAX) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -574,7 +567,7 @@ static void open_files (bool readonly)
/*
* For shadow password files we have to lock the file and read in
* the entries as was done for the password file. The user entries
* does not have to exist in this case; a new entry will be created
* do not have to exist in this case; a new entry will be created
* for this user if one does not exist already.
*/
if (!readonly) {
+12 -8
View File
@@ -6,27 +6,32 @@
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "atoi/str2i.h"
#include "atoi/getnum.h"
#include "atoi/str2i/str2u.h"
#include "defines.h"
#include "prototypes.h"
#include "subordinateio.h"
#include "idmapping.h"
#include "shadowlog.h"
static const char Prog[] = "check_subid_range";
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
char *owner;
unsigned long start, count;
bool check_uids;
bool check_uids;
char *owner;
uid_t start;
unsigned long count;
log_set_progname(Prog);
log_set_logfd(stderr);
@@ -35,8 +40,7 @@ int main(int argc, char **argv)
owner = argv[1];
check_uids = argv[2][0] == 'u';
errno = 0;
if (str2ul(&start, argv[3]) == -1)
if (get_uid(argv[3], &start) == -1)
exit(1);
if (str2ul(&count, argv[4]) == -1)
exit(1);
+20 -19
View File
@@ -18,22 +18,24 @@
#include <sys/types.h>
#include <getopt.h>
#include "alloc.h"
#include "chkname.h"
#include "defines.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "getdef.h"
#include "nscd.h"
#include "sssd.h"
#ifdef USE_PAM
#include "pam_defs.h"
#endif
#include "prototypes.h"
#include "pwauth.h"
#include "pwio.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/sprintf.h"
#include "string/strtcpy.h"
#include "sssd.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
/*
@@ -150,9 +152,9 @@ static bool may_change_field (int field)
cp = getdef_str ("CHFN_RESTRICT");
if (NULL == cp) {
cp = "";
} else if (strcmp (cp, "yes") == 0) {
} else if (streq(cp, "yes")) {
cp = "rwh";
} else if (strcmp (cp, "no") == 0) {
} else if (streq(cp, "no")) {
cp = "frwh";
}
@@ -214,32 +216,27 @@ static void new_fields (void)
*/
static char *copy_field (char *in, char *out, char *extra)
{
char *cp = NULL;
while (NULL != in) {
cp = strchr (in, ',');
if (NULL != cp) {
*cp++ = '\0';
}
char *f;
if (strchr (in, '=') == NULL) {
f = strsep(&in, ",");
if (strchr(f, '=') == NULL)
break;
}
if (NULL != extra) {
if ('\0' != extra[0]) {
strcat (extra, ",");
}
strcat (extra, in);
strcat(extra, f);
}
in = cp;
}
if ((NULL != in) && (NULL != out)) {
strcpy (out, in);
}
return cp;
return in;
}
/*
@@ -648,6 +645,10 @@ 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);
}
user = argv[optind];
pw = xgetpwnam (user);
if (NULL == pw) {
+25 -29
View File
@@ -22,7 +22,7 @@
#include "pam_defs.h"
#endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */
#include "atoi/str2i.h"
#include "atoi/str2i/str2s.h"
#include "defines.h"
#include "nscd.h"
#include "sssd.h"
@@ -34,6 +34,8 @@
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/strcmp/streq.h"
#include "string/strtok/stpsep.h"
/*
@@ -197,19 +199,19 @@ static void process_flags (int argc, char **argv)
usage (E_USAGE);
}
#if defined(USE_SHA_CRYPT)
if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512")))
if ( ( (streq(crypt_method, "SHA256") || streq(crypt_method, "SHA512"))
&& (-1 == str2sl(&sha_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (( (0 == strcmp (crypt_method, "BCRYPT"))
if (( streq(crypt_method, "BCRYPT")
&& (-1 == str2sl(&bcrypt_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
if (( streq(crypt_method, "YESCRYPT")
&& (-1 == str2sl(&yescrypt_cost, optarg)))) {
bad_s = 1;
}
@@ -258,18 +260,18 @@ static void check_flags (void)
}
if (cflg) {
if ( (0 != strcmp (crypt_method, "DES"))
&& (0 != strcmp (crypt_method, "MD5"))
&& (0 != strcmp (crypt_method, "NONE"))
if ( !streq(crypt_method, "DES")
&& !streq(crypt_method, "MD5")
&& !streq(crypt_method, "NONE")
#ifdef USE_SHA_CRYPT
&& (0 != strcmp (crypt_method, "SHA256"))
&& (0 != strcmp (crypt_method, "SHA512"))
&& !streq(crypt_method, "SHA256")
&& !streq(crypt_method, "SHA512")
#endif /* USE_SHA_CRYPT */
#ifdef USE_BCRYPT
&& (0 != strcmp (crypt_method, "BCRYPT"))
&& !streq(crypt_method, "BCRYPT")
#endif /* USE_BCRYPT */
#ifdef USE_YESCRYPT
&& (0 != strcmp (crypt_method, "YESCRYPT"))
&& !streq(crypt_method, "YESCRYPT")
#endif /* USE_YESCRYPT */
) {
fprintf (stderr,
@@ -460,10 +462,7 @@ int main (int argc, char **argv)
*/
while (fgets (buf, (int) sizeof buf, stdin) != NULL) {
line++;
cp = strrchr (buf, '\n');
if (NULL != cp) {
*cp = '\0';
} else {
if (stpsep(buf, "\n") == NULL) {
fprintf (stderr, _("%s: line %d: line too long\n"),
Prog, line);
errors++;
@@ -480,11 +479,8 @@ int main (int argc, char **argv)
*/
name = buf;
cp = strchr (name, ':');
if (NULL != cp) {
*cp = '\0';
cp++;
} else {
cp = stpsep(name, ":");
if (cp == NULL) {
fprintf (stderr,
_("%s: line %d: missing new password\n"),
Prog, line);
@@ -494,7 +490,7 @@ int main (int argc, char **argv)
newpwd = cp;
if ( (!eflg)
&& ( (NULL == crypt_method)
|| (0 != strcmp (crypt_method, "NONE")))) {
|| !streq(crypt_method, "NONE"))) {
void *arg = NULL;
const char *salt;
if (md5flg) {
@@ -503,18 +499,18 @@ int main (int argc, char **argv)
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
if (sflg) {
#if defined(USE_SHA_CRYPT)
if ( (0 == strcmp (crypt_method, "SHA256"))
|| (0 == strcmp (crypt_method, "SHA512"))) {
if ( streq(crypt_method, "SHA256")
|| streq(crypt_method, "SHA512")) {
arg = &sha_rounds;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (0 == strcmp (crypt_method, "BCRYPT")) {
if (streq(crypt_method, "BCRYPT")) {
arg = &bcrypt_rounds;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (0 == strcmp (crypt_method, "YESCRYPT")) {
if (streq(crypt_method, "YESCRYPT")) {
arg = &yescrypt_cost;
}
#endif /* USE_YESCRYPT */
@@ -553,8 +549,8 @@ int main (int argc, char **argv)
sg = sgr_locate (name);
if ( (NULL == sg)
&& (strcmp (gr->gr_passwd,
SHADOW_PASSWD_STRING) == 0)) {
&& streq(gr->gr_passwd, SHADOW_PASSWD_STRING))
{
static char *empty = NULL;
/* If the password is set to 'x' in
* group, but there are no entries in
@@ -581,7 +577,7 @@ int main (int argc, char **argv)
newsg.sg_passwd = cp;
}
if ( (NULL == sg)
|| (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0))
|| !streq(gr->gr_passwd, SHADOW_PASSWD_STRING))
#endif
{
newgr = *gr;
@@ -604,7 +600,7 @@ int main (int argc, char **argv)
}
}
if ( (NULL == sg)
|| (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0))
|| !streq(gr->gr_passwd, SHADOW_PASSWD_STRING))
#endif
{
if (gr_update (&newgr) == 0) {
+11 -16
View File
@@ -20,7 +20,7 @@
#ifdef USE_PAM
#include "pam_defs.h"
#endif /* USE_PAM */
#include "atoi/str2i.h"
#include "atoi/str2i/str2s.h"
#include "defines.h"
#include "nscd.h"
#include "sssd.h"
@@ -31,9 +31,11 @@
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/strcmp/streq.h"
#include "string/strtok/stpsep.h"
#define IS_CRYPT_METHOD(str) ((crypt_method != NULL && strcmp(crypt_method, str) == 0) ? true : false)
#define IS_CRYPT_METHOD(str) ((crypt_method != NULL && streq(crypt_method, str)) ? true : false)
/*
* Global variables
@@ -501,12 +503,8 @@ int main (int argc, char **argv)
*/
while (fgets (buf, sizeof buf, stdin) != NULL) {
line++;
cp = strrchr (buf, '\n');
if (NULL != cp) {
*cp = '\0';
} else {
if (stpsep(buf, "\n") == NULL) {
if (feof (stdin) == 0) {
// Drop all remaining characters on this line.
while (fgets (buf, sizeof buf, stdin) != NULL) {
cp = strchr (buf, '\n');
@@ -533,11 +531,8 @@ int main (int argc, char **argv)
*/
name = buf;
cp = strchr (name, ':');
if (NULL != cp) {
*cp = '\0';
cp++;
} else {
cp = stpsep(name, ":");
if (cp == NULL) {
fprintf (stderr,
_("%s: line %d: missing new password\n"),
Prog, line);
@@ -594,8 +589,8 @@ int main (int argc, char **argv)
sp = spw_locate (name);
if ( (NULL == sp)
&& (strcmp (pw->pw_passwd,
SHADOW_PASSWD_STRING) == 0)) {
&& streq(pw->pw_passwd, SHADOW_PASSWD_STRING))
{
/* If the password is set to 'x' in
* passwd, but there are no entries in
* shadow, create one.
@@ -632,7 +627,7 @@ int main (int argc, char **argv)
}
if ( (NULL == sp)
|| (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) != 0)) {
|| !streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) {
newpw = *pw;
newpw.pw_passwd = cp;
}
@@ -652,7 +647,7 @@ int main (int argc, char **argv)
}
}
if ( (NULL == sp)
|| (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) != 0)) {
|| !streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) {
if (pw_update (&newpw) == 0) {
fprintf (stderr,
_("%s: line %d: failed to prepare the new %s entry '%s'\n"),
+16 -8
View File
@@ -17,21 +17,24 @@
#include <stdio.h>
#include <sys/types.h>
#include "alloc.h"
#include "chkname.h"
#include "defines.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "getdef.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#include "pwauth.h"
#include "pwio.h"
#ifdef USE_PAM
#include "pam_defs.h"
#endif
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/strtcpy.h"
#include "sssd.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
#ifndef SHELLS_FILE
#define SHELLS_FILE "/etc/shells"
@@ -43,6 +46,7 @@
#define ETCDIR "/etc"
#endif
/*
* Global variables
*/
@@ -176,7 +180,7 @@ static bool shell_is_listed (const char *sh)
}
for (size_t i = 0; i < size; i++) {
if (strcmp (keys[i], sh) == 0) {
if (streq(keys[i], sh)) {
found = true;
break;
}
@@ -197,7 +201,7 @@ static bool shell_is_listed (const char *sh)
char *cp;
setusershell ();
while ((cp = getusershell ())) {
if (strcmp (cp, sh) == 0) {
if (streq(cp, sh)) {
found = true;
break;
}
@@ -218,7 +222,7 @@ static bool shell_is_listed (const char *sh)
continue;
}
if (strcmp (buf, sh) == 0) {
if (streq(buf, sh)) {
found = true;
break;
}
@@ -498,6 +502,10 @@ 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);
}
user = argv[optind];
pw = xgetpwnam (user);
if (NULL == pw) {
+4 -8
View File
@@ -19,14 +19,14 @@
#include <time.h>
#include <assert.h>
#include "atoi/str2i.h"
#include "atoi/str2i/str2s.h"
#include "defines.h"
#include "faillog.h"
#include "memzero.h"
#include "prototypes.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/memset/memzero.h"
#include "string/strftime.h"
@@ -154,7 +154,7 @@ static void print_one (/*@null@*/const struct passwd *pw, bool force)
return;
}
(void) time(&now);
now = time(NULL);
/* Filter out entries that do not match with the -t option */
if (tflg && ((now - fl.fail_time) > seconds)) {
@@ -557,16 +557,12 @@ int main (int argc, char **argv)
break;
case 'm':
{
long lmax;
if ( (str2sl(&lmax, optarg) == -1)
|| ((long)(short) lmax != lmax)) {
if (str2sh(&fail_max, optarg) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
exit (E_BAD_ARG);
}
fail_max = lmax;
mflg = true;
break;
}
+6 -2
View File
@@ -1,12 +1,16 @@
/* SPDX-License-Identifier: BSD-3-Clause */
#include <stdio.h>
#include <unistd.h>
#include "atoi/str2i/str2u.h"
#include "subid.h"
#include "stdlib.h"
#include "prototypes.h"
#include "shadowlog.h"
/* Test program for the subid freeing routine */
static const char Prog[] = "free_subid_range";
@@ -38,8 +42,8 @@ int main(int argc, char *argv[])
if (argc < 3)
usage();
range.owner = argv[0];
range.start = atoi(argv[1]);
range.count = atoi(argv[2]);
str2ul(&range.start, argv[1]);
str2ul(&range.count, argv[2]);
if (group)
ok = subid_ungrant_gid_range(&range);
else
+19 -9
View File
@@ -1,13 +1,19 @@
/* SPDX-License-Identifier: BSD-3-Clause */
#include <stdio.h>
#include "subid.h"
#include "stdlib.h"
#include "atoi/getnum.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "stdlib.h"
#include "string/strcmp/streq.h"
#include "subid.h"
static const char Prog[] = "get_subid_owners";
static void usage(void)
{
fprintf(stderr, "Usage: [-g] %s subuid\n", Prog);
@@ -18,20 +24,24 @@ static void usage(void)
int main(int argc, char *argv[])
{
int i, n;
uid_t *uids;
int i, n;
uid_t u;
uid_t *uids;
log_set_progname(Prog);
log_set_logfd(stderr);
if (argc < 2) {
usage();
}
if (argc == 3 && strcmp(argv[1], "-g") == 0)
n = subid_get_gid_owners(atoi(argv[2]), &uids);
else if (argc == 2 && strcmp(argv[1], "-h") == 0)
if (argc == 3 && streq(argv[1], "-g")) {
get_uid(argv[2], &u);
n = subid_get_gid_owners(u, &uids);
} else if (argc == 2 && streq(argv[1], "-h")) {
usage();
else
n = subid_get_uid_owners(atoi(argv[1]), &uids);
} else {
get_gid(argv[1], &u);
n = subid_get_uid_owners(u, &uids);
}
if (n < 0) {
fprintf(stderr, "No owners found\n");
exit(1);
+7 -5
View File
@@ -1,11 +1,13 @@
/* SPDX-License-Identifier: BSD-3-Clause */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "subid.h"
#include <string.h>
#include "prototypes.h"
#include "shadowlog.h"
#include "string/strcmp/streq.h"
#include "subid.h"
static const char Prog[] = "getsubids";
@@ -28,10 +30,10 @@ int main(int argc, char *argv[])
if (argc < 2)
usage();
owner = argv[1];
if (argc == 3 && strcmp(argv[1], "-g") == 0) {
if (argc == 3 && streq(argv[1], "-g")) {
owner = argv[2];
count = subid_get_gid_ranges(owner, &ranges);
} else if (argc == 2 && strcmp(argv[1], "-h") == 0) {
} else if (argc == 2 && streq(argv[1], "-h")) {
usage();
} else {
count = subid_get_uid_ranges(owner, &ranges);
@@ -44,6 +46,6 @@ int main(int argc, char *argv[])
printf("%d: %s %lu %lu\n", i, owner,
ranges[i].start, ranges[i].count);
}
free(ranges);
subid_free(ranges);
return 0;
}
+23 -55
View File
@@ -21,22 +21,24 @@
#include <sys/types.h>
#include "agetpass.h"
#include "alloc.h"
#include "alloc/x/xmalloc.h"
#include "attr.h"
#include "defines.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "groupio.h"
#include "memzero.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#ifdef SHADOWGRP
#include "sgroupio.h"
#endif
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/sprintf.h"
#include "string/strtcpy.h"
#include "sssd.h"
#include "string/memset/memzero.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
/*
@@ -172,33 +174,29 @@ static void catch_signals (int killed)
*/
static bool is_valid_user_list (const char *users)
{
const char *username;
char *end;
bool is_valid = true;
/*@owned@*/char *tmpusers = xstrdup (users);
char *dup, *tmpusers;
for (username = tmpusers;
(NULL != username) && ('\0' != *username);
username = end) {
end = strchr (username, ',');
if (NULL != end) {
*end = '\0';
end++;
}
tmpusers = dup = xstrdup(users);
while (NULL != tmpusers && '\0' != *tmpusers) {
const char *u;
u = strsep(&tmpusers, ",");
/*
* This user must exist.
*/
/* local, no need for xgetpwnam */
if (getpwnam (username) == NULL) {
if (getpwnam(u) == NULL) {
fprintf (stderr, _("%s: user '%s' does not exist\n"),
Prog, username);
Prog, u);
is_valid = false;
}
}
free (tmpusers);
free(dup);
return is_valid;
}
@@ -687,30 +685,8 @@ static void check_perms (const struct group *gr)
}
} else
#endif /* SHADOWGRP */
if (!amroot) {
/*
* The policy here for changing a group is that
* 1) you must be root or
* 2) you must be the first listed member of the group.
* The first listed member of a group can do anything to
* that group that the root user can. The rationale for
* this hack is that the FIRST user is probably the most
* important user in this entire group.
*
* This feature enabled by default could be a security
* problem when installed on existing systems where the
* first group member might be just a normal user.
* --marekm
*/
#if !defined(FIRST_MEMBER_IS_ADMIN)
if (!amroot)
failure();
#endif
if (gr->gr_mem[0] == NULL)
failure();
if (strcmp(gr->gr_mem[0], myname) != 0)
failure();
}
}
/*
@@ -810,16 +786,8 @@ static void get_group (struct group *gr)
sg->sg_mem = dup_list (gr->gr_mem);
sg->sg_adm = XMALLOC(2, char *);
#ifdef FIRST_MEMBER_IS_ADMIN
if (sg->sg_mem[0]) {
sg->sg_adm[0] = xstrdup (sg->sg_mem[0]);
sg->sg_adm[1] = NULL;
} else
#endif
{
sg->sg_adm[0] = NULL;
}
sg->sg_adm = XMALLOC(1, char *);
sg->sg_adm[0] = NULL;
}
if (sgr_close () == 0) {
@@ -876,7 +844,7 @@ static void change_passwd (struct group *gr)
exit (1);
}
if (strcmp (pass, cp) == 0) {
if (streq(pass, cp)) {
erase_pass (cp);
break;
}
+33 -27
View File
@@ -16,6 +16,7 @@
#include <getopt.h>
#include <grp.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
@@ -23,19 +24,23 @@
#include <pwd.h>
#endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */
#include "atoi/getnum.h"
#include "chkname.h"
#include "defines.h"
#include "getdef.h"
#include "groupio.h"
#include "memzero.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#include "run_part.h"
#ifdef SHADOWGRP
#include "sgroupio.h"
#endif
#include "shadowlog.h"
#include "run_part.h"
#include "string/memset/memzero.h"
#include "string/strtok/stpsep.h"
/*
* exit status values
@@ -160,7 +165,8 @@ static void new_sgent (struct sgrp *sgent)
*
* grp_update() writes the new records to the group files.
*/
static void grp_update (void)
static void
grp_update(void)
{
struct group grp;
@@ -192,15 +198,20 @@ static void grp_update (void)
#endif /* SHADOWGRP */
if (user_list) {
char *token;
token = strtok(user_list, ",");
while (token) {
if (prefix_getpwnam (token) == NULL) {
fprintf (stderr, _("Invalid member username %s\n"), token);
char *u, *ul;
ul = user_list;
while (NULL != (u = strsep(&ul, ","))) {
if (prefix_getpwnam(u) == NULL) {
fprintf(stderr, _("Invalid member username %s\n"), u);
exit (E_GRP_UPDATE);
}
grp.gr_mem = add_list(grp.gr_mem, token);
token = strtok(NULL, ",");
grp.gr_mem = add_list(grp.gr_mem, u);
#ifdef SHADOWGRP
if (is_shadow_grp)
sgrp.sg_mem = add_list(sgrp.sg_mem, u);
#endif
}
}
@@ -232,20 +243,17 @@ static void grp_update (void)
* check_new_name() insures that the new name doesn't contain any
* illegal characters.
*/
static void check_new_name (void)
static void
check_new_name(void)
{
if (is_valid_group_name (group_name)) {
return;
if (!is_valid_group_name(group_name)) {
fprintf(stderr, _("%s: '%s' is not a valid group name\n"),
Prog, group_name);
exit(E_BAD_ARG);
}
/*
* All invalid group names land here.
*/
fprintf (stderr, _("%s: '%s' is not a valid group name\n"),
Prog, group_name);
exit (E_BAD_ARG);
return;
}
/*
@@ -420,15 +428,13 @@ static void process_flags (int argc, char **argv)
* example: -K GID_MIN=100 -K GID_MAX=499
* note: -K GID_MIN=10,GID_MAX=499 doesn't work yet
*/
cp = strchr (optarg, '=');
cp = stpsep(optarg, "=");
if (NULL == cp) {
fprintf (stderr,
_("%s: -K requires KEY=VALUE\n"),
Prog);
exit (E_BAD_ARG);
}
/* terminate name, point to value */
*cp++ = '\0';
if (putdef_str (optarg, cp, NULL) < 0) {
exit (E_BAD_ARG);
}
@@ -481,11 +487,11 @@ static void check_flags (void)
check_new_name ();
/*
* Check if the group already exist.
* Check if the group already exists.
*/
/* local, no need for xgetgrnam */
if (prefix_getgrnam (group_name) != NULL) {
/* The group already exist */
/* The group already exists */
if (fflg) {
/* OK, no need to do anything */
exit (E_SUCCESS);
@@ -497,7 +503,7 @@ static void check_flags (void)
}
if (gflg && (prefix_getgrgid (group_id) != NULL)) {
/* A GID was specified, and a group already exist with that GID
/* A GID was specified, and a group already exists with that GID
* - either we will use this GID anyway (-o)
* - either we ignore the specified GID and
* we will use another one (-f)
+8 -21
View File
@@ -19,14 +19,17 @@
#endif /* USE_PAM */
#include <pwd.h>
#include "alloc.h"
#include "alloc/x/xmalloc.h"
#include "defines.h"
#include "prototypes.h"
#include "groupio.h"
#include "prototypes.h"
#ifdef SHADOWGRP
#include "sgroupio.h"
#endif
#include "shadowlog.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
/* Exit Status Values */
/*@-exitarg@*/
@@ -83,7 +86,7 @@ static char *whoami (void)
if ( (NULL != usr)
&& (NULL != grp)
&& (0 == strcmp (usr->pw_name, grp->gr_name))) {
&& streq(usr->pw_name, grp->gr_name)) {
return xstrdup (usr->pw_name);
} else {
return NULL;
@@ -128,15 +131,7 @@ static void add_user (const char *user,
sgrent.sg_name = xstrdup (newgrp->gr_name);
sgrent.sg_mem = dup_list (newgrp->gr_mem);
sgrent.sg_adm = XMALLOC(1, char *);
#ifdef FIRST_MEMBER_IS_ADMIN
if (sgrent.sg_mem[0]) {
sgrent.sg_adm[0] = xstrdup (sgrent.sg_mem[0]);
sgrent.sg_adm[1] = NULL;
} else
#endif
{
sgrent.sg_adm[0] = NULL;
}
sgrent.sg_adm[0] = NULL;
/* Move any password to gshadow */
sgrent.sg_passwd = newgrp->gr_passwd;
@@ -211,15 +206,7 @@ static void remove_user (const char *user,
sgrent.sg_name = xstrdup (newgrp->gr_name);
sgrent.sg_mem = dup_list (newgrp->gr_mem);
sgrent.sg_adm = XMALLOC(1, char *);
#ifdef FIRST_MEMBER_IS_ADMIN
if (sgrent.sg_mem[0]) {
sgrent.sg_adm[0] = xstrdup (sgrent.sg_mem[0]);
sgrent.sg_adm[1] = NULL;
} else
#endif
{
sgrent.sg_adm[0] = NULL;
}
sgrent.sg_adm[0] = NULL;
/* Move any password to gshadow */
sgrent.sg_passwd = newgrp->gr_passwd;
+58 -42
View File
@@ -17,6 +17,7 @@
#include <grp.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#ifdef ACCT_TOOLS_SETUID
@@ -26,20 +27,25 @@
#endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */
#include "alloc.h"
#include "alloc/x/xmalloc.h"
#include "atoi/getnum.h"
#include "chkname.h"
#include "defines.h"
#include "groupio.h"
#include "pwio.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#include "pwio.h"
#ifdef SHADOWGRP
#include "sgroupio.h"
#endif
#include "shadowlog.h"
#include "string/stpecpy.h"
#include "string/stpeprintf.h"
#include "sssd.h"
#include "string/sprintf/stpeprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/stpecpy.h"
#include "string/strdup/xstrdup.h"
/*
* exit status values
*/
@@ -150,7 +156,7 @@ static void new_grent (struct group *grent)
if ( pflg
#ifdef SHADOWGRP
&& ( (!is_shadow_grp)
|| (strcmp (grent->gr_passwd, SHADOW_PASSWD_STRING) != 0))
|| !streq(grent->gr_passwd, SHADOW_PASSWD_STRING))
#endif
) {
/* Update the password in group if there is no gshadow
@@ -193,7 +199,8 @@ static void new_sgent (struct sgrp *sgent)
*
* grp_update() updates the new records in the memory databases.
*/
static void grp_update (void)
static void
grp_update(void)
{
struct group grp;
const struct group *ogrp;
@@ -217,13 +224,13 @@ static void grp_update (void)
new_grent (&grp);
#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg)) {
&& (pflg || nflg || user_list)) {
osgrp = sgr_locate (group_name);
if (NULL != osgrp) {
sgrp = *osgrp;
new_sgent (&sgrp);
} else if ( pflg
&& (strcmp (grp.gr_passwd, SHADOW_PASSWD_STRING) == 0)) {
&& streq(grp.gr_passwd, SHADOW_PASSWD_STRING)) {
static char *empty = NULL;
/* If there is a gshadow file with no entries for
* the group, but the group file indicates a
@@ -246,7 +253,7 @@ static void grp_update (void)
}
if (user_list) {
char *token;
char *u, *ul;
if (!aflg) {
// requested to replace the existing groups
@@ -257,15 +264,30 @@ static void grp_update (void)
if (NULL != grp.gr_mem[0])
grp.gr_mem = dup_list (grp.gr_mem);
}
#ifdef SHADOWGRP
if (NULL != osgrp) {
if (!aflg) {
sgrp.sg_mem = XMALLOC(1, char *);
sgrp.sg_mem[0] = NULL;
} else {
if (NULL != sgrp.sg_mem[0])
sgrp.sg_mem = dup_list(sgrp.sg_mem);
}
}
#endif /* SHADOWGRP */
token = strtok(user_list, ",");
while (token) {
if (prefix_getpwnam (token) == NULL) {
fprintf (stderr, _("Invalid member username %s\n"), token);
ul = user_list;
while (NULL != (u = strsep(&ul, ","))) {
if (prefix_getpwnam(u) == NULL) {
fprintf(stderr, _("Invalid member username %s\n"), u);
exit (E_GRP_UPDATE);
}
grp.gr_mem = add_list(grp.gr_mem, token);
token = strtok(NULL, ",");
grp.gr_mem = add_list(grp.gr_mem, u);
#ifdef SHADOWGRP
if (NULL != osgrp)
sgrp.sg_mem = add_list(sgrp.sg_mem, u);
#endif /* SHADOWGRP */
}
}
@@ -347,39 +369,33 @@ static void check_new_gid (void)
* check_new_name() insures that the new name does not exist already.
* You can't have the same name twice, period.
*/
static void check_new_name (void)
static void
check_new_name(void)
{
/*
* Make sure they are actually changing the name.
*/
if (strcmp (group_name, group_newname) == 0) {
if (streq(group_name, group_newname)) {
nflg = 0;
return;
}
if (is_valid_group_name (group_newname)) {
/*
* If the entry is found, too bad.
*/
/* local, no need for xgetgrnam */
if (prefix_getgrnam (group_newname) != NULL) {
fprintf (stderr,
_("%s: group '%s' already exists\n"),
Prog, group_newname);
exit (E_NAME_IN_USE);
}
return;
if (!is_valid_group_name(group_newname)) {
fprintf(stderr,
_("%s: invalid group name '%s'\n"),
Prog, group_newname);
exit(E_BAD_ARG);
}
/*
* All invalid group names land here.
*/
/* local, no need for xgetgrnam */
if (prefix_getgrnam(group_newname) != NULL) {
fprintf(stderr,
_("%s: group '%s' already exists\n"),
Prog, group_newname);
exit(E_NAME_IN_USE);
}
fprintf (stderr,
_("%s: invalid group name '%s'\n"),
Prog, group_newname);
exit (E_BAD_ARG);
return;
}
/*
@@ -487,7 +503,7 @@ static void close_files (void)
#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg)) {
&& (pflg || nflg || user_list)) {
if (sgr_close () == 0) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"),
@@ -619,7 +635,7 @@ static void prepare_failure_reports (void)
add_cleanup (cleanup_report_mod_group, &info_group);
#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg)) {
&& (pflg || nflg || user_list)) {
add_cleanup (cleanup_report_mod_gshadow, &info_gshadow);
}
#endif
@@ -646,7 +662,7 @@ static void lock_files (void)
#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg)) {
&& (pflg || nflg || user_list)) {
if (sgr_lock () == 0) {
fprintf (stderr,
_("%s: cannot lock %s; try again later.\n"),
@@ -684,7 +700,7 @@ static void open_files (void)
#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg)) {
&& (pflg || nflg || user_list)) {
if (sgr_open (O_CREAT | O_RDWR) == 0) {
fprintf (stderr,
_("%s: cannot open %s\n"),
-178
View File
@@ -1,178 +0,0 @@
/*
* SPDX-FileCopyrightText: 1991 - 1993, Julianne Frances Haugh
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
* SPDX-FileCopyrightText: 2001 - 2006, Tomasz Kłoczko
* SPDX-FileCopyrightText: 2007 - 2008, Nicolas François
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <config.h>
#ident "$Id$"
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include "alloc.h"
#include "defines.h"
#include "prototypes.h"
#include "shadowlog.h"
/*
* Global variables
*/
static const char Prog[] = "groups";
/* local function prototypes */
static void print_groups (const char *member);
/*
* print_groups - print the groups which the named user is a member of
*
* print_groups() scans the groups file for the list of groups which
* the user is listed as being a member of.
*/
static void print_groups (const char *member)
{
int groups = 0;
struct group *grp;
struct passwd *pwd;
bool flag = false;
pwd = getpwnam (member); /* local, no need for xgetpwnam */
if (NULL == pwd) {
(void) fprintf (stderr, _("%s: unknown user %s\n"),
Prog, member);
exit (EXIT_FAILURE);
}
setgrent ();
while ((grp = getgrent ()) != NULL) {
if (is_on_list (grp->gr_mem, member)) {
if (0 != groups) {
(void) putchar (' ');
}
groups++;
(void) printf ("%s", grp->gr_name);
if (grp->gr_gid == pwd->pw_gid) {
flag = true;
}
}
}
endgrent ();
/* The user may not be in the list of members of its primary group */
if (!flag) {
grp = getgrgid (pwd->pw_gid); /* local, no need for xgetgrgid */
if (NULL != grp) {
if (0 != groups) {
(void) putchar (' ');
}
groups++;
(void) printf ("%s", grp->gr_name);
}
}
if (0 != groups) {
(void) putchar ('\n');
}
}
/*
* groups - print out the groups a process is a member of
*/
int main (int argc, char **argv)
{
long sys_ngroups;
GETGROUPS_T *groups;
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
groups = XMALLOC(sys_ngroups, GETGROUPS_T);
(void) setlocale (LC_ALL, "");
(void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE);
log_set_progname(Prog);
log_set_logfd(stderr);
if (argc == 1) {
/*
* Called with no arguments - give the group set for the
* current user.
*/
int i;
int pri_grp; /* TODO: should be GETGROUPS_T */
/*
* This system supports concurrent group sets, so I can ask
* the system to tell me which groups are currently set for
* this process.
*/
int ngroups = getgroups (sys_ngroups, groups);
if (ngroups < 0) {
perror ("getgroups");
exit (EXIT_FAILURE);
}
/*
* The groupset includes the primary group as well.
*/
pri_grp = getegid ();
for (i = 0; i < ngroups; i++) {
if (pri_grp == (int) groups[i]) {
break;
}
}
if (i != ngroups) {
pri_grp = -1;
}
/*
* Print out the name of every group in the current group
* set. Unknown groups are printed as their decimal group ID
* values.
*/
if (-1 != pri_grp) {
struct group *gr;
/* local, no need for xgetgrgid */
gr = getgrgid (pri_grp);
if (NULL != gr) {
(void) printf ("%s", gr->gr_name);
} else {
(void) printf ("%d", pri_grp);
}
}
for (i = 0; i < ngroups; i++) {
struct group *gr;
if ((0 != i) || (-1 != pri_grp)) {
(void) putchar (' ');
}
/* local, no need for xgetgrgid */
gr = getgrgid (groups[i]);
if (NULL != gr) {
(void) printf ("%s", gr->gr_name);
} else {
(void) printf ("%ld", (long) groups[i]);
}
}
(void) putchar ('\n');
} else {
/*
* The invoker wanted to know about some other user. Use
* that name to look up the groups instead.
*/
print_groups (argv[1]);
}
return EXIT_SUCCESS;
}
+7 -5
View File
@@ -15,14 +15,16 @@
#include <pwd.h>
#include <stdio.h>
#include <getopt.h>
#include "chkname.h"
#include "commonio.h"
#include "defines.h"
#include "groupio.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "sssd.h"
#include "string/strcmp/streq.h"
#ifdef SHADOWGRP
#include "sgroupio.h"
@@ -436,7 +438,7 @@ static void compare_members_lists (const char *groupname,
for (pmem = members; NULL != *pmem; pmem++) {
for (other_pmem = other_members; NULL != *other_pmem; other_pmem++) {
if (strcmp (*pmem, *other_pmem) == 0) {
if (streq(*pmem, *other_pmem)) {
break;
}
}
@@ -535,7 +537,7 @@ static void check_grp_file (int *errors, bool *changed)
continue;
}
if (strcmp (grp->gr_name, ent->gr_name) != 0) {
if (!streq(grp->gr_name, ent->gr_name)) {
continue;
}
@@ -647,7 +649,7 @@ static void check_grp_file (int *errors, bool *changed)
/* The group entry has a gshadow counterpart.
* Make sure no passwords are in group.
*/
if (strcmp (grp->gr_passwd, SHADOW_PASSWD_STRING) != 0) {
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"),
grp->gr_name, sgr_file, grp_file);
*errors += 1;
@@ -737,7 +739,7 @@ static void check_sgr_file (int *errors, bool *changed)
continue;
}
if (strcmp (sgr->sg_name, ent->sg_name) != 0) {
if (!streq(sgr->sg_name, ent->sg_name)) {
continue;
}
+10 -6
View File
@@ -17,6 +17,7 @@
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
@@ -24,18 +25,21 @@
#include <strings.h>
#include <time.h>
#include <unistd.h>
#include <getopt.h>
#include "attr.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "nscd.h"
#include "prototypes.h"
#include "string/strcmp/streq.h"
#ifdef SHADOWGRP
#include "groupio.h"
#include "sgroupio.h"
#include "shadowlog.h"
#include "sssd.h"
/*
* Global variables
*/
@@ -194,10 +198,10 @@ int main (int argc, char **argv)
if (NULL != sg) {
/* update existing shadow group entry */
sgent = *sg;
if (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0)
if (!streq(gr->gr_passwd, SHADOW_PASSWD_STRING))
sgent.sg_passwd = gr->gr_passwd;
} else {
static char *empty = 0;
static char *empty = NULL;
/* add new shadow group entry */
bzero(&sgent, sizeof sgent);
+8 -4
View File
@@ -26,15 +26,19 @@
#include <getopt.h>
#include "attr.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "nscd.h"
#include "prototypes.h"
#include "sssd.h"
#include "string/strcmp/streq.h"
#ifdef SHADOWGRP
#include "groupio.h"
#include "sgroupio.h"
#include "shadowlog.h"
/*
* Global variables
*/
@@ -174,7 +178,7 @@ int main (int argc, char **argv)
while ((gr = gr_next ()) != NULL) {
sg = sgr_locate (gr->gr_name);
if ( (NULL != sg)
&& (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) == 0)) {
&& streq(gr->gr_passwd, SHADOW_PASSWD_STRING)) {
/* add password to /etc/group */
grent = *gr;
grent.gr_passwd = sg->sg_passwd;
-175
View File
@@ -1,175 +0,0 @@
/*
* SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
* SPDX-FileCopyrightText: 2001 - 2006, Tomasz Kłoczko
* SPDX-FileCopyrightText: 2007 - 2008, Nicolas François
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* id - print current process user identification information
*
* Print the current process identifiers. This includes the
* UID, GID, effective-UID and effective-GID. Optionally print
* the concurrent group set if the current system supports it.
*/
#include <config.h>
#ident "$Id$"
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <sys/types.h>
#include "alloc.h"
#include "defines.h"
/* local function prototypes */
static void usage (void);
static void usage (void)
{
(void) fputs (_("Usage: id [-a]\n"), stderr);
exit (EXIT_FAILURE);
}
int
main(int argc, char *argv[])
{
uid_t ruid, euid;
gid_t rgid, egid;
long sys_ngroups;
/*
* This block of declarations is particularly strained because of several
* different ways of doing concurrent groups. Old BSD systems used int for
* gid's, but short for the type passed to getgroups(). Newer systems use
* gid_t for everything. Some systems have a small and fixed NGROUPS,
* usually about 16 or 32. Others use bigger values.
*/
GETGROUPS_T *groups;
int ngroups;
bool aflg = 0;
struct passwd *pw;
struct group *gr;
(void) setlocale (LC_ALL, "");
(void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE);
/*
* Dynamically get the maximum number of groups from system, instead
* of using the symbolic constant NGROUPS_MAX. This ensures that the
* group limit is not hard coded into the binary, so it will still
* work if the system library is recompiled.
*/
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
groups = MALLOC(sys_ngroups, GETGROUPS_T);
/*
* See if the -a flag has been given to print out the concurrent
* group set.
*/
if (argc > 1) {
if (argc > 2 || strcmp(argv[1], "-a") != 0)
usage();
else
aflg = true;
}
ruid = getuid ();
euid = geteuid ();
rgid = getgid ();
egid = getegid ();
/*
* Print out the real user ID and group ID. If the user or group
* does not exist, just give the numerical value.
*/
pw = getpwuid (ruid); /* local, no need for xgetpwuid */
if (NULL != pw) {
(void) printf ("UID=%lu(%s)",
(unsigned long) ruid, pw->pw_name);
} else {
(void) printf ("UID=%lu", (unsigned long) ruid);
}
gr = getgrgid (rgid);; /* local, no need for xgetgrgid */
if (NULL != gr) {
(void) printf (" GID=%lu(%s)",
(unsigned long) rgid, gr->gr_name);
} else {
(void) printf (" GID=%lu", (unsigned long) rgid);
}
/*
* Print out the effective user ID and group ID if they are
* different from the real values.
*/
if (ruid != euid) {
pw = getpwuid (euid); /* local, no need for xgetpwuid */
if (NULL != pw) {
(void) printf (" EUID=%lu(%s)",
(unsigned long) euid, pw->pw_name);
} else {
(void) printf (" EUID=%lu", (unsigned long) euid);
}
}
if (rgid != egid) {
gr = getgrgid (egid); /* local, no need for xgetgrgid */
if (NULL != gr) {
(void) printf (" EGID=%lu(%s)",
(unsigned long) egid, gr->gr_name);
} else {
(void) printf (" EGID=%lu", (unsigned long) egid);
}
}
/*
* Print out the concurrent group set if the user has requested it.
* The group numbers will be printed followed by their names.
*/
if (aflg && (ngroups = getgroups (sys_ngroups, groups)) != -1) {
int i;
/*
* Start off the group message. It will be of the format
*
* groups=###(aaa),###(aaa),###(aaa)
*
* where "###" is a numerical value and "aaa" is the
* corresponding name for each respective numerical value.
*/
(void) puts (_(" groups="));
for (i = 0; i < ngroups; i++) {
if (0 != i)
(void) putchar (',');
/* local, no need for xgetgrgid */
gr = getgrgid (groups[i]);
if (NULL != gr) {
(void) printf ("%lu(%s)",
(unsigned long) groups[i],
gr->gr_name);
} else {
(void) printf ("%lu",
(unsigned long) groups[i]);
}
}
}
free (groups);
/*
* Finish off the line.
*/
(void) putchar ('\n');
return EXIT_SUCCESS;
}
+2 -2
View File
@@ -23,14 +23,14 @@
#include <net/if.h>
#endif
#include "atoi/str2i.h"
#include "atoi/str2i/str2u.h"
#include "defines.h"
#include "prototypes.h"
#include "getdef.h"
#include "memzero.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/memset/memzero.h"
#include "string/strftime.h"
+25 -83
View File
@@ -25,22 +25,24 @@
#include <sys/ioctl.h>
#include <assert.h>
#include "alloc.h"
#include "alloc/x/xmalloc.h"
#include "attr.h"
#include "chkname.h"
#include "defines.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "faillog.h"
#include "failure.h"
#include "getdef.h"
#include "memzero.h"
#include "prototypes.h"
#include "pwauth.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/sprintf.h"
#include "string/memset/memzero.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
#include "string/strftime.h"
#include "string/strtcpy.h"
#ifdef USE_PAM
@@ -85,11 +87,6 @@ static struct lastlog ll;
static bool pflg = false;
static bool fflg = false;
#ifdef RLOGIN
static bool rflg = false;
#else /* RLOGIN */
#define rflg false
#endif /* !RLOGIN */
static bool hflg = false;
static bool preauth_flag = false;
@@ -134,7 +131,6 @@ static void exit_handler (int);
* usage - print login command usage and exit
*
* login [ name ]
* login -r hostname (for rlogind)
* login -h hostname (for telnetd, etc.)
* login -f name (for pre-authenticated login: datakit, xterm, etc.)
*/
@@ -145,9 +141,6 @@ static void usage (void)
exit (1);
}
fprintf (stderr, _(" %s [-p] [-h host] [-f name]\n"), Prog);
#ifdef RLOGIN
fprintf (stderr, _(" %s [-p] -r host\n"), Prog);
#endif /* RLOGIN */
exit (1);
}
@@ -271,13 +264,13 @@ static void process_flags (int argc, char *const *argv)
/*
* Check the flags for proper form. Every argument starting with
* "-" must be exactly two characters long. This closes all the
* clever rlogin, telnet, and getty holes.
* clever telnet, and getty holes.
*/
for (arg = 1; arg < argc; arg++) {
if (argv[arg][0] == '-' && strlen (argv[arg]) > 2) {
usage ();
}
if (strcmp(argv[arg], "--") == 0) {
if (streq(argv[arg], "--")) {
break; /* stop checking on a "--" */
}
}
@@ -298,13 +291,6 @@ static void process_flags (int argc, char *const *argv)
hostname = optarg;
reason = PW_TELNET;
break;
#ifdef RLOGIN
case 'r':
rflg = true;
hostname = optarg;
reason = PW_RLOGIN;
break;
#endif /* RLOGIN */
case 'p':
pflg = true;
break;
@@ -313,21 +299,11 @@ static void process_flags (int argc, char *const *argv)
}
}
#ifdef RLOGIN
/*
* Neither -h nor -f should be combined with -r.
*/
if (rflg && (hflg || fflg)) {
usage ();
}
#endif /* RLOGIN */
/*
* Allow authentication bypass only if real UID is zero.
*/
if ((rflg || fflg || hflg) && !amroot) {
if ((fflg || hflg) && !amroot) {
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
exit (1);
}
@@ -342,11 +318,6 @@ static void process_flags (int argc, char *const *argv)
++optind;
}
#ifdef RLOGIN
if (rflg && (NULL != username)) {
usage ();
}
#endif /* RLOGIN */
if (fflg && (NULL == username)) {
usage ();
}
@@ -474,7 +445,6 @@ static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use
* the flags which login supports are
*
* -p - preserve the environment
* -r - perform autologin protocol for rlogin
* -f - do not perform authentication, user is preauthenticated
* -h - the name of the remote host
*/
@@ -505,9 +475,6 @@ int main (int argc, char **argv)
# if defined(ENABLE_LASTLOG)
char ptime[80];
# endif
#endif
#if defined(RLOGIN)
char term[128] = "";
#endif
/*
@@ -559,7 +526,7 @@ int main (int argc, char **argv)
is_console = console (tty);
#endif
if (rflg || hflg) {
if (hflg) {
/*
* Add remote hostname to the environment. I think
* (not sure) I saw it once on Irix. --marekm
@@ -572,23 +539,6 @@ int main (int argc, char **argv)
if (hflg) {
reason = PW_RLOGIN;
}
#ifdef RLOGIN
if (rflg) {
size_t max_size;
max_size = login_name_max_size();
assert (NULL == username);
username = XMALLOC(max_size, char);
username[max_size - 1] = '\0';
if (do_rlogin(hostname, username, max_size, term, sizeof(term)))
{
preauth_flag = true;
} else {
free (username);
username = NULL;
}
}
#endif /* RLOGIN */
OPENLOG (Prog);
@@ -623,18 +573,11 @@ int main (int argc, char **argv)
}
}
#ifdef RLOGIN
if (term[0] != '\0') {
addenv ("TERM", term);
} else
#endif /* RLOGIN */
{
/* preserve TERM from getty */
if (!pflg) {
tmp = getenv ("TERM");
if (NULL != tmp) {
addenv ("TERM", tmp);
}
/* preserve TERM from getty */
if (!pflg) {
tmp = getenv ("TERM");
if (NULL != tmp) {
addenv ("TERM", tmp);
}
}
@@ -644,7 +587,7 @@ int main (int argc, char **argv)
set_env (argc - optind, &argv[optind]);
}
if (rflg || hflg) {
if (hflg) {
cp = hostname;
} else if ((host != NULL) && (host[0] != '\0')) {
cp = host;
@@ -893,7 +836,6 @@ int main (int argc, char **argv)
}
preauth_flag = false;
username = XMALLOC(max_size, char);
username[max_size - 1] = '\0';
login_prompt(username, max_size);
if ('\0' == username[0]) {
@@ -923,22 +865,22 @@ int main (int argc, char **argv)
failed = true;
}
if (strcmp (user_passwd, "") == 0) {
if (streq(user_passwd, "")) {
const char *prevent_no_auth = getdef_str("PREVENT_NO_AUTH");
if (prevent_no_auth == NULL) {
prevent_no_auth = "superuser";
}
if (strcmp(prevent_no_auth, "yes") == 0) {
if (streq(prevent_no_auth, "yes")) {
failed = true;
} else if ((pwd->pw_uid == 0)
&& (strcmp(prevent_no_auth, "superuser") == 0)) {
&& streq(prevent_no_auth, "superuser")) {
failed = true;
}
}
}
if (strcmp (user_passwd, SHADOW_PASSWD_STRING) == 0) {
if (streq(user_passwd, SHADOW_PASSWD_STRING)) {
spwd = xgetspnam (username);
if (NULL != spwd) {
user_passwd = spwd->sp_pwdp;
@@ -954,7 +896,7 @@ int main (int argc, char **argv)
}
/*
* The -r and -f flags provide a name which has already
* The -f flag provides a name which has already
* been authenticated by some server.
*/
if (preauth_flag) {
@@ -1043,8 +985,8 @@ int main (int argc, char **argv)
(void) puts (_("Login incorrect"));
/* allow only one attempt with -r or -f */
if (rflg || fflg || (retries <= 0)) {
/* allow only one attempt with -f */
if (fflg || (retries <= 0)) {
closelog ();
exit (1);
}
+29 -33
View File
@@ -52,26 +52,21 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h> /* for inet_ntoa() */
#include "sizeof.h"
#include "string/strchr/strrspn.h"
#include "string/strtok/stpsep.h"
#if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 64)
#undef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif
/* Path name of the access control file. */
#ifndef TABLE
#define TABLE "/etc/login.access"
#endif
/* Delimiters for fields and for lists of users, ttys or hosts. */
static char fs[] = ":"; /* field separator */
static char sep[] = ", \t"; /* list-element separator */
static bool list_match (char *list, const char *item, bool (*match_fn) (const char *, const char *));
static bool user_match (const char *tok, const char *string);
static bool from_match (const char *tok, const char *string);
@@ -79,7 +74,8 @@ static bool string_match (const char *tok, const char *string);
static const char *resolve_hostname (const char *string);
/* login_access - match username/group and host/tty with access control file */
int login_access (const char *user, const char *from)
int
login_access(const char *user, const char *from)
{
FILE *fp;
char line[BUFSIZ];
@@ -99,11 +95,12 @@ int login_access (const char *user, const char *from)
if (NULL != fp) {
int lineno = 0; /* for diagnostics */
while ( !match
&& (fgets (line, sizeof (line), fp) == line)) {
ptrdiff_t end;
&& (fgets (line, sizeof (line), fp) == line))
{
char *p;
lineno++;
end = strlen (line) - 1;
if (line[0] == '\0' || line[end] != '\n') {
if (stpsep(line, "\n") == NULL) {
SYSLOG ((LOG_ERR,
"%s: line %d: missing newline or line too long",
TABLE, lineno));
@@ -112,17 +109,15 @@ int login_access (const char *user, const char *from)
if (line[0] == '#') {
continue; /* comment line */
}
while (end > 0 && isspace (line[end - 1])) {
end--;
}
line[end] = '\0'; /* strip trailing whitespace */
stpcpy(strrspn(line, " \t"), "");
if (line[0] == '\0') { /* skip blank lines */
continue;
}
if ( ((perm = strtok (line, fs)) == NULL)
|| ((users = strtok (NULL, fs)) == NULL)
|| ((froms = strtok (NULL, fs)) == NULL)
|| (strtok (NULL, fs) != NULL)) {
p = line;
perm = strsep(&p, ":");
users = strsep(&p, ":");
froms = strsep(&p, ":");
if (froms == NULL || p != NULL) {
SYSLOG ((LOG_ERR,
"%s: line %d: bad field count",
TABLE, lineno));
@@ -146,8 +141,11 @@ int 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) (const char *, const char*))
static bool
list_match(char *list, const char *item, bool (*match_fn)(const char *, const char*))
{
static const char sep[] = ", \t";
char *tok;
bool match = false;
@@ -157,7 +155,7 @@ static bool list_match (char *list, const char *item, bool (*match_fn) (const ch
* a match, look for an "EXCEPT" list and recurse to determine whether
* the match is affected by any exceptions.
*/
for (tok = strtok (list, sep); tok != NULL; tok = strtok (NULL, sep)) {
while (NULL != (tok = strsep(&list, sep))) {
if (strcasecmp (tok, "EXCEPT") == 0) { /* EXCEPT: give up */
break;
}
@@ -169,10 +167,10 @@ static bool list_match (char *list, const char *item, bool (*match_fn) (const ch
/* Process exceptions to matches. */
if (match) {
while ( ((tok = strtok (NULL, sep)) != NULL)
while ( (NULL != (tok = strsep(&list, sep)))
&& (strcasecmp (tok, "EXCEPT") != 0))
/* VOID */ ;
if (tok == 0 || !list_match (NULL, item, match_fn)) {
if (tok == NULL || !list_match(NULL, item, match_fn)) {
return (match);
}
}
@@ -186,7 +184,7 @@ static char *myhostname (void)
if (name[0] == '\0') {
gethostname (name, sizeof (name));
name[MAXHOSTNAMELEN] = '\0';
stpcpy(&name[MAXHOSTNAMELEN], "");
}
return (name);
}
@@ -217,18 +215,16 @@ static bool user_match (const char *tok, const char *string)
#ifdef PRIMARY_GROUP_MATCH
struct passwd *userinf;
#endif
char *at;
char *host;
/*
* If a token has the magic value "ALL" the match always succeeds.
* Otherwise, return true if the token fully matches the username, or if
* the token is a group that contains the username.
*/
at = strchr (tok + 1, '@');
if (NULL != at) { /* split user@host pattern */
*at = '\0';
return ( user_match (tok, string)
&& from_match (at + 1, myhostname ()));
host = stpsep(tok + 1, "@"); /* split user@host pattern */
if (host != NULL) {
return user_match(tok, string) && from_match(host, myhostname());
#if HAVE_INNETGR
} else if (tok[0] == '@') { /* netgroup */
return (netgroup_match (tok + 1, NULL, string));
@@ -270,7 +266,7 @@ static const char *resolve_hostname (const char *string)
const char *addr_str;
struct addrinfo *addrs;
static char host[MAXHOSTNAMELEN];
static char host[NI_MAXHOST];
gai_err = getaddrinfo(string, NULL, NULL, &addrs);
if (gai_err != 0) {
+24 -31
View File
@@ -16,11 +16,15 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <utmpx.h>
#include "defines.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "sizeof.h"
#include "string/zustr2stp.h"
#include "string/strcpy/strncat.h"
#include "string/strdup/strndupa.h"
/*
* Global variables
*/
@@ -46,22 +50,16 @@ static void send_mesg_to_tty (int tty_fd);
static int
check_login(const struct utmpx *ut)
{
char user[sizeof(ut->ut_user) + 1];
char line[sizeof(ut->ut_line) + 1];
char *user;
char *line;
time_t now;
ZUSTR2STP(user, ut->ut_user);
ZUSTR2STP(line, ut->ut_line);
user = STRNDUPA(ut->ut_user);
line = STRNDUPA(ut->ut_line);
(void) time (&now);
now = time(NULL);
/*
* Check if they are allowed to be logged in right now.
*/
if (!isttytime(user, line, now)) {
return 0;
}
return 1;
return isttytime(user, line, now);
}
@@ -118,15 +116,8 @@ static void send_mesg_to_tty (int tty_fd)
int
main(int argc, char **argv)
{
int i;
int status;
pid_t pid;
struct utmpx *ut;
char user[sizeof (ut->ut_user) + 1]; /* terminating NUL */
char tty_name[sizeof (ut->ut_line) + 6]; /* /dev/ + NUL */
int tty_fd;
if (1 != argc) {
(void) fputs (_("Usage: logoutd\n"), stderr);
}
@@ -136,7 +127,7 @@ main(int argc, char **argv)
(void) textdomain (PACKAGE);
#ifndef DEBUG
for (i = 0; close (i) == 0; i++);
for (int i = 0; close(i) == 0; i++);
setpgrp ();
@@ -167,6 +158,7 @@ main(int argc, char **argv)
* are not supposed to still be logged in.
*/
while (true) {
struct utmpx *ut;
/*
* Attempt to re-open the utmp file. The file is only
@@ -180,6 +172,9 @@ main(int argc, char **argv)
* is permitted to be signed on at this time.
*/
while ((ut = getutxent()) != NULL) {
int tty_fd;
char tty_name[sizeof(ut->ut_line) + 6]; // /dev/ + NUL
if (ut->ut_type != USER_PROCESS) {
continue;
}
@@ -205,13 +200,12 @@ main(int argc, char **argv)
}
/* child */
if (strncmp (ut->ut_line, "/dev/", 5) != 0) {
strcpy (tty_name, "/dev/");
} else {
tty_name[0] = '\0';
}
if (strncmp(ut->ut_line, "/dev/", 5) != 0)
strcpy(tty_name, "/dev/");
else
strcpy(tty_name, "");
strncat(tty_name, ut->ut_line, NITEMS(ut->ut_line));
STRNCAT(tty_name, ut->ut_line);
#ifndef O_NOCTTY
#define O_NOCTTY 0
#endif
@@ -229,10 +223,9 @@ main(int argc, char **argv)
kill (-ut->ut_pid, SIGKILL);
}
ZUSTR2STP(user, ut->ut_user);
SYSLOG ((LOG_NOTICE,
"logged off user '%s' on '%s'", user,
"logged off user '%s' on '%s'",
STRNDUPA(ut->ut_user),
tty_name));
/*
@@ -249,7 +242,7 @@ main(int argc, char **argv)
/*
* Reap any dead babies ...
*/
while (wait (&status) != -1);
while (wait(NULL) != -1);
}
return EXIT_FAILURE;
+4 -1
View File
@@ -2,11 +2,14 @@
#include <stdio.h>
#include <unistd.h>
#include "atoi/str2i/str2u.h"
#include "subid.h"
#include "stdlib.h"
#include "prototypes.h"
#include "shadowlog.h"
/* Test program for the subid creation routine */
static const char Prog[] = "new_subid_range";
@@ -45,7 +48,7 @@ int main(int argc, char *argv[])
range.start = 0;
range.count = 65536;
if (argc > 1)
range.count = atoi(argv[1]);
str2ul(&range.count, argv[1]);
if (group)
ok = subid_grant_gid_range(&range, !makenew);
else
+1 -1
View File
@@ -177,7 +177,7 @@ int main(int argc, char **argv)
if (proc_dir_fd < 0)
usage();
}
/* Who am i? */
/* Who am I? */
pw = get_my_pwent ();
if (NULL == pw) {
fprintf (stderr,
+35 -20
View File
@@ -18,14 +18,17 @@
#include <assert.h>
#include "agetpass.h"
#include "alloc.h"
#include "alloc/x/xmalloc.h"
#include "chkname.h"
#include "defines.h"
#include "getdef.h"
#include "prototypes.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "getdef.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "string/sprintf.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
/*
@@ -72,7 +75,7 @@ static bool ingroup(const char *name, struct group *gr)
look = gr->gr_mem;
while (*look && notfound)
notfound = strcmp (*look++, name);
notfound = !streq(*look++, name);
return !notfound;
}
@@ -186,7 +189,7 @@ static void check_perms (const struct group *grp,
}
if (grp->gr_passwd[0] == '\0' ||
strcmp (cpasswd, grp->gr_passwd) != 0) {
!streq(cpasswd, grp->gr_passwd)) {
#ifdef WITH_AUDIT
SNPRINTF(audit_buf, "authentication new-gid=%lu",
(unsigned long) grp->gr_gid);
@@ -399,7 +402,7 @@ int main (int argc, char **argv)
/*
* Save my name for error messages and save my real gid in case of
* errors. If there is an error i have to exec a new login shell for
* errors. If there is an error, I have to exec a new login shell for
* the user since her old shell won't have fork'd to create the
* process. Skip over the program name to the next command line
* argument.
@@ -426,7 +429,7 @@ int main (int argc, char **argv)
* injecting arbitrary strings into our stderr/stdout, as this can
* be an exploit vector.
*/
is_newgrp = (strcmp (Basename (argv[0]), "newgrp") == 0);
is_newgrp = streq(Basename (argv[0]), "newgrp");
Prog = is_newgrp ? "newgrp" : "sg";
log_set_progname(Prog);
@@ -459,7 +462,7 @@ int main (int argc, char **argv)
* for sg causes a command string to be executed.
*
* The next argument, if present, must be the new group name. Any
* remaining remaining arguments will be used to execute a command
* remaining arguments will be used to execute a command
* as the named group. If the group name isn't present, I just use
* the login group ID of the current user.
*
@@ -470,8 +473,8 @@ int main (int argc, char **argv)
* sg [-] groupid [[-c command]
*/
if ( (argc > 0)
&& ( (strcmp (argv[0], "-") == 0)
|| (strcmp (argv[0], "-l") == 0))) {
&& ( streq(argv[0], "-")
|| streq(argv[0], "-l"))) {
argc--;
argv++;
initflag = true;
@@ -482,6 +485,12 @@ int main (int argc, char **argv)
* not "newgrp".
*/
if ((argc > 0) && (argv[0][0] != '-')) {
if (!is_valid_group_name (argv[0])) {
fprintf (
stderr, _("%s: provided group is not a valid group name\n"),
Prog);
goto failure;
}
group = argv[0];
argc--;
argv++;
@@ -497,7 +506,7 @@ int main (int argc, char **argv)
* "sg group -c command" (as in the man page) or
* "sg group command" (as in the usage message).
*/
if ((argc > 1) && (strcmp (argv[0], "-c") == 0)) {
if ((argc > 1) && streq(argv[0], "-c")) {
command = argv[1];
} else {
command = argv[0];
@@ -513,6 +522,12 @@ int main (int argc, char **argv)
usage ();
goto failure;
} else if (argv[0] != NULL) {
if (!is_valid_group_name (argv[0])) {
fprintf (
stderr, _("%s: provided group is not a valid group name\n"),
Prog);
goto failure;
}
group = argv[0];
} else {
/*
@@ -538,9 +553,9 @@ int main (int argc, char **argv)
#ifdef HAVE_SETGROUPS
/*
* get the current users groupset. The new group will be added to
* get the current user's groupset. The new group will be added to
* the concurrent groupset if there is room, otherwise you get a
* nasty message but at least your real and effective group id's are
* nasty message but at least your real and effective group ids are
* set.
*/
/* don't use getgroups(0, 0) - it doesn't work on some systems */
@@ -575,7 +590,7 @@ int main (int argc, char **argv)
* now we put her in the new group. The password file entry for her
* current user id has been gotten. If there was no optional group
* argument she will have her real and effective group id set to the
* set to the value from her password file entry.
* value from her password file entry.
*
* If run as newgrp, or as sg with no command, this process exec's
* an interactive subshell with the effective GID of the new group.
@@ -676,8 +691,8 @@ int main (int argc, char **argv)
#ifdef HAVE_SETGROUPS
/*
* I am going to try to add her new group id to her concurrent group
* set. If the group id is already present i'll just skip this part.
* If the group doesn't fit, i'll complain loudly and skip this
* set. If the group id is already present I'll just skip this part.
* If the group doesn't fit, I'll complain loudly and skip this
* part.
*/
for (i = 0; i < ngroups; i++) {
@@ -736,7 +751,7 @@ int main (int argc, char **argv)
}
/*
* See if the "-c" flag was used. If it was, i just create a shell
* See if the "-c" flag was used. If it was, I just create a shell
* command for her using the argument that followed the "-c" flag.
*/
if (cflag) {
@@ -752,7 +767,7 @@ int main (int argc, char **argv)
}
/*
* I have to get the pathname of her login shell. As a favor, i'll
* I have to get the pathname of her login shell. As a favor, I'll
* try her environment for a $SHELL value first, and then try the
* password file entry. Obviously this shouldn't be in the
* restricted command directory since it could be used to leave the
@@ -784,7 +799,7 @@ int main (int argc, char **argv)
progbase = Basename (prog);
/*
* Switch back to her home directory if i am doing login
* Switch back to her home directory if I am doing login
* initialization.
*/
if (initflag) {
+1 -1
View File
@@ -106,7 +106,7 @@ int main(int argc, char **argv)
usage();
}
/* Who am i? */
/* Who am I? */
pw = get_my_pwent ();
if (NULL == pw) {
fprintf (stderr,
+49 -45
View File
@@ -30,28 +30,32 @@
#include <errno.h>
#include <string.h>
#include "alloc.h"
#include "atoi/str2i.h"
#include "alloc/reallocf.h"
#include "atoi/getnum.h"
#include "atoi/str2i/str2s.h"
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
#include "pam_defs.h"
#endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */
#include "prototypes.h"
#include "chkname.h"
#include "defines.h"
#include "getdef.h"
#include "groupio.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#include "pwio.h"
#include "sgroupio.h"
#include "shadowio.h"
#ifdef ENABLE_SUBIDS
#include "subordinateio.h"
#endif /* ENABLE_SUBIDS */
#include "chkname.h"
#include "shadowlog.h"
#include "string/sprintf.h"
#include "sssd.h"
#include "string/sprintf/snprintf.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
#include "string/strtok/stpsep.h"
/*
@@ -383,10 +387,16 @@ static int add_user (const char *name, uid_t uid, gid_t gid)
struct passwd pwent;
/* Check if this is a valid user name */
if (!is_valid_user_name (name)) {
fprintf (stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, name);
if (!is_valid_user_name(name)) {
if (errno == EINVAL) {
fprintf(stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, name);
} else {
fprintf(stderr,
_("%s: invalid user name '%s'\n"),
Prog, name);
}
return -1;
}
@@ -419,29 +429,29 @@ static int update_passwd (struct passwd *pwd, const char *password)
if (NULL != crypt_method) {
#if defined(USE_SHA_CRYPT)
if (sflg) {
if ( (0 == strcmp (crypt_method, "SHA256"))
|| (0 == strcmp (crypt_method, "SHA512"))) {
if ( streq(crypt_method, "SHA256")
|| streq(crypt_method, "SHA512")) {
crypt_arg = &sha_rounds;
}
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (sflg) {
if (0 == strcmp (crypt_method, "BCRYPT")) {
if (streq(crypt_method, "BCRYPT")) {
crypt_arg = &bcrypt_rounds;
}
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (sflg) {
if (0 == strcmp (crypt_method, "YESCRYPT")) {
if (streq(crypt_method, "YESCRYPT")) {
crypt_arg = &yescrypt_cost;
}
}
#endif /* USE_YESCRYPT */
}
if ((NULL != crypt_method) && (0 == strcmp(crypt_method, "NONE"))) {
if ((NULL != crypt_method) && streq(crypt_method, "NONE")) {
pwd->pw_passwd = (char *)password;
} else {
const char *salt = crypt_make_salt (crypt_method, crypt_arg);
@@ -475,22 +485,23 @@ static int add_passwd (struct passwd *pwd, const char *password)
if (NULL != crypt_method) {
#if defined(USE_SHA_CRYPT)
if (sflg) {
if ( (0 == strcmp (crypt_method, "SHA256"))
|| (0 == strcmp (crypt_method, "SHA512"))) {
if (streq(crypt_method, "SHA256")
|| streq(crypt_method, "SHA512"))
{
crypt_arg = &sha_rounds;
}
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (sflg) {
if (0 == strcmp (crypt_method, "BCRYPT")) {
if (streq(crypt_method, "BCRYPT")) {
crypt_arg = &bcrypt_rounds;
}
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (sflg) {
if (0 == strcmp (crypt_method, "YESCRYPT")) {
if (streq(crypt_method, "YESCRYPT")) {
crypt_arg = &yescrypt_cost;
}
}
@@ -516,7 +527,8 @@ static int add_passwd (struct passwd *pwd, const char *password)
if (NULL != sp) {
spent = *sp;
if ( (NULL != crypt_method)
&& (0 == strcmp(crypt_method, "NONE"))) {
&& streq(crypt_method, "NONE"))
{
spent.sp_pwdp = (char *)password;
} else {
const char *salt = crypt_make_salt (crypt_method,
@@ -545,7 +557,7 @@ static int add_passwd (struct passwd *pwd, const char *password)
* when the entry was created, so this user would have to have had
* the password set someplace else.
*/
if (strcmp (pwd->pw_passwd, "x") != 0) {
if (!streq(pwd->pw_passwd, "x")) {
return update_passwd (pwd, password);
}
#else /* USE_PAM */
@@ -556,7 +568,7 @@ static int add_passwd (struct passwd *pwd, const char *password)
* The password will be updated later for all users using PAM.
*/
if ( (NULL != sp)
|| (strcmp (pwd->pw_passwd, "x") != 0)) {
|| !streq(pwd->pw_passwd, "x")) {
return 0;
}
#endif /* USE_PAM */
@@ -567,7 +579,7 @@ static int add_passwd (struct passwd *pwd, const char *password)
*/
spent.sp_namp = pwd->pw_name;
#ifndef USE_PAM
if ((crypt_method != NULL) && (0 == strcmp(crypt_method, "NONE"))) {
if ((crypt_method != NULL) && streq(crypt_method, "NONE")) {
spent.sp_pwdp = (char *)password;
} else {
const char *salt = crypt_make_salt (crypt_method, crypt_arg);
@@ -673,19 +685,19 @@ static void process_flags (int argc, char **argv)
usage (EXIT_FAILURE);
}
#if defined(USE_SHA_CRYPT)
if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512")))
if ( ( (streq(crypt_method, "SHA256") || streq(crypt_method, "SHA512"))
&& (-1 == str2sl(&sha_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_SHA_CRYPT */
#if defined(USE_BCRYPT)
if (( (0 == strcmp (crypt_method, "BCRYPT"))
if (( streq(crypt_method, "BCRYPT")
&& (-1 == str2sl(&bcrypt_rounds, optarg)))) {
bad_s = 1;
}
#endif /* USE_BCRYPT */
#if defined(USE_YESCRYPT)
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
if (( streq(crypt_method, "YESCRYPT")
&& (-1 == str2sl(&yescrypt_cost, optarg)))) {
bad_s = 1;
}
@@ -742,18 +754,18 @@ static void check_flags (void)
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
if (cflg) {
if ( (0 != strcmp (crypt_method, "DES"))
&& (0 != strcmp (crypt_method, "MD5"))
&& (0 != strcmp (crypt_method, "NONE"))
if ( !streq(crypt_method, "DES")
&& !streq(crypt_method, "MD5")
&& !streq(crypt_method, "NONE")
#ifdef USE_SHA_CRYPT
&& (0 != strcmp (crypt_method, "SHA256"))
&& (0 != strcmp (crypt_method, "SHA512"))
&& !streq(crypt_method, "SHA256")
&& !streq(crypt_method, "SHA512")
#endif /* USE_SHA_CRYPT */
#ifdef USE_BCRYPT
&& (0 != strcmp (crypt_method, "BCRYPT"))
&& !streq(crypt_method, "BCRYPT")
#endif /* USE_BCRYPT */
#ifdef USE_YESCRYPT
&& (0 != strcmp (crypt_method, "YESCRYPT"))
&& !streq(crypt_method, "YESCRYPT")
#endif /* USE_YESCRYPT */
) {
fprintf (stderr,
@@ -1099,15 +1111,11 @@ int main (int argc, char **argv)
*/
while (fgets (buf, sizeof buf, stdin) != NULL) {
line++;
cp = strrchr (buf, '\n');
if (cp == NULL && feof (stdin) == 0) {
if (stpsep(buf, "\n") == NULL && feof(stdin) == 0) {
fprintf (stderr, _("%s: line %d: line too long\n"),
Prog, line);
fail_exit (EXIT_FAILURE);
}
if (cp != NULL) {
*cp = '\0';
}
/*
* Break the string into fields and screw around with them.
@@ -1115,13 +1123,9 @@ int main (int argc, char **argv)
* values aren't that particular.
*/
for (cp = buf, nfields = 0; nfields < 7; nfields++) {
fields[nfields] = cp;
cp = strchr (cp, ':');
fields[nfields] = strsep(&cp, ":");
if (cp == NULL)
break;
*cp = '\0';
cp++;
}
if (nfields != 6) {
fprintf (stderr, _("%s: line %d: invalid line\n"),
@@ -1209,8 +1213,8 @@ int main (int argc, char **argv)
fail_exit (EXIT_FAILURE);
}
lines[nusers-1] = line;
usernames[nusers-1] = strdup (fields[0]);
passwords[nusers-1] = strdup (fields[1]);
usernames[nusers-1] = xstrdup(fields[0]);
passwords[nusers-1] = xstrdup(fields[1]);
#endif /* USE_PAM */
if (add_passwd (&newpw, fields[1]) != 0) {
fprintf (stderr,
+40 -31
View File
@@ -21,23 +21,25 @@
#include <time.h>
#include "agetpass.h"
#include "alloc.h"
#include "atoi/str2i.h"
#include "atoi/a2i/a2s.h"
#include "chkname.h"
#include "defines.h"
#include "getdef.h"
#include "memzero.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#include "pwauth.h"
#include "pwio.h"
#include "shadowio.h"
#include "shadowlog.h"
#include "string/strtcpy.h"
#include "sssd.h"
#include "string/memset/memzero.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
#include "time/day_to_str.h"
/*
* exit status values
*/
@@ -211,7 +213,7 @@ static int new_password (const struct passwd *pw)
return -1;
}
if (strcmp (cipher, crypt_passwd) != 0) {
if (!streq(cipher, crypt_passwd)) {
erase_pass (clear);
strzero (cipher);
SYSLOG ((LOG_WARN, "incorrect password for %s",
@@ -226,7 +228,7 @@ static int new_password (const struct passwd *pw)
erase_pass (clear);
strzero (cipher);
} else {
orig[0] = '\0';
strcpy(orig, "");
}
/*
@@ -241,16 +243,16 @@ static int new_password (const struct passwd *pw)
pass_max_len = getdef_num ("PASS_MAX_LEN", 8);
}
} else {
if ( (strcmp (method, "MD5") == 0)
if ( streq(method, "MD5")
#ifdef USE_SHA_CRYPT
|| (strcmp (method, "SHA256") == 0)
|| (strcmp (method, "SHA512") == 0)
|| streq(method, "SHA256")
|| streq(method, "SHA512")
#endif /* USE_SHA_CRYPT */
#ifdef USE_BCRYPT
|| (strcmp (method, "BCRYPT") == 0)
|| streq(method, "BCRYPT")
#endif /* USE_BCRYPT*/
#ifdef USE_YESCRYPT
|| (strcmp (method, "YESCRYPT") == 0)
|| streq(method, "YESCRYPT")
#endif /* USE_YESCRYPT*/
) {
@@ -297,7 +299,7 @@ static int new_password (const struct passwd *pw)
MEMZERO(pass);
return -1;
}
if (warned && (strcmp (pass, cp) != 0)) {
if (warned && !streq(pass, cp)) {
warned = false;
}
ret = STRTCPY (pass, cp);
@@ -331,7 +333,7 @@ static int new_password (const struct passwd *pw)
MEMZERO(pass);
return -1;
}
if (strcmp (cp, pass) != 0) {
if (!streq(cp, pass)) {
erase_pass (cp);
(void) fputs (_("They don't match; try again.\n"), stderr);
} else {
@@ -514,9 +516,8 @@ static char *update_crypt_pw (char *cp)
}
}
if (dflg) {
*cp = '\0';
}
if (dflg)
strcpy(cp, "");
if (uflg && *cp == '!') {
if (cp[1] == '\0') {
@@ -531,10 +532,9 @@ static char *update_crypt_pw (char *cp)
}
if (lflg && *cp != '!') {
char *newpw = XMALLOC(strlen(cp) + 2, char);
char *newpw;
strcpy (newpw, "!");
strcat (newpw, cp);
xasprintf(&newpw, "!%s", cp);
if (!use_pam)
{
if (do_update_pwd) {
@@ -723,7 +723,8 @@ static void update_shadow (void)
* appropriate internal format. For finer resolute the chage
* command must be used.
*/
int main (int argc, char **argv)
int
main(int argc, char **argv)
{
const struct passwd *pw; /* Password file entry for user */
@@ -801,8 +802,9 @@ int main (int argc, char **argv)
usage (E_SUCCESS);
/*@notreached@*/break;
case 'i':
if ( (str2sl(&inact, optarg) == -1)
|| (inact < -1)) {
if (a2sl(&inact, optarg, NULL, 0, -1, LONG_MAX)
== -1)
{
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -820,8 +822,9 @@ int main (int argc, char **argv)
anyflag = true;
break;
case 'n':
if ( (str2sl(&age_min, optarg) == -1)
|| (age_min < -1)) {
if (a2sl(&age_min, optarg, NULL, 0, -1, LONG_MAX)
== -1)
{
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -836,7 +839,7 @@ int main (int argc, char **argv)
case 'r':
/* -r repository (files|nis|nisplus) */
/* only "files" supported for now */
if (strcmp (optarg, "files") != 0) {
if (!streq(optarg, "files")) {
fprintf (stderr,
_("%s: repository %s not supported\n"),
Prog, optarg);
@@ -855,8 +858,9 @@ int main (int argc, char **argv)
anyflag = true;
break;
case 'w':
if ( (str2sl(&warn, optarg) == -1)
|| (warn < -1)) {
if (a2sl(&warn, optarg, NULL, 0, -1, LONG_MAX)
== -1)
{
(void) fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -866,8 +870,9 @@ int main (int argc, char **argv)
anyflag = true;
break;
case 'x':
if ( (str2sl(&age_max, optarg) == -1)
|| (age_max < -1)) {
if (a2sl(&age_max, optarg, NULL, 0, -1, LONG_MAX)
== -1)
{
(void) fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -907,6 +912,10 @@ int main (int argc, char **argv)
}
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);
}
name = argv[optind];
} else {
name = myname;
+19 -12
View File
@@ -13,23 +13,26 @@
#ident "$Id$"
#include <fcntl.h>
#include <getopt.h>
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <getopt.h>
#include "chkname.h"
#include "commonio.h"
#include "defines.h"
#include "getdef.h"
#include "nscd.h"
#include "prototypes.h"
#include "pwio.h"
#include "shadowio.h"
#include "getdef.h"
#include "nscd.h"
#include "shadowlog.h"
#include "sssd.h"
#include "string/strcmp/streq.h"
#ifdef WITH_TCB
#include "tcbfuncs.h"
#endif /* WITH_TCB */
#include "shadowlog.h"
/*
* Exit codes
@@ -447,7 +450,7 @@ static void check_pw_file (int *errors, bool *changed)
continue;
}
if (strcmp (pwd->pw_name, ent->pw_name) != 0) {
if (!streq(pwd->pw_name, ent->pw_name)) {
continue;
}
@@ -471,9 +474,14 @@ static void check_pw_file (int *errors, bool *changed)
* Check for invalid usernames. --marekm
*/
if (!is_valid_user_name (pwd->pw_name)) {
printf (_("invalid user name '%s': use --badname to ignore\n"),
pwd->pw_name);
if (!is_valid_user_name(pwd->pw_name)) {
if (errno == EINVAL) {
printf(_("invalid user name '%s': use --badname to ignore\n"),
pwd->pw_name);
} else {
printf(_("invalid user name '%s'\n"),
pwd->pw_name);
}
*errors += 1;
}
@@ -513,7 +521,7 @@ static void check_pw_file (int *errors, bool *changed)
/*
* Home directory does not exist, give a warning (unless intentional)
*/
if (NULL == nonexistent || strcmp (pwd->pw_dir, nonexistent) != 0) {
if (NULL == nonexistent || !streq(pwd->pw_dir, nonexistent)) {
printf (_("user '%s': directory '%s' does not exist\n"),
pwd->pw_name, pwd->pw_dir);
*errors += 1;
@@ -639,8 +647,7 @@ static void check_pw_file (int *errors, bool *changed)
* Make sure no passwords are in passwd.
*/
if ( !quiet
&& (strcmp (pwd->pw_passwd,
SHADOW_PASSWD_STRING) != 0)) {
&& !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 ());
*errors += 1;
@@ -768,7 +775,7 @@ static void check_spw_file (int *errors, bool *changed)
continue;
}
if (strcmp (spw->sp_namp, ent->sp_namp) != 0) {
if (!streq(spw->sp_namp, ent->sp_namp)) {
continue;
}
+5 -3
View File
@@ -47,12 +47,14 @@
#include "defines.h"
#include "getdef.h"
#include "nscd.h"
#include "prototypes.h"
#include "pwio.h"
#include "shadowio.h"
#include "nscd.h"
#include "sssd.h"
#include "shadowio.h"
#include "shadowlog.h"
#include "string/strcmp/streq.h"
/*
* exit status values
@@ -231,7 +233,7 @@ int main (int argc, char **argv)
sp = spw_locate (pw->pw_name);
if (NULL != sp) {
/* do we need to update this entry? */
if (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) == 0) {
if (streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) {
continue;
}
/* update existing shadow entry */
+7 -4
View File
@@ -17,16 +17,19 @@
#include <sys/types.h>
#include <unistd.h>
#include <getopt.h>
#include "defines.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "getdef.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#include "pwio.h"
#include "shadowio.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "sssd.h"
#include "string/strcmp/streq.h"
/*
* Global variables
@@ -180,7 +183,7 @@ int main (int argc, char **argv)
/*
* Update password if non-shadow is "x".
*/
if (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) == 0) {
if (streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) {
pwent.pw_passwd = spwd->sp_pwdp;
}
+26 -23
View File
@@ -46,21 +46,24 @@
#include <fcntl.h>
#endif /* !USE_PAM */
#include "alloc.h"
#include "alloc/x/xmalloc.h"
#include "attr.h"
#include "cast.h"
#include "prototypes.h"
#include "defines.h"
#include "pwauth.h"
/*@-exitarg@*/
#include "exitcodes.h"
#include "getdef.h"
#ifdef USE_PAM
#include "pam_defs.h"
#endif /* USE_PAM */
/*@-exitarg@*/
#include "exitcodes.h"
#include "pwauth.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "string/sprintf.h"
#include "string/strtcpy.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/xstrdup.h"
/*
@@ -126,7 +129,7 @@ static void check_perms_pam (const struct passwd *pw);
#else /* !USE_PAM */
static void check_perms_nopam (const struct passwd *pw);
#endif /* !USE_PAM */
static void save_caller_context (char **argv);
static void save_caller_context(void);
static void process_flags (int argc, char **argv);
static void set_environment (struct passwd *pw);
@@ -184,7 +187,7 @@ static bool restricted_shell (const char *shellname)
setusershell ();
while ((line = getusershell ()) != NULL) {
if (('#' != *line) && (strcmp (line, shellname) == 0)) {
if (('#' != *line) && streq(line, shellname)) {
endusershell ();
return false;
}
@@ -509,17 +512,17 @@ static void check_perms_nopam (const struct passwd *pw)
return;
}
if (strcmp (pw->pw_passwd, "") == 0) {
if (streq(pw->pw_passwd, "")) {
const char *prevent_no_auth = getdef_str("PREVENT_NO_AUTH");
if (prevent_no_auth == NULL) {
prevent_no_auth = "superuser";
}
if (strcmp(prevent_no_auth, "yes") == 0) {
if (streq(prevent_no_auth, "yes")) {
fprintf(stderr, _("Password field is empty, this is forbidden for all accounts.\n"));
exit(1);
} else if ((pw->pw_uid == 0)
&& (strcmp(prevent_no_auth, "superuser") == 0)) {
&& streq(prevent_no_auth, "superuser")) {
fprintf(stderr, _("Password field is empty, this is forbidden for super-user.\n"));
exit(1);
}
@@ -553,7 +556,7 @@ static void check_perms_nopam (const struct passwd *pw)
}
spwd = getspnam (name); /* !USE_PAM, no need for xgetspnam */
#ifdef SU_ACCESS
if (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) == 0) {
if (streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) {
if (NULL != spwd) {
password = spwd->sp_pwdp;
}
@@ -678,7 +681,7 @@ static /*@only@*/struct passwd * do_check_perms (void)
su_failure (caller_tty, 0 == pw->pw_uid);
}
tmp_name = item;
if (strcmp (name, tmp_name) != 0) {
if (!streq(name, tmp_name)) {
SYSLOG ((LOG_INFO,
"Change user from '%s' to '%s' as requested by PAM",
name, tmp_name));
@@ -722,6 +725,7 @@ static /*@only@*/struct passwd * do_check_perms (void)
return pw;
}
/*
* save_caller_context - save information from the call context
*
@@ -730,7 +734,8 @@ static /*@only@*/struct passwd * do_check_perms (void)
* the TTY (ttyp), and whether su was called from a console
* (is_console) for further processing and before they might change.
*/
static void save_caller_context (char **argv)
static void
save_caller_context(void)
{
struct passwd *pw = NULL;
#ifndef USE_PAM
@@ -788,7 +793,7 @@ static void save_caller_context (char **argv)
* -- chris
*/
password = pw->pw_passwd;
if (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) == 0) {
if (streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) {
const struct spwd *spwd = getspnam (caller_name);
if (NULL != spwd) {
password = spwd->sp_pwdp;
@@ -801,6 +806,7 @@ static void save_caller_context (char **argv)
pw_free (pw);
}
/*
* process_flags - Process the command line arguments
*
@@ -848,7 +854,7 @@ static void process_flags (int argc, char **argv)
}
}
if ((optind < argc) && (strcmp (argv[optind], "-") == 0)) {
if ((optind < argc) && streq(argv[optind], "-")) {
fakelogin = true;
optind++;
}
@@ -1013,7 +1019,7 @@ int main (int argc, char **argv)
(void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE);
save_caller_context (argv);
save_caller_context();
OPENLOG (Prog);
@@ -1198,17 +1204,14 @@ int main (int argc, char **argv)
* case they will be provided to the new user's shell as arguments.
*/
if (fakelogin) {
char *arg0;
char *arg0;
cp = getdef_str ("SU_NAME");
if (NULL == cp) {
cp = Basename (shellstr);
}
arg0 = XMALLOC(strlen(cp) + 2, char);
arg0[0] = '-';
strcpy (arg0 + 1, cp);
cp = arg0;
xasprintf(&arg0, "-%s", cp);
} else {
cp = Basename (shellstr);
}
+33 -36
View File
@@ -8,13 +8,21 @@
*/
#include <config.h>
#include <errno.h>
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "defines.h"
#include "prototypes.h"
#include "string/strchr/stpspn.h"
#include "string/strchr/strrspn.h"
#include "string/strcmp/streq.h"
#include "string/strtok/stpsep.h"
#ifndef SUAUTHFILE
#define SUAUTHFILE "/etc/suauth"
@@ -37,12 +45,9 @@ static int isgrp (const char *, const char *);
static int lines = 0;
int check_su_auth (const char *actual_id,
const char *wanted_id,
bool su_to_root)
int
check_su_auth(const char *actual_id, const char *wanted_id, bool su_to_root)
{
int posn, endline;
const char field[] = ":";
FILE *authfile_fd;
char temp[1024];
char *to_users;
@@ -67,34 +72,27 @@ int check_su_auth (const char *actual_id,
}
while (fgets (temp, sizeof (temp), authfile_fd) != NULL) {
lines++;
endline = strlen(temp) - 1;
char *p;
if (temp[0] == '\0' || temp[endline] != '\n') {
lines++;
if (stpsep(temp, "\n") == NULL) {
SYSLOG ((LOG_ERR,
"%s, line %d: line too long or missing newline",
SUAUTHFILE, lines));
continue;
}
while (endline > 0 && (temp[endline - 1] == ' '
|| temp[endline - 1] == '\t'
|| temp[endline - 1] == '\n'))
endline--;
temp[endline] = '\0';
stpcpy(strrspn(temp, " \t"), "");
posn = 0;
while (temp[posn] == ' ' || temp[posn] == '\t')
posn++;
if (temp[posn] == '\n' || temp[posn] == '#'
|| temp[posn] == '\0') {
p = stpspn(temp, " \t");
if (*p == '#' || *p == '\0')
continue;
}
if (!(to_users = strtok (temp + posn, field))
|| !(from_users = strtok (NULL, field))
|| !(action = strtok (NULL, field))
|| strtok (NULL, field)) {
to_users = strsep(&p, ":");
from_users = strsep(&p, ":");
action = strsep(&p, ":");
if (action == NULL || p != NULL) {
SYSLOG ((LOG_ERR,
"%s, line %d. Bad number of fields.\n",
SUAUTHFILE, lines));
@@ -105,7 +103,7 @@ int check_su_auth (const char *actual_id,
continue;
if (!applies (actual_id, from_users))
continue;
if (!strcmp (action, "DENY")) {
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));
@@ -113,14 +111,14 @@ int check_su_auth (const char *actual_id,
stderr);
fclose (authfile_fd);
return DENY;
} else if (!strcmp (action, "NOPASS")) {
} 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);
return NOPWORD;
} else if (!strcmp (action, "OWNPASS")) {
} 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",
actual_id, wanted_id, SUAUTHFILE));
@@ -138,17 +136,16 @@ int check_su_auth (const char *actual_id,
return NOACTION;
}
static int applies (const char *single, char *list)
static int
applies(const char *single, char *list)
{
const char split[] = ", ";
char *tok;
int state = 0;
for (tok = strtok (list, split); tok != NULL;
tok = strtok (NULL, split)) {
while (NULL != (tok = strsep(&list, ", "))) {
if (!strcmp (tok, "ALL")) {
if (streq(tok, "ALL")) {
if (state != 0) {
SYSLOG ((LOG_ERR,
"%s, line %d: ALL in bad place\n",
@@ -156,7 +153,7 @@ static int applies (const char *single, char *list)
return 0;
}
state = 1;
} else if (!strcmp (tok, "EXCEPT")) {
} else if (streq(tok, "EXCEPT")) {
if (state != 1) {
SYSLOG ((LOG_ERR,
"%s, line %d: EXCEPT in bas place\n",
@@ -164,7 +161,7 @@ static int applies (const char *single, char *list)
return 0;
}
state = 2;
} else if (!strcmp (tok, "GROUP")) {
} else if (streq(tok, "GROUP")) {
if ((state != 0) && (state != 2)) {
SYSLOG ((LOG_ERR,
"%s, line %d: GROUP in bad place\n",
@@ -175,7 +172,7 @@ static int applies (const char *single, char *list)
} else {
switch (state) {
case 0: /* No control words yet */
if (!strcmp (tok, single))
if (streq(tok, single))
return 1;
break;
case 1: /* An all */
@@ -184,7 +181,7 @@ static int applies (const char *single, char *list)
SUAUTHFILE, lines));
return 0;
case 2: /* All except */
if (!strcmp (tok, single))
if (streq(tok, single))
return 0;
break;
case 3: /* Group */
+1 -1
View File
@@ -19,7 +19,6 @@
#include <sys/types.h>
#include "agetpass.h"
#include "alloc.h"
#include "attr.h"
#include "defines.h"
#include "getdef.h"
@@ -28,6 +27,7 @@
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/strdup/xstrdup.h"
/*
+138 -136
View File
@@ -36,16 +36,15 @@
#include <time.h>
#include <unistd.h>
#include "alloc.h"
#include "atoi/str2i.h"
#include "alloc/x/xmalloc.h"
#include "atoi/a2i/a2s.h"
#include "atoi/getnum.h"
#include "chkname.h"
#include "defines.h"
#include "faillog.h"
#include "getdef.h"
#include "groupio.h"
#include "memzero.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#include "pwauth.h"
#include "pwio.h"
@@ -64,7 +63,13 @@
#include "tcbfuncs.h"
#endif
#include "shadowlog.h"
#include "string/sprintf.h"
#include "sssd.h"
#include "string/memset/memzero.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
#include "string/strtok/stpsep.h"
#ifndef SKEL_DIR
@@ -197,16 +202,16 @@ static bool home_added = false;
#define E_SUB_GID_UPDATE 18 /* can't update the subordinate gid file */
#endif /* ENABLE_SUBIDS */
#define DGROUP "GROUP="
#define DGROUPS "GROUPS="
#define DHOME "HOME="
#define DSHELL "SHELL="
#define DINACT "INACTIVE="
#define DEXPIRE "EXPIRE="
#define DSKEL "SKEL="
#define DUSRSKEL "USRSKEL="
#define DCREATE_MAIL_SPOOL "CREATE_MAIL_SPOOL="
#define DLOG_INIT "LOG_INIT="
#define DGROUP "GROUP"
#define DGROUPS "GROUPS"
#define DHOME "HOME"
#define DSHELL "SHELL"
#define DINACT "INACTIVE"
#define DEXPIRE "EXPIRE"
#define DSKEL "SKEL"
#define DUSRSKEL "USRSKEL"
#define DCREATE_MAIL_SPOOL "CREATE_MAIL_SPOOL"
#define DLOG_INIT "LOG_INIT"
/* local function prototypes */
NORETURN static void fail_exit (int);
@@ -238,7 +243,7 @@ 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);
static FILE *fmkomstemp(char *template, unsigned int flags, mode_t m);
/*
@@ -322,8 +327,6 @@ static void fail_exit (int code)
exit(code);
}
#define MATCH(x,y) (strncmp((x),(y),strlen(y)) == 0)
/*
* get_defaults - read the defaults file
*
@@ -331,7 +334,8 @@ static void fail_exit (int code)
* various values from the file, or uses built-in default values if the
* file does not exist.
*/
static void get_defaults (void)
static void
get_defaults(void)
{
FILE *fp;
char *default_file = USER_DEFAULTS_FILE;
@@ -358,29 +362,23 @@ static void get_defaults (void)
* values are used, everything else can be ignored.
*/
while (fgets (buf, sizeof buf, fp) == buf) {
cp = strrchr (buf, '\n');
if (NULL != cp) {
*cp = '\0';
}
stpsep(buf, "\n");
cp = strchr (buf, '=');
if (NULL == cp) {
cp = stpsep(buf, "=");
if (NULL == cp)
continue;
}
cp++;
/*
* Primary GROUP identifier
*/
if (MATCH (buf, DGROUP)) {
if (streq(buf, DGROUP)) {
const struct group *grp = prefix_getgr_nam_gid (cp);
if (NULL == grp) {
fprintf (stderr,
_("%s: group '%s' does not exist\n"),
Prog, cp);
fprintf (stderr,
_("%s: the %s configuration in %s will be ignored\n"),
_("%s: the %s= configuration in %s will be ignored\n"),
Prog, DGROUP, default_file);
} else {
def_group = grp->gr_gid;
@@ -390,10 +388,10 @@ static void get_defaults (void)
ccp = cp;
if (MATCH (buf, DGROUPS)) {
if (streq(buf, DGROUPS)) {
if (get_groups (cp) != 0) {
fprintf (stderr,
_("%s: the '%s' configuration in %s has an invalid group, ignoring the bad group\n"),
_("%s: the '%s=' configuration in %s has an invalid group, ignoring the bad group\n"),
Prog, DGROUPS, default_file);
}
if (user_groups[0] != NULL) {
@@ -404,28 +402,27 @@ static void get_defaults (void)
/*
* Default HOME filesystem
*/
else if (MATCH (buf, DHOME)) {
else if (streq(buf, DHOME)) {
def_home = xstrdup(ccp);
}
/*
* Default Login Shell command
*/
else if (MATCH (buf, DSHELL)) {
else if (streq(buf, DSHELL)) {
def_shell = xstrdup(ccp);
}
/*
* Default Password Inactive value
*/
else if (MATCH (buf, DINACT)) {
if ( (str2sl(&def_inactive, ccp) == -1)
|| (def_inactive < -1)) {
else if (streq(buf, DINACT)) {
if (a2sl(&def_inactive, ccp, NULL, 0, -1, LONG_MAX) == -1) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, ccp);
fprintf (stderr,
_("%s: the %s configuration in %s will be ignored\n"),
_("%s: the %s= configuration in %s will be ignored\n"),
Prog, DINACT, default_file);
def_inactive = -1;
}
@@ -434,14 +431,14 @@ static void get_defaults (void)
/*
* Default account expiration date
*/
else if (MATCH (buf, DEXPIRE)) {
else if (streq(buf, DEXPIRE)) {
def_expire = xstrdup(ccp);
}
/*
* Default Skeleton information
*/
else if (MATCH (buf, DSKEL)) {
else if (streq(buf, DSKEL)) {
if ('\0' == *ccp)
ccp = SKEL_DIR;
@@ -458,7 +455,7 @@ static void get_defaults (void)
/*
* Default Usr Skeleton information
*/
else if (MATCH (buf, DUSRSKEL)) {
else if (streq(buf, DUSRSKEL)) {
if ('\0' == *ccp)
ccp = USRSKELDIR;
@@ -474,7 +471,7 @@ static void get_defaults (void)
/*
* Create by default user mail spool or not ?
*/
else if (MATCH (buf, DCREATE_MAIL_SPOOL)) {
else if (streq(buf, DCREATE_MAIL_SPOOL)) {
if (*ccp == '\0')
ccp = "no";
@@ -484,7 +481,7 @@ static void get_defaults (void)
/*
* By default do we add the user to the lastlog and faillog databases ?
*/
else if (MATCH (buf, DLOG_INIT)) {
else if (streq(buf, DLOG_INIT)) {
if (*ccp == '\0')
ccp = def_log_init;
@@ -525,7 +522,8 @@ static void show_defaults (void)
* are currently set. Duplicated lines are pruned, missing lines are
* added, and unrecognized lines are copied as is.
*/
static int set_defaults (void)
static int
set_defaults(void)
{
int ret = -1;
bool out_group = false;
@@ -584,7 +582,7 @@ static int set_defaults (void)
/*
* Create a temporary file to copy the new output to.
*/
ofp = fmkstemp(new_file);
ofp = fmkomstemp(new_file, 0, 0644);
if (NULL == ofp) {
fprintf (stderr,
_("%s: cannot open new defaults file\n"),
@@ -604,10 +602,9 @@ static int set_defaults (void)
}
while (fgets (buf, sizeof buf, ifp) == buf) {
cp = strrchr (buf, '\n');
if (NULL != cp) {
*cp = '\0';
} else {
char *val;
if (stpsep(buf, "\n") == NULL) {
/* A line which does not end with \n is only valid
* at the end of the file.
*/
@@ -621,44 +618,46 @@ static int set_defaults (void)
}
}
if (!out_group && MATCH (buf, DGROUP)) {
fprintf (ofp, DGROUP "%u\n", (unsigned int) def_group);
val = stpsep(buf, "=");
if (val == NULL) {
fprintf(ofp, "%s\n", buf);
} else if (!out_group && streq(buf, DGROUP)) {
fprintf(ofp, DGROUP "=%u\n", (unsigned int) def_group);
out_group = true;
} else if (!out_groups && MATCH (buf, DGROUPS)) {
fprintf (ofp, DGROUPS "%s\n", def_groups);
} else if (!out_groups && streq(buf, DGROUPS)) {
fprintf(ofp, DGROUPS "=%s\n", def_groups);
out_groups = true;
} else if (!out_home && MATCH (buf, DHOME)) {
fprintf (ofp, DHOME "%s\n", def_home);
} else if (!out_home && streq(buf, DHOME)) {
fprintf(ofp, DHOME "=%s\n", def_home);
out_home = true;
} else if (!out_inactive && MATCH (buf, DINACT)) {
fprintf (ofp, DINACT "%ld\n", def_inactive);
} else if (!out_inactive && streq(buf, DINACT)) {
fprintf(ofp, DINACT "=%ld\n", def_inactive);
out_inactive = true;
} else if (!out_expire && MATCH (buf, DEXPIRE)) {
fprintf (ofp, DEXPIRE "%s\n", def_expire);
} else if (!out_expire && streq(buf, DEXPIRE)) {
fprintf(ofp, DEXPIRE "=%s\n", def_expire);
out_expire = true;
} else if (!out_shell && MATCH (buf, DSHELL)) {
fprintf (ofp, DSHELL "%s\n", def_shell);
} else if (!out_shell && streq(buf, DSHELL)) {
fprintf(ofp, DSHELL "=%s\n", def_shell);
out_shell = true;
} else if (!out_skel && MATCH (buf, DSKEL)) {
fprintf (ofp, DSKEL "%s\n", def_template);
} else if (!out_skel && streq(buf, DSKEL)) {
fprintf(ofp, DSKEL "=%s\n", def_template);
out_skel = true;
} else if (!out_usrskel && MATCH (buf, DUSRSKEL)) {
fprintf (ofp, DUSRSKEL "%s\n", def_usrtemplate);
} else if (!out_usrskel && streq(buf, DUSRSKEL)) {
fprintf(ofp, DUSRSKEL "=%s\n", def_usrtemplate);
out_usrskel = true;
} else if (!out_create_mail_spool
&& MATCH (buf, DCREATE_MAIL_SPOOL)) {
fprintf (ofp,
DCREATE_MAIL_SPOOL "%s\n",
def_create_mail_spool);
&& streq(buf, DCREATE_MAIL_SPOOL))
{
fprintf(ofp,
DCREATE_MAIL_SPOOL "=%s\n",
def_create_mail_spool);
out_create_mail_spool = true;
} else if (!out_log_init
&& MATCH (buf, DLOG_INIT)) {
fprintf (ofp,
DLOG_INIT "%s\n",
def_log_init);
} else if (!out_log_init && streq(buf, DLOG_INIT)) {
fprintf(ofp, DLOG_INIT "=%s\n", def_log_init);
out_log_init = true;
} else
fprintf (ofp, "%s\n", buf);
} else {
fprintf(ofp, "%s=%s\n", buf, val);
}
}
(void) fclose (ifp);
@@ -669,26 +668,26 @@ static int 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_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.
@@ -758,11 +757,19 @@ err_free_new:
*/
static int get_groups (char *list)
{
char *cp;
struct group *grp;
int errors = 0;
int ngroups = 0;
/*
* Free previous group list before creating a new one.
*/
int i = 0;
while (NULL != user_groups[i]) {
free(user_groups[i]);
user_groups[i++] = NULL;
}
if ('\0' == *list) {
return 0;
}
@@ -777,20 +784,19 @@ static int get_groups (char *list)
* each name and look it up. A mix of numerical and string
* values for group identifiers is permitted.
*/
do {
while (NULL != list) {
char *g;
/*
* Strip off a single name from the list
*/
cp = strchr (list, ',');
if (NULL != cp) {
*cp++ = '\0';
}
g = strsep(&list, ",");
/*
* Names starting with digits are treated as numerical
* GID values, otherwise the string is looked up as is.
*/
grp = get_local_group (list);
grp = get_local_group(g);
/*
* There must be a match, either by GID value or by
@@ -801,10 +807,9 @@ static int get_groups (char *list)
if (NULL == grp) {
fprintf (stderr,
_("%s: group '%s' does not exist\n"),
Prog, list);
Prog, g);
errors++;
}
list = cp;
/*
* If the group doesn't exist, don't dump core...
@@ -827,7 +832,7 @@ static int get_groups (char *list)
*/
user_groups[ngroups++] = xstrdup (grp->gr_name);
gr_free (grp);
} while (NULL != list);
}
close_group_files ();
unlock_group_files ();
@@ -853,21 +858,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;
gid_t gid;
struct group *result_grp = NULL;
const struct group *grp;
gid = strtoll(grp_name, &end, 10);
if ( ('\0' != *grp_name)
&& ('\0' == *end)
&& (ERANGE != errno)
&& (gid == (gid_t)gid)) {
grp = gr_locate_gid (gid);
}
else {
if (get_gid(grp_name, &gid) == 0)
grp = gr_locate_gid(gid);
else
grp = gr_locate(grp_name);
}
if (grp != NULL) {
result_grp = __gr_dup (grp);
@@ -1298,8 +1296,9 @@ static void process_flags (int argc, char **argv)
eflg = true;
break;
case 'f':
if ( (str2sl(&def_inactive, optarg) == -1)
|| (def_inactive < -1)) {
if (a2sl(&def_inactive, optarg, NULL, 0, -1, LONG_MAX)
== -1)
{
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -1360,16 +1359,13 @@ static void process_flags (int argc, char **argv)
* example: -K UID_MIN=100 -K UID_MAX=499
* note: -K UID_MIN=10,UID_MAX=499 doesn't work yet
*/
cp = strchr (optarg, '=');
cp = stpsep(optarg, "=");
if (NULL == cp) {
fprintf (stderr,
_("%s: -K requires KEY=VALUE\n"),
Prog);
exit (E_BAD_ARG);
}
/* terminate name, point to value */
*cp = '\0';
cp++;
if (putdef_str (optarg, cp, NULL) < 0) {
exit (E_BAD_ARG);
}
@@ -1417,7 +1413,7 @@ static void process_flags (int argc, char **argv)
}
if ( '\0' != optarg[0]
&& '*' != optarg[0]
&& strcmp(optarg, "/sbin/nologin") != 0
&& !streq(optarg, "/sbin/nologin")
&& ( stat(optarg, &st) != 0
|| S_ISDIR(st.st_mode)
|| access(optarg, X_OK) != 0)) {
@@ -1537,10 +1533,16 @@ static void process_flags (int argc, char **argv)
}
user_name = argv[optind];
if (!is_valid_user_name (user_name)) {
fprintf (stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, user_name);
if (!is_valid_user_name(user_name)) {
if (errno == EINVAL) {
fprintf(stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, user_name);
} else {
fprintf(stderr,
_("%s: invalid user name '%s'\n"),
Prog, user_name);
}
#ifdef WITH_AUDIT
audit_logger (AUDIT_ADD_USER, Prog,
"adding user",
@@ -1582,7 +1584,7 @@ static void process_flags (int argc, char **argv)
if (!lflg) {
/* If we are missing the flag lflg aka -l, check the defaults
* file to see if we need to disable it as a default*/
if (strcmp (def_log_init, "no") == 0) {
if (streq(def_log_init, "no")) {
lflg = true;
}
}
@@ -2050,7 +2052,7 @@ static void lastlog_reset (uid_t uid)
return;
}
if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid)
|| (write_full (fd, &ll, sizeof (ll)) != (ssize_t) sizeof (ll))
|| (write_full (fd, &ll, sizeof (ll)) == -1)
|| (fsync (fd) != 0)) {
fprintf (stderr,
_("%s: failed to reset the lastlog entry of UID %lu: %s\n"),
@@ -2089,11 +2091,7 @@ static void tallylog_reset (const char *user_name)
failed = 1;
break;
case 0: /* child */
pname = strrchr(pam_tally2, '/');
if (pname == NULL)
pname = pam_tally2;
else
pname++; /* Skip the '/' */
pname = Basename(pam_tally2);
execl(pam_tally2, pname, "--user", user_name, "--reset", "--quiet", NULL);
/* If we come here, something has gone terribly wrong */
perror(pam_tally2);
@@ -2237,7 +2235,7 @@ static void create_home (void)
if (access (prefix_user_home, F_OK) == 0)
return;
path[0] = '\0';
strcpy(path, "");
bhome = strdup(prefix_user_home);
if (!bhome) {
fprintf(stderr,
@@ -2283,7 +2281,7 @@ static void create_home (void)
Prog, path);
fail_exit(E_HOMEDIR);
}
btrfs_check[strlen(path) - strlen(cp) - 1] = '\0';
stpcpy(&btrfs_check[strlen(path) - strlen(cp) - 1], "");
if (is_btrfs(btrfs_check) <= 0) {
fprintf(stderr,
_("%s: home directory \"%s\" must be mounted on BTRFS\n"),
@@ -2749,21 +2747,25 @@ int main (int argc, char **argv)
static FILE *
fmkstemp(char *template)
fmkomstemp(char *template, unsigned int flags, mode_t m)
{
int fd;
FILE *fp;
fd = mkstemp(template);
fd = mkostemp(template, flags);
if (fd == -1)
return NULL;
if (fchmod(fd, m) == -1)
goto fail;
fp = fdopen(fd, "w");
if (fp == NULL) {
close(fd);
unlink(template);
return NULL;
}
if (fp == NULL)
goto fail;
return fp;
fail:
close(fd);
unlink(template);
return NULL;
}
+5 -4
View File
@@ -20,7 +20,6 @@
#include <sys/types.h>
#include <unistd.h>
#include "alloc.h"
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
#include "pam_defs.h"
@@ -52,7 +51,9 @@
#include "subordinateio.h"
#endif /* ENABLE_SUBIDS */
#include "shadowlog.h"
#include "string/sprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
/*
@@ -319,7 +320,7 @@ static void remove_usergroup (void)
*/
prefix_setpwent ();
while ((pwd = prefix_getpwent ()) != NULL) {
if (strcmp (pwd->pw_name, user_name) == 0) {
if (streq(pwd->pw_name, user_name)) {
continue;
}
if (pwd->pw_gid == grp->gr_gid) {
@@ -1183,7 +1184,7 @@ int main (int argc, char **argv)
*/
prefix_setpwent ();
while ((pwd = prefix_getpwent ())) {
if (strcmp (pwd->pw_name, user_name) == 0) {
if (streq(pwd->pw_name, user_name)) {
continue;
}
if (path_prefix (user_home, pwd->pw_dir)) {
+123 -97
View File
@@ -32,16 +32,18 @@
#include <sys/types.h>
#include <time.h>
#include "alloc.h"
#include "atoi/str2i.h"
#include "alloc/malloc.h"
#include "alloc/x/xmalloc.h"
#include "atoi/a2i/a2i.h"
#include "atoi/a2i/a2s.h"
#include "atoi/getnum.h"
#include "chkname.h"
#include "defines.h"
#include "faillog.h"
#include "getdef.h"
#include "groupio.h"
#include "memzero.h"
#include "must_be.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#include "pwauth.h"
#include "pwio.h"
@@ -59,7 +61,11 @@
#include "tcbfuncs.h"
#endif
#include "shadowlog.h"
#include "string/sprintf.h"
#include "sssd.h"
#include "string/memset/memzero.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
#include "time/day_to_str.h"
@@ -212,7 +218,6 @@ extern int allow_bad_names;
*/
static int get_groups (char *list)
{
char *cp;
struct group *grp;
int errors = 0;
int ngroups = 0;
@@ -231,21 +236,19 @@ static int get_groups (char *list)
* name and look it up. A mix of numerical and string values for
* group identifiers is permitted.
*/
do {
while (NULL != list) {
char *g;
/*
* Strip off a single name from the list
*/
cp = strchr (list, ',');
if (NULL != cp) {
*cp = '\0';
cp++;
}
g = strsep(&list, ",");
/*
* Names starting with digits are treated as numerical GID
* values, otherwise the string is looked up as is.
*/
grp = prefix_getgr_nam_gid (list);
grp = prefix_getgr_nam_gid(g);
/*
* There must be a match, either by GID value or by
@@ -253,10 +256,9 @@ static int get_groups (char *list)
*/
if (NULL == grp) {
fprintf (stderr, _("%s: group '%s' does not exist\n"),
Prog, list);
Prog, g);
errors++;
}
list = cp;
/*
* If the group doesn't exist, don't dump core. Instead,
@@ -279,7 +281,7 @@ static int get_groups (char *list)
*/
user_groups[ngroups++] = xstrdup (grp->gr_name);
gr_free (grp);
} while (NULL != list);
}
user_groups[ngroups] = NULL;
@@ -294,63 +296,64 @@ static int get_groups (char *list)
}
#ifdef ENABLE_SUBIDS
struct ulong_range
struct id_range
{
unsigned long first;
unsigned long last;
id_t first;
id_t last;
};
static struct ulong_range getulong_range(const char *str)
static struct id_range
getid_range(const char *str)
{
struct ulong_range result = { .first = ULONG_MAX, .last = 0 };
long long first, last;
char *pos;
id_t first, last;
const char *pos;
struct id_range result = {
.first = type_max(id_t),
.last = type_min(id_t)
};
errno = 0;
first = strtoll(str, &pos, 10);
if (('\0' == *str) || ('-' != *pos ) || (0 != errno) ||
(first != (unsigned long)first))
goto out;
static_assert(is_same_type(id_t, uid_t), "");
static_assert(is_same_type(id_t, gid_t), "");
errno = 0;
last = strtoll(pos + 1, &pos, 10);
if (('\0' != *pos ) || (0 != errno) ||
(last != (unsigned long)last))
goto out;
first = type_min(id_t);
last = type_max(id_t);
if (first > last)
goto out;
if (a2i(id_t, &first, str, &pos, 10, first, last) == -1
&& errno != ENOTSUP)
{
return result;
}
/*
* uid_t in linux is an unsigned int, anything over this is an invalid
* range will be later refused anyway by get_map_ranges().
*/
if (first > UINT_MAX || last > UINT_MAX)
goto out;
if ('-' != *pos++)
return result;
result.first = (unsigned long)first;
result.last = (unsigned long)last;
out:
if (a2i(id_t, &last, pos, NULL, 10, first, last) == -1)
return result;
result.first = first;
result.last = last;
return result;
}
struct ulong_range_list_entry {
struct ulong_range_list_entry *next;
struct ulong_range range;
struct id_range_list_entry {
struct id_range_list_entry *next;
struct id_range range;
};
static struct ulong_range_list_entry *add_sub_uids = NULL, *del_sub_uids = NULL;
static struct ulong_range_list_entry *add_sub_gids = NULL, *del_sub_gids = NULL;
static struct id_range_list_entry *add_sub_uids = NULL, *del_sub_uids = NULL;
static struct id_range_list_entry *add_sub_gids = NULL, *del_sub_gids = NULL;
static int prepend_range(const char *str, struct ulong_range_list_entry **head)
static int
prepend_range(const char *str, struct id_range_list_entry **head)
{
struct ulong_range range;
struct ulong_range_list_entry *entry;
range = getulong_range(str);
struct id_range range;
struct id_range_list_entry *entry;
range = getid_range(str);
if (range.first > range.last)
return 0;
entry = MALLOC(1, struct ulong_range_list_entry);
entry = MALLOC(1, struct id_range_list_entry);
if (!entry) {
fprintf (stderr,
_("%s: failed to allocate memory: %s\n"),
@@ -424,15 +427,14 @@ usage (int status)
static char *new_pw_passwd (char *pw_pass)
{
if (Lflg && ('!' != pw_pass[0])) {
char *buf = XMALLOC(strlen(pw_pass) + 2, char);
char *buf;
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"updating passwd", user_newname, user_newid, 0);
#endif
SYSLOG ((LOG_INFO, "lock user '%s' password", user_newname));
strcpy (buf, "!");
strcat (buf, pw_pass);
xasprintf(&buf, "!%s", pw_pass);
pw_pass = buf;
} else if (Uflg && pw_pass[0] == '!') {
if (pw_pass[1] == '\0') {
@@ -494,7 +496,7 @@ static void new_pwent (struct passwd *pwent)
* used for this account.
*/
if ( (!is_shadow_pwd)
|| (strcmp (pwent->pw_passwd, SHADOW_PASSWD_STRING) != 0)) {
|| !streq(pwent->pw_passwd, SHADOW_PASSWD_STRING)) {
pwent->pw_passwd = new_pw_passwd (pwent->pw_passwd);
}
@@ -981,7 +983,8 @@ static void grp_update (void)
* 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)
{
struct stat st;
bool anyflag = false;
@@ -1060,7 +1063,7 @@ static void process_flags (int argc, char **argv)
}
dflg = true;
user_newhome = optarg;
if (user_newhome[0] != '/') {
if ((user_newhome[0] != '/') && !streq(user_newhome, "")) {
fprintf (stderr,
_("%s: homedir must be an absolute path\n"),
Prog);
@@ -1078,8 +1081,9 @@ static void process_flags (int argc, char **argv)
eflg = true;
break;
case 'f':
if ( (str2sl(&user_newinactive, optarg) == -1)
|| (user_newinactive < -1)) {
if (a2sl(&user_newinactive, optarg, NULL, 0, -1, LONG_MAX)
== -1)
{
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"),
Prog, optarg);
@@ -1113,10 +1117,16 @@ static void process_flags (int argc, char **argv)
usage (E_SUCCESS);
/*@notreached@*/break;
case 'l':
if (!is_valid_user_name (optarg)) {
fprintf (stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, optarg);
if (!is_valid_user_name(optarg)) {
if (errno == EINVAL) {
fprintf(stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, optarg);
} else {
fprintf(stderr,
_("%s: invalid user name '%s'\n"),
Prog, optarg);
}
exit (E_BAD_ARG);
}
lflg = true;
@@ -1154,7 +1164,7 @@ static void process_flags (int argc, char **argv)
}
if ( '\0' != optarg[0]
&& '*' != optarg[0]
&& strcmp(optarg, "/sbin/nologin") != 0
&& !streq(optarg, "/sbin/nologin")
&& ( stat(optarg, &st) != 0
|| S_ISDIR(st.st_mode)
|| access(optarg, X_OK) != 0)) {
@@ -1364,10 +1374,10 @@ static void process_flags (int argc, char **argv)
gflg = false;
}
if ( (NULL != user_newshell)
&& (strcmp (user_newshell, user_shell) == 0)) {
&& streq(user_newshell, user_shell)) {
sflg = false;
}
if (strcmp (user_newname, user_name) == 0) {
if (streq(user_newname, user_name)) {
lflg = false;
}
if (user_newinactive == user_inactive) {
@@ -1377,12 +1387,12 @@ static void process_flags (int argc, char **argv)
eflg = false;
}
if ( (NULL != user_newhome)
&& (strcmp (user_newhome, user_home) == 0)) {
&& streq(user_newhome, user_home)) {
dflg = false;
mflg = false;
}
if ( (NULL != user_newcomment)
&& (strcmp (user_newcomment, user_comment) == 0)) {
&& streq(user_newcomment, user_comment)) {
cflg = false;
}
@@ -1717,7 +1727,7 @@ static void usr_update (void)
spent = *spwd;
new_spent (&spent);
} else if ( ( pflg
&& (strcmp (pwent.pw_passwd, SHADOW_PASSWD_STRING) == 0))
&& streq(pwent.pw_passwd, SHADOW_PASSWD_STRING))
|| eflg || fflg) {
/* In some cases, we force the creation of a
* shadow entry:
@@ -1794,7 +1804,7 @@ static void move_home (void)
if (access (prefix_user_newhome, F_OK) == 0) {
/*
* If the new home directory already exist, the user
* If the new home directory already exists, the user
* should not use -m.
*/
fprintf (stderr,
@@ -2241,53 +2251,69 @@ int main (int argc, char **argv)
}
#ifdef ENABLE_SUBIDS
if (Vflg) {
struct ulong_range_list_entry *ptr;
struct id_range_list_entry *ptr;
for (ptr = del_sub_uids; ptr != NULL; ptr = ptr->next) {
unsigned long count = ptr->range.last - ptr->range.first + 1;
id_t count = ptr->range.last - ptr->range.first + 1;
if (sub_uid_remove(user_name, ptr->range.first, count) == 0) {
fprintf (stderr,
_("%s: failed to remove uid range %lu-%lu from '%s'\n"),
Prog, ptr->range.first, ptr->range.last,
sub_uid_dbname ());
fprintf(stderr,
_("%s: failed to remove uid range %ju-%ju from '%s'\n"),
Prog,
(uintmax_t) ptr->range.first,
(uintmax_t) ptr->range.last,
sub_uid_dbname());
fail_exit (E_SUB_UID_UPDATE);
}
}
}
if (vflg) {
struct ulong_range_list_entry *ptr;
struct id_range_list_entry *ptr;
for (ptr = add_sub_uids; ptr != NULL; ptr = ptr->next) {
unsigned long count = ptr->range.last - ptr->range.first + 1;
id_t count = ptr->range.last - ptr->range.first + 1;
if (sub_uid_add(user_name, ptr->range.first, count) == 0) {
fprintf (stderr,
_("%s: failed to add uid range %lu-%lu to '%s'\n"),
Prog, ptr->range.first, ptr->range.last,
sub_uid_dbname ());
fprintf(stderr,
_("%s: failed to add uid range %ju-%ju to '%s'\n"),
Prog,
(uintmax_t) ptr->range.first,
(uintmax_t) ptr->range.last,
sub_uid_dbname());
fail_exit (E_SUB_UID_UPDATE);
}
}
}
if (Wflg) {
struct ulong_range_list_entry *ptr;
struct id_range_list_entry *ptr;
for (ptr = del_sub_gids; ptr != NULL; ptr = ptr->next) {
unsigned long count = ptr->range.last - ptr->range.first + 1;
id_t count = ptr->range.last - ptr->range.first + 1;
if (sub_gid_remove(user_name, ptr->range.first, count) == 0) {
fprintf (stderr,
_("%s: failed to remove gid range %lu-%lu from '%s'\n"),
Prog, ptr->range.first, ptr->range.last,
sub_gid_dbname ());
fprintf(stderr,
_("%s: failed to remove gid range %ju-%ju from '%s'\n"),
Prog,
(uintmax_t) ptr->range.first,
(uintmax_t) ptr->range.last,
sub_gid_dbname());
fail_exit (E_SUB_GID_UPDATE);
}
}
}
if (wflg) {
struct ulong_range_list_entry *ptr;
struct id_range_list_entry *ptr;
for (ptr = add_sub_gids; ptr != NULL; ptr = ptr->next) {
unsigned long count = ptr->range.last - ptr->range.first + 1;
id_t count = ptr->range.last - ptr->range.first + 1;
if (sub_gid_add(user_name, ptr->range.first, count) == 0) {
fprintf (stderr,
_("%s: failed to add gid range %lu-%lu to '%s'\n"),
Prog, ptr->range.first, ptr->range.last,
sub_gid_dbname ());
fprintf(stderr,
_("%s: failed to add gid range %ju-%ju to '%s'\n"),
Prog,
(uintmax_t) ptr->range.first,
(uintmax_t) ptr->range.last,
sub_gid_dbname());
fail_exit (E_SUB_GID_UPDATE);
}
}
+7 -6
View File
@@ -27,12 +27,10 @@
#include <unistd.h>
#include <utime.h>
#include "alloc.h"
#include "defines.h"
#include "getdef.h"
#include "groupio.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
#include "pwio.h"
#include "sgroupio.h"
@@ -44,7 +42,10 @@
#include "tcbfuncs.h"
#endif /* WITH_TCB */
#include "shadowlog.h"
#include "string/sprintf.h"
#include "sssd.h"
#include "string/sprintf/snprintf.h"
#include "string/sprintf/xasprintf.h"
#include "string/strcmp/streq.h"
#define MSG_WARN_EDIT_OTHER_FILE _( \
@@ -389,7 +390,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
vipwexit (fileedit, 1, 1);
}
if (st1.st_mtime == st2.st_mtime) {
vipwexit (0, 0, 0);
vipwexit(NULL, 0, 0);
}
#ifdef WITH_SELINUX
/* unset the fscreatecon */
@@ -446,7 +447,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
free(to_rename);
}
#endif /* WITH_TCB */
vipwexit (0, 0, 1);
vipwexit(NULL, 0, 1);
}
#ifdef WITH_TCB
@@ -471,7 +472,7 @@ int main (int argc, char **argv)
bool editshadow = false;
bool do_vigr;
do_vigr = (strcmp(Basename(argv[0]), "vigr") == 0);
do_vigr = streq(Basename(argv[0]), "vigr");
Prog = do_vigr ? "vigr" : "vipw";
log_set_progname(Prog);