From: Alejandro Colomar Date: Wed, 1 Jan 2025 13:41:18 +0000 (+0100) Subject: lib/, src/: Use xaprintf() instead of xasprintf() X-Git-Tag: 4.18.0-rc1~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d7a049a86b198a981c7f9059aa627ff4a045467;p=thirdparty%2Fshadow.git lib/, src/: Use xaprintf() instead of xasprintf() This makes some temporary variables unnecessary. They'll be removed in the next commit. Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index 621ac29e3..788862d63 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 \ diff --git a/lib/copydir.c b/lib/copydir.c index 9dbe6fd6f..37462dd80 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -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; } diff --git a/lib/env.c b/lib/env.c index 9a21a368e..5eb585347 100644 --- 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); } diff --git a/lib/getdef.c b/lib/getdef.c index 84bc939b8..b83a820dd 100644 --- a/lib/getdef.c +++ b/lib/getdef.c @@ -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 diff --git a/lib/mail.c b/lib/mail.c index b62287e6a..968bfa41c 100644 --- a/lib/mail.c +++ b/lib/mail.c @@ -16,7 +16,7 @@ #include #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) { diff --git a/lib/obscure.c b/lib/obscure.c index eca4338a8..ad13d50a8 100644 --- a/lib/obscure.c +++ b/lib/obscure.c @@ -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"); diff --git a/lib/prefix_flag.c b/lib/prefix_flag.c index 53c13fafb..a2bac36a3 100644 --- a/lib/prefix_flag.c +++ b/lib/prefix_flag.c @@ -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 } diff --git a/lib/setupenv.c b/lib/setupenv.c index 29e2aac3c..8aee2121a 100644 --- a/lib/setupenv.c +++ b/lib/setupenv.c @@ -26,7 +26,7 @@ #include #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); } diff --git a/src/passwd.c b/src/passwd.c index df3394a04..cdd817a25 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -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) { diff --git a/src/su.c b/src/su.c index 0902c49a6..7718d1597 100644 --- 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); diff --git a/src/useradd.c b/src/useradd.c index 0821e03ee..001d63f63 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -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) { diff --git a/src/userdel.c b/src/userdel.c index caf34606c..72ce11fac 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -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); } diff --git a/src/usermod.c b/src/usermod.c index cbae052fb..48649eb12 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -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)) { diff --git a/src/vipw.c b/src/vipw.c index e729d6dfb..3c840e9f2 100644 --- a/src/vipw.c +++ b/src/vipw.c @@ -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) {