]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Use xaprintf() instead of xasprintf()
authorAlejandro Colomar <alx@kernel.org>
Wed, 1 Jan 2025 13:41:18 +0000 (14:41 +0100)
committerSerge Hallyn <serge@hallyn.com>
Wed, 4 Jun 2025 04:25:02 +0000 (23:25 -0500)
This makes some temporary variables unnecessary.  They'll be removed in
the next commit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 files changed:
lib/Makefile.am
lib/copydir.c
lib/env.c
lib/getdef.c
lib/mail.c
lib/obscure.c
lib/prefix_flag.c
lib/setupenv.c
src/passwd.c
src/su.c
src/useradd.c
src/userdel.c
src/usermod.c
src/vipw.c

index 621ac29e3cbae8b86075585320f13b501ad7d7e8..788862d63e45973de5de5e30441b7bb144b2bcb8 100644 (file)
@@ -199,8 +199,8 @@ libshadow_la_SOURCES = \
        string/sprintf/snprintf.h \
        string/sprintf/stpeprintf.c \
        string/sprintf/stpeprintf.h \
-       string/sprintf/xasprintf.c \
-       string/sprintf/xasprintf.h \
+       string/sprintf/xaprintf.c \
+       string/sprintf/xaprintf.h \
        string/strchr/strchrcnt.c \
        string/strchr/strchrcnt.h \
        string/strchr/strchrscnt.c \
index 9dbe6fd6f44fd77c5a3ac55a38746b57791a8325..37462dd8069a20eefd7bc330c809b41cc8812bd6 100644 (file)
@@ -39,7 +39,7 @@
 #endif                         /* WITH_ATTR */
 #include "shadowlog.h"
 #include "string/sprintf/aprintf.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 
@@ -234,7 +234,7 @@ static /*@exposed@*/ /*@null@*/struct link_name *check_link (const char *name, c
        lp->ln_dev = sb->st_dev;
        lp->ln_ino = sb->st_ino;
        lp->ln_count = sb->st_nlink;
-       xasprintf(&lp->ln_name, "%s%s", dst_orig, name + strlen(src_orig));
+       lp->ln_name = xaprintf("%s%s", dst_orig, name + strlen(src_orig));
        lp->ln_next = links;
        links = lp;
 
@@ -581,7 +581,7 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds
        if (strprefix(oldlink, src_orig)) {
                char  *dummy;
 
-               xasprintf(&dummy, "%s%s", dst_orig, oldlink + strlen(src_orig));
+               dummy = xaprintf("%s%s", dst_orig, oldlink + strlen(src_orig));
                free(oldlink);
                oldlink = dummy;
        }
index 9a21a368e0a47de58eec4f63f705811a567255e0..5eb585347e435c34315a4fcbe787e2160b75244b 100644 (file)
--- a/lib/env.c
+++ b/lib/env.c
@@ -22,7 +22,7 @@
 #include "defines.h"
 #include "shadowlog.h"
 #include "string/sprintf/snprintf.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strdup/xstrdup.h"
 
@@ -78,7 +78,7 @@ void addenv (const char *string, /*@null@*/const char *value)
        size_t  i, n;
 
        if (NULL != value) {
-               xasprintf(&newstring, "%s=%s", string, value);
+               newstring = xaprintf("%s=%s", string, value);
        } else {
                newstring = xstrdup (string);
        }
index 84bc939b88825d9142a7ed5175b2e5d55422fde4..b83a820dd30099aca931333f9735e0901e3eb5d9 100644 (file)
@@ -30,7 +30,7 @@
 #include "prototypes.h"
 #include "shadowlog_internal.h"
 #include "sizeof.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/strcaseeq.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
@@ -458,10 +458,10 @@ void setdef_config_file (const char* file)
 #ifdef USE_ECONF
        char  *cp;
 
-       xasprintf(&cp, "%s/%s", file, sysconfdir);
+       cp = xaprintf("%s/%s", file, sysconfdir);
        sysconfdir = cp;
 #ifdef VENDORDIR
-       xasprintf(&cp, "%s/%s", file, vendordir);
+       cp = xaprintf("%s/%s", file, vendordir);
        vendordir = cp;
 #endif
 #else
index b62287e6a51892c12bf862e37962d1c7608334cf..968bfa41ca4ca5cee621f70647ac1dfa42069106 100644 (file)
@@ -16,7 +16,7 @@
 #include <string.h>
 
 #include "getdef.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 
 #ident "$Id$"
 
@@ -37,7 +37,7 @@ void mailcheck (void)
        if (NULL != mailbox) {
                char  *newmail;
 
-               xasprintf(&newmail, "%s/new", mailbox);
+               newmail = xaprintf("%s/new", mailbox);
 
                if (stat (newmail, &statbuf) != -1 && statbuf.st_size != 0) {
                        if (statbuf.st_mtime > statbuf.st_atime) {
index eca4338a896dd3d8b6a269cd456d3f6a254eba41..ad13d50a893a99fc156596d7f41946f3dbb63ad6 100644 (file)
@@ -20,7 +20,7 @@
 #include "getdef.h"
 #include "string/ctype/strtoascii/strtolower.h"
 #include "string/memset/memzero.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strdup/xstrdup.h"
 
@@ -93,7 +93,7 @@ static /*@observer@*//*@null@*/const char *password_check (
 
        newmono = strtolower(xstrdup(new));
        oldmono = strtolower(xstrdup(old));
-       xasprintf(&wrapped, "%s%s", oldmono, oldmono);
+       wrapped = xaprintf("%s%s", oldmono, oldmono);
 
        if (palindrome (oldmono, newmono)) {
                msg = _("a palindrome");
index 53c13fafb304046c4a349f8d632420d6689adda4..a2bac36a3de65ea87827087767fdf96baea3a298 100644 (file)
@@ -28,7 +28,7 @@
 #endif                         /* ENABLE_SUBIDS */
 #include "getdef.h"
 #include "shadowlog.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 
@@ -108,32 +108,32 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char **
                        exit (E_BAD_ARG);
                }
 
-               xasprintf(&passwd_db_file, "%s/%s", prefix, PASSWD_FILE);
+               passwd_db_file = xaprintf("%s/%s", prefix, PASSWD_FILE);
                pw_setdbname(passwd_db_file);
 
-               xasprintf(&group_db_file, "%s/%s", prefix, GROUP_FILE);
+               group_db_file = xaprintf("%s/%s", prefix, GROUP_FILE);
                gr_setdbname(group_db_file);
 
 #ifdef  SHADOWGRP
-               xasprintf(&sgroup_db_file, "%s/%s", prefix, SGROUP_FILE);
+               sgroup_db_file = xaprintf("%s/%s", prefix, SGROUP_FILE);
                sgr_setdbname(sgroup_db_file);
 #endif
 
-               xasprintf(&spw_db_file, "%s/%s", prefix, SHADOW_FILE);
+               spw_db_file = xaprintf("%s/%s", prefix, SHADOW_FILE);
                spw_setdbname(spw_db_file);
 
 #ifdef ENABLE_SUBIDS
-               xasprintf(&suid_db_file, "%s/%s", prefix, SUBUID_FILE);
+               suid_db_file = xaprintf("%s/%s", prefix, SUBUID_FILE);
                sub_uid_setdbname(suid_db_file);
 
-               xasprintf(&sgid_db_file, "%s/%s", prefix, SUBGID_FILE);
+               sgid_db_file = xaprintf("%s/%s", prefix, SUBGID_FILE);
                sub_gid_setdbname(sgid_db_file);
 #endif
 
 #ifdef USE_ECONF
                setdef_config_file(prefix);
 #else
-               xasprintf(&def_conf_file, "%s/%s", prefix, "/etc/login.defs");
+               def_conf_file = xaprintf("%s/%s", prefix, "/etc/login.defs");
                setdef_config_file(def_conf_file);
 #endif
        }
index 29e2aac3cbe72e664c1dd08df704d1414535704b..8aee2121a0f855b2d2dc231edd8e827430495e96 100644 (file)
@@ -26,7 +26,7 @@
 #include <pwd.h>
 #include "getdef.h"
 #include "shadowlog.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strdup/xstrdup.h"
@@ -40,7 +40,7 @@ addenv_path(const char *varname, const char *dirname, const char *filename)
 {
        char  *buf;
 
-       xasprintf(&buf, "%s/%s", dirname, filename);
+       buf = xaprintf("%s/%s", dirname, filename);
        addenv(varname, buf);
        free(buf);
 }
index df3394a04f59afbffd13f89a3f95a0c857c682ac..cdd817a25c22172ac0df36116b7e247be255af10 100644 (file)
@@ -33,7 +33,7 @@
 #include "shadowlog.h"
 #include "sssd.h"
 #include "string/memset/memzero.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strcpy/strtcpy.h"
@@ -536,7 +536,7 @@ static char *update_crypt_pw (char *cp)
        if (lflg && *cp != '!') {
                char  *newpw;
 
-               xasprintf(&newpw, "!%s", cp);
+               newpw = xaprintf("!%s", cp);
                if (!use_pam)
                {
                        if (do_update_pwd) {
index 0902c49a6322d48e621d1c6d31f6e4a0dfd50a0f..7718d1597c3b31a61ffbaa8cb65e77fdca967f68 100644 (file)
--- a/src/su.c
+++ b/src/su.c
@@ -60,7 +60,7 @@
 #include "prototypes.h"
 #include "shadowlog.h"
 #include "string/sprintf/snprintf.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strcpy/strtcpy.h"
@@ -1212,7 +1212,7 @@ int main (int argc, char **argv)
                        cp = Basename (shellstr);
                }
 
-               xasprintf(&arg0, "-%s", cp);
+               arg0 = xaprintf("-%s", cp);
                cp = arg0;
        } else {
                cp = Basename (shellstr);
index 0821e03ee3c80c628f5c655b5d88317d2b8c96e0..001d63f63c7f6ba4a8ebe60caa0aede271ad89e5 100644 (file)
@@ -68,7 +68,7 @@
 #include "string/memset/memzero.h"
 #include "string/sprintf/aprintf.h"
 #include "string/sprintf/snprintf.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/strcaseeq.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
@@ -433,7 +433,7 @@ get_defaults(void)
                        if (prefix[0]) {
                                char  *dt;
 
-                               xasprintf(&dt, "%s/%s", prefix, ccp);
+                               dt = xaprintf("%s/%s", prefix, ccp);
                                def_template = dt;
                        } else {
                                def_template = xstrdup(ccp);
@@ -450,7 +450,7 @@ get_defaults(void)
                        if (prefix[0]) {
                                char  *dut;
 
-                               xasprintf(&dut, "%s/%s", prefix, ccp);
+                               dut = xaprintf("%s/%s", prefix, ccp);
                                def_usrtemplate = dut;
                        } else {
                                def_usrtemplate = xstrdup(ccp);
@@ -1520,13 +1520,13 @@ static void process_flags (int argc, char **argv)
                if (!dflg) {
                        char  *uh;
 
-                       xasprintf(&uh, "%s/%s", def_home, user_name);
+                       uh = xaprintf("%s/%s", def_home, user_name);
                        user_home = uh;
                }
                if (prefix[0]) {
                        char  *puh; /* to avoid const warning */
 
-                       xasprintf(&puh, "%s/%s", prefix, user_home);
+                       puh = xaprintf("%s/%s", prefix, user_home);
                        prefix_user_home = puh;
                } else {
                        prefix_user_home = user_home;
@@ -2330,9 +2330,9 @@ static void create_mail (void)
                return;
        }
        if (prefix[0])
-               xasprintf(&file, "%s/%s/%s", prefix, spool, user_name);
+               file = xaprintf("%s/%s/%s", prefix, spool, user_name);
        else
-               xasprintf(&file, "%s/%s", spool, user_name);
+               file = xaprintf("%s/%s", spool, user_name);
 
 #ifdef WITH_SELINUX
        if (set_selinux_file_context(file, S_IFREG) != 0) {
index caf34606c582460253d6d5c95c89eaa23db49c06..72ce11fac3aa8146a567c843010280fd2b1ab4a7 100644 (file)
@@ -52,7 +52,7 @@
 #endif                         /* ENABLE_SUBIDS */
 #include "shadowlog.h"
 #include "string/sprintf/aprintf.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strdup/xstrdup.h"
@@ -751,9 +751,9 @@ static bool remove_mailbox (void)
        }
 
        if (prefix[0]) {
-               xasprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name);
+               mailfile = xaprintf("%s/%s/%s", prefix, maildir, user_name);
        } else {
-               xasprintf(&mailfile, "%s/%s", maildir, user_name);
+               mailfile = xaprintf("%s/%s", maildir, user_name);
        }
 
        if (access (mailfile, F_OK) != 0) {
@@ -1061,7 +1061,7 @@ int main (int argc, char **argv)
                user_gid = pwd->pw_gid;
 
                if (prefix[0]) {
-                       xasprintf(&user_home, "%s/%s", prefix, pwd->pw_dir);
+                       user_home = xaprintf("%s/%s", prefix, pwd->pw_dir);
                } else {
                        user_home = xstrdup(pwd->pw_dir);
                }
index cbae052fbe212adae9c4c18bcfd347c9e17e0288..48649eb128c54369ef9f56e512bd7a46af46b21c 100644 (file)
@@ -62,7 +62,7 @@
 #include "shadowlog.h"
 #include "sssd.h"
 #include "string/memset/memzero.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strdup/xstrdup.h"
@@ -435,7 +435,7 @@ static char *new_pw_passwd (char *pw_pass)
                              "updating-passwd", user_newname, user_newid, 1);
 #endif
                SYSLOG ((LOG_INFO, "lock user '%s' password", user_newname));
-               xasprintf(&buf, "!%s", pw_pass);
+               buf = xaprintf("!%s", pw_pass);
                pw_pass = buf;
        } else if (Uflg && strprefix(pw_pass, "!")) {
                if (pw_pass[1] == '\0') {
@@ -1304,10 +1304,10 @@ process_flags(int argc, char **argv)
                user_newgid = user_gid;
        }
        if (prefix[0]) {
-               xasprintf(&prefix_user_home, "%s/%s", prefix, user_home);
+               prefix_user_home = xaprintf("%s/%s", prefix, user_home);
                if (user_newhome) {
-                       xasprintf(&prefix_user_newhome, "%s/%s",
-                                 prefix, user_newhome);
+                       prefix_user_newhome = xaprintf("%s/%s",
+                                                      prefix, user_newhome);
                }
        } else {
                prefix_user_home = user_home;
@@ -2081,9 +2081,9 @@ static void move_mailbox (void)
         * between stat and chown).  --marekm
         */
        if (prefix[0]) {
-               xasprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name);
+               mailfile = xaprintf("%s/%s/%s", prefix, maildir, user_name);
        } else {
-               xasprintf(&mailfile, "%s/%s", maildir, user_name);
+               mailfile = xaprintf("%s/%s", maildir, user_name);
        }
 
        fd = open (mailfile, O_RDONLY | O_NONBLOCK, 0);
@@ -2128,10 +2128,10 @@ static void move_mailbox (void)
                char  *newmailfile;
 
                if (prefix[0]) {
-                       xasprintf(&newmailfile, "%s/%s/%s",
-                                 prefix, maildir, user_newname);
+                       newmailfile = xaprintf("%s/%s/%s",
+                                              prefix, maildir, user_newname);
                } else {
-                       xasprintf(&newmailfile, "%s/%s", maildir, user_newname);
+                       newmailfile = xaprintf("%s/%s", maildir, user_newname);
                }
                if (   (link (mailfile, newmailfile) != 0)
                    || (unlink (mailfile) != 0)) {
index e729d6dfb7fc0730d7ff83d685e6d01090d6105b..3c840e9f246b33196d916982bc2e9d89ce0fe395 100644 (file)
@@ -45,7 +45,7 @@
 #include "sssd.h"
 #include "string/sprintf/aprintf.h"
 #include "string/sprintf/snprintf.h"
-#include "string/sprintf/xasprintf.h"
+#include "string/sprintf/xaprintf.h"
 #include "string/strcmp/streq.h"
 
 
@@ -308,7 +308,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
                                continue;
                }
 
-               xasprintf(&buf, "%s %s", editor, fileedit);
+               buf = xaprintf("%s %s", editor, fileedit);
 
                status = system (buf);
                if (-1 == status) {