lib/, src/: Use xasprintf() instead of its pattern
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
+4
-5
@@ -35,6 +35,7 @@
|
||||
#include <attr/libattr.h>
|
||||
#endif /* WITH_ATTR */
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
static /*@null@*/const char *src_orig;
|
||||
@@ -228,8 +229,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;
|
||||
if (asprintf(&lp->ln_name, "%s%s", dst_orig, name + strlen(src_orig)) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&lp->ln_name, "%s%s", dst_orig, name + strlen(src_orig));
|
||||
lp->ln_next = links;
|
||||
links = lp;
|
||||
|
||||
@@ -608,11 +608,10 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds
|
||||
* create a link to the corresponding entry in the dst_orig
|
||||
* directory.
|
||||
*/
|
||||
if (strncmp (oldlink, src_orig, strlen (src_orig)) == 0) {
|
||||
if (strncmp(oldlink, src_orig, strlen(src_orig)) == 0) {
|
||||
char *dummy;
|
||||
|
||||
if (asprintf(&dummy, "%s%s", dst_orig, oldlink + strlen(src_orig)) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&dummy, "%s%s", dst_orig, oldlink + strlen(src_orig));
|
||||
free(oldlink);
|
||||
oldlink = dummy;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -73,8 +74,7 @@ void addenv (const char *string, /*@null@*/const char *value)
|
||||
size_t i, n;
|
||||
|
||||
if (NULL != value) {
|
||||
if (asprintf(&newstring, "%s=%s", string, value) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&newstring, "%s=%s", string, value);
|
||||
} else {
|
||||
newstring = xstrdup (string);
|
||||
}
|
||||
|
||||
+3
-4
@@ -25,6 +25,7 @@
|
||||
#include "alloc.h"
|
||||
#include "getdef.h"
|
||||
#include "shadowlog_internal.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -447,12 +448,10 @@ void setdef_config_file (const char* file)
|
||||
#ifdef USE_ECONF
|
||||
char *cp;
|
||||
|
||||
if (asprintf(&cp, "%s/%s", file, sysconfdir) == -1)
|
||||
exit(13);
|
||||
xasprintf(&cp, "%s/%s", file, sysconfdir);
|
||||
sysconfdir = cp;
|
||||
#ifdef VENDORDIR
|
||||
if (asprintf(&cp, "%s/%s", file, vendordir) == -1)
|
||||
exit(13);
|
||||
xasprintf(&cp, "%s/%s", file, vendordir);
|
||||
vendordir = cp;
|
||||
#endif
|
||||
#else
|
||||
|
||||
+2
-2
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "alloc.h"
|
||||
#include "getdef.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
@@ -37,8 +38,7 @@ void mailcheck (void)
|
||||
if (NULL != mailbox) {
|
||||
char *newmail;
|
||||
|
||||
if (asprintf(&newmail, "%s/new", mailbox) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&newmail, "%s/new", mailbox);
|
||||
|
||||
if (stat (newmail, &statbuf) != -1 && statbuf.st_size != 0) {
|
||||
if (statbuf.st_mtime > statbuf.st_atime) {
|
||||
|
||||
+8
-14
@@ -28,6 +28,7 @@
|
||||
#endif /* ENABLE_SUBIDS */
|
||||
#include "getdef.h"
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
static char *passwd_db_file = NULL;
|
||||
@@ -106,42 +107,35 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char **
|
||||
exit (E_BAD_ARG);
|
||||
}
|
||||
|
||||
if (asprintf(&passwd_db_file, "%s/%s", prefix, PASSWD_FILE) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&passwd_db_file, "%s/%s", prefix, PASSWD_FILE);
|
||||
pw_setdbname(passwd_db_file);
|
||||
|
||||
if (asprintf(&group_db_file, "%s/%s", prefix, GROUP_FILE) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&group_db_file, "%s/%s", prefix, GROUP_FILE);
|
||||
gr_setdbname(group_db_file);
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
if (asprintf(&sgroup_db_file, "%s/%s", prefix, SGROUP_FILE) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&sgroup_db_file, "%s/%s", prefix, SGROUP_FILE);
|
||||
sgr_setdbname(sgroup_db_file);
|
||||
#endif
|
||||
#ifdef USE_NIS
|
||||
__setspNIS(0); /* disable NIS for now, at least until it is properly supporting a "prefix" */
|
||||
#endif
|
||||
|
||||
if (asprintf(&spw_db_file, "%s/%s", prefix, SHADOW_FILE) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&spw_db_file, "%s/%s", prefix, SHADOW_FILE);
|
||||
spw_setdbname(spw_db_file);
|
||||
|
||||
#ifdef ENABLE_SUBIDS
|
||||
if (asprintf(&suid_db_file, "%s/%s", prefix, "/etc/subuid") == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&suid_db_file, "%s/%s", prefix, "/etc/subuid");
|
||||
sub_uid_setdbname(suid_db_file);
|
||||
|
||||
if (asprintf(&sgid_db_file, "%s/%s", prefix, "/etc/subgid") == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&sgid_db_file, "%s/%s", prefix, "/etc/subgid");
|
||||
sub_gid_setdbname(sgid_db_file);
|
||||
#endif
|
||||
|
||||
#ifdef USE_ECONF
|
||||
setdef_config_file(prefix);
|
||||
#else
|
||||
if (asprintf(&def_conf_file, "%s/%s", prefix, "/etc/login.defs") == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&def_conf_file, "%s/%s", prefix, "/etc/login.defs");
|
||||
setdef_config_file(def_conf_file);
|
||||
#endif
|
||||
}
|
||||
|
||||
+4
-5
@@ -27,18 +27,17 @@
|
||||
#include <pwd.h>
|
||||
#include "getdef.h"
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
#ifndef USE_PAM
|
||||
static void
|
||||
addenv_path (const char *varname, const char *dirname, const char *filename)
|
||||
addenv_path(const char *varname, const char *dirname, const char *filename)
|
||||
{
|
||||
char *buf;
|
||||
|
||||
if (asprintf(&buf, "%s/%s", dirname, filename) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
addenv (varname, buf);
|
||||
xasprintf(&buf, "%s/%s", dirname, filename);
|
||||
addenv(varname, buf);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
|
||||
+11
-14
@@ -63,6 +63,7 @@
|
||||
#include "tcbfuncs.h"
|
||||
#endif
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
#ifndef SKEL_DIR
|
||||
@@ -440,11 +441,10 @@ static void get_defaults (void)
|
||||
}
|
||||
|
||||
if (prefix[0]) {
|
||||
char *_def_template; /* avoid const warning */
|
||||
char *dt; /* avoid const warning */
|
||||
|
||||
if (asprintf(&_def_template, "%s/%s", prefix, cp) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
def_template = _def_template;
|
||||
xasprintf(&dt, "%s/%s", prefix, cp);
|
||||
def_template = dt;
|
||||
} else {
|
||||
def_template = xstrdup(cp);
|
||||
}
|
||||
@@ -459,11 +459,10 @@ static void get_defaults (void)
|
||||
}
|
||||
|
||||
if (prefix[0]) {
|
||||
char *_def_usrtemplate; /* avoid const warning */
|
||||
char *dut; /* avoid const warning */
|
||||
|
||||
if (asprintf(&_def_usrtemplate, "%s/%s", prefix, cp) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
def_usrtemplate = _def_usrtemplate;
|
||||
xasprintf(&dut, "%s/%s", prefix, cp);
|
||||
def_usrtemplate = dut;
|
||||
} else {
|
||||
def_usrtemplate = xstrdup(cp);
|
||||
}
|
||||
@@ -1582,16 +1581,14 @@ static void process_flags (int argc, char **argv)
|
||||
if (!dflg) {
|
||||
char *uh;
|
||||
|
||||
if (asprintf(&uh, "%s/%s", def_home, user_name) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&uh, "%s/%s", def_home, user_name);
|
||||
user_home = uh;
|
||||
}
|
||||
if (prefix[0]) {
|
||||
char *p_u_h; /* to avoid const warning */
|
||||
char *puh; /* to avoid const warning */
|
||||
|
||||
if (asprintf(&p_u_h, "%s/%s", prefix, user_home) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
prefix_user_home = p_u_h;
|
||||
xasprintf(&puh, "%s/%s", prefix, user_home);
|
||||
prefix_user_home = puh;
|
||||
} else {
|
||||
prefix_user_home = user_home;
|
||||
}
|
||||
|
||||
+4
-6
@@ -52,6 +52,7 @@
|
||||
#include "subordinateio.h"
|
||||
#endif /* ENABLE_SUBIDS */
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -804,11 +805,9 @@ static int remove_mailbox (void)
|
||||
}
|
||||
|
||||
if (prefix[0]) {
|
||||
if (asprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name);
|
||||
} else {
|
||||
if (asprintf(&mailfile, "%s/%s", maildir, user_name) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&mailfile, "%s/%s", maildir, user_name);
|
||||
}
|
||||
|
||||
if (access (mailfile, F_OK) != 0) {
|
||||
@@ -1119,8 +1118,7 @@ int main (int argc, char **argv)
|
||||
user_gid = pwd->pw_gid;
|
||||
|
||||
if (prefix[0]) {
|
||||
if (asprintf(&user_home, "%s/%s", prefix, pwd->pw_dir) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&user_home, "%s/%s", prefix, pwd->pw_dir);
|
||||
} else {
|
||||
user_home = xstrdup(pwd->pw_dir);
|
||||
}
|
||||
|
||||
+10
-21
@@ -58,6 +58,7 @@
|
||||
#include "tcbfuncs.h"
|
||||
#endif
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -1266,18 +1267,12 @@ static void process_flags (int argc, char **argv)
|
||||
user_newgid = user_gid;
|
||||
}
|
||||
if (prefix[0]) {
|
||||
if (asprintf(&prefix_user_home, "%s/%s", prefix, user_home) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&prefix_user_home, "%s/%s", prefix, user_home);
|
||||
if (user_newhome) {
|
||||
if (asprintf(&prefix_user_newhome, "%s/%s",
|
||||
prefix, user_newhome) == -1)
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
xasprintf(&prefix_user_newhome, "%s/%s",
|
||||
prefix, user_newhome);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
prefix_user_home = user_home;
|
||||
prefix_user_newhome = user_newhome;
|
||||
}
|
||||
@@ -2063,11 +2058,9 @@ static void move_mailbox (void)
|
||||
* between stat and chown). --marekm
|
||||
*/
|
||||
if (prefix[0]) {
|
||||
if (asprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&mailfile, "%s/%s/%s", prefix, maildir, user_name);
|
||||
} else {
|
||||
if (asprintf(&mailfile, "%s/%s", maildir, user_name) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&mailfile, "%s/%s", maildir, user_name);
|
||||
}
|
||||
|
||||
fd = open (mailfile, O_RDONLY | O_NONBLOCK, 0);
|
||||
@@ -2112,14 +2105,10 @@ static void move_mailbox (void)
|
||||
char *newmailfile;
|
||||
|
||||
if (prefix[0]) {
|
||||
if (asprintf(&newmailfile, "%s/%s/%s",
|
||||
prefix, maildir, user_newname) == -1)
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
xasprintf(&newmailfile, "%s/%s/%s",
|
||||
prefix, maildir, user_newname);
|
||||
} else {
|
||||
if (asprintf(&newmailfile, "%s/%s", maildir, user_newname) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&newmailfile, "%s/%s", maildir, user_newname);
|
||||
}
|
||||
if ( (link (mailfile, newmailfile) != 0)
|
||||
|| (unlink (mailfile) != 0)) {
|
||||
|
||||
+2
-2
@@ -43,6 +43,7 @@
|
||||
#include "tcbfuncs.h"
|
||||
#endif /* WITH_TCB */
|
||||
#include "shadowlog.h"
|
||||
#include "sprintf.h"
|
||||
|
||||
|
||||
#define MSG_WARN_EDIT_OTHER_FILE _( \
|
||||
@@ -304,8 +305,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (asprintf(&buf, "%s %s", editor, fileedit) == -1)
|
||||
exit(EXIT_FAILURE);
|
||||
xasprintf(&buf, "%s %s", editor, fileedit);
|
||||
|
||||
status = system (buf);
|
||||
if (-1 == status) {
|
||||
|
||||
Reference in New Issue
Block a user