#include <errno.h>
#include <stdio.h>
#include <signal.h>
+
+#include "alloc.h"
#include "nscd.h"
#include "sssd.h"
#ifdef WITH_TCB
}
file_len = strlen(db->filename) + 11;/* %lu max size */
lock_file_len = strlen(db->filename) + 6; /* sizeof ".lock" */
- file = (char*)malloc(file_len);
+ file = MALLOCARRAY(file_len, char);
if (file == NULL) {
goto cleanup_ENOMEM;
}
- lock = (char*)malloc(lock_file_len);
+ lock = MALLOCARRAY(lock_file_len, char);
if (lock == NULL) {
goto cleanup_ENOMEM;
}
fcntl (fileno (db->fp), F_SETFD, FD_CLOEXEC);
buflen = BUFLEN;
- buf = (char *) malloc (buflen);
+ buf = MALLOCARRAY (buflen, char);
if (NULL == buf) {
goto cleanup_ENOMEM;
}
size_t len;
buflen += BUFLEN;
- cp = (char *) realloc (buf, buflen);
+ cp = REALLOCARRAY (buf, buflen, char);
if (NULL == cp) {
goto cleanup_buf;
}
}
}
- p = (struct commonio_entry *) malloc (sizeof *p);
+ p = MALLOC (struct commonio_entry);
if (NULL == p) {
goto cleanup_entry;
}
return 0;
}
- entries = mallocarray (n, sizeof (struct commonio_entry *));
+ entries = MALLOCARRAY (n, struct commonio_entry *);
if (entries == NULL) {
return -1;
}
return 1;
}
/* not found, new entry */
- p = (struct commonio_entry *) malloc (sizeof *p);
+ p = MALLOC (struct commonio_entry);
if (NULL == p) {
db->ops->free (nentry);
errno = ENOMEM;
return 0;
}
/* new entry */
- p = (struct commonio_entry *) malloc (sizeof *p);
+ p = MALLOC (struct commonio_entry);
if (NULL == p) {
db->ops->free (nentry);
errno = ENOMEM;
#ifdef USE_ECONF
#include <libeconf.h>
#endif
+
+#include "alloc.h"
#include "getdef.h"
#include "shadowlog_internal.h"
+
/*
* A configuration item definition.
*/
char* cp;
len = strlen(file) + strlen(sysconfdir) + 2;
- cp = malloc(len);
+ cp = MALLOCARRAY(len, char);
if (cp == NULL)
exit (13);
snprintf(cp, len, "%s/%s", file, sysconfdir);
sysconfdir = cp;
#ifdef VENDORDIR
len = strlen(file) + strlen(vendordir) + 2;
- cp = malloc(len);
+ cp = MALLOCARRAY(len, char);
if (cp == NULL)
exit (13);
snprintf(cp, len, "%s/%s", file, vendordir);
#include <assert.h>
#include <stdio.h>
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
#include "commonio.h"
/* Concatenate the 2 lines */
new_line_len = strlen (gr1->line) + strlen (gr2->line) +1;
- new_line = (char *)malloc (new_line_len + 1);
+ new_line = MALLOCARRAY (new_line_len + 1, char);
if (NULL == new_line) {
return NULL;
}
members++;
}
}
- new_members = (char **)calloc ( (members+1), sizeof(char*) );
+ new_members = CALLOC (members + 1, char *);
if (NULL == new_members) {
free (new_line);
return NULL;
continue;
}
- new = (struct commonio_entry *) malloc (sizeof *new);
+ new = MALLOC (struct commonio_entry);
if (NULL == new) {
return 0;
}
#ident "$Id$"
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
#include "groupio.h"
struct group *gr;
int i;
- gr = (struct group *) malloc (sizeof *gr);
+ gr = MALLOC (struct group);
if (NULL == gr) {
return NULL;
}
for (i = 0; grent->gr_mem[i]; i++);
/*@-mustfreeonly@*/
- gr->gr_mem = (char **) mallocarray (i + 1, sizeof (char *));
+ gr->gr_mem = MALLOCARRAY (i + 1, char *);
/*@=mustfreeonly@*/
if (NULL == gr->gr_mem) {
gr_free(gr);
#include <stdio.h>
#include <string.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
+
static /*@null@*/FILE *shadow;
static /*@null@*//*@only@*/char **members = NULL;
static size_t nmembers = 0;
while (s != NULL && *s != '\0') {
size = (nelem + 1) * sizeof (ptr);
- ptr = realloc (*list, size);
+ ptr = REALLOCARRAY (*list, size, char *);
if (NULL != ptr) {
ptr[nelem] = s;
nelem++;
}
}
size = (nelem + 1) * sizeof (ptr);
- ptr = realloc (*list, size);
+ ptr = REALLOCARRAY (*list, size, char *);
if (NULL != ptr) {
ptr[nelem] = NULL;
*list = ptr;
size_t len = strlen (string) + 1;
if (len > sgrbuflen) {
- char *buf = (char *) reallocarray (sgrbuf, len, sizeof (char));
+ char *buf = REALLOCARRAY (sgrbuf, len, char);
if (NULL == buf) {
return NULL;
}
char *cp;
if (0 == buflen) {
- buf = (char *) malloc (BUFSIZ);
+ buf = MALLOCARRAY (BUFSIZ, char);
if (NULL == buf) {
return NULL;
}
&& (feof (fp) == 0)) {
size_t len;
- cp = (char *) realloc (buf, buflen*2);
+ cp = REALLOCARRAY (buf, buflen * 2, char);
if (NULL == cp) {
return NULL;
}
size += strlen (sgrp->sg_mem[i]) + 1;
}
- buf = malloc (size);
+ buf = MALLOCARRAY (size, char);
if (NULL == buf) {
return -1;
}
#include <strings.h>
#include <ctype.h>
#include <stdatomic.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "../libsubid/subid.h"
#include "shadowlog_internal.h"
subid_nss = NULL;
goto done;
}
- subid_nss = malloc(sizeof(*subid_nss));
+ subid_nss = MALLOC(struct subid_nss_ops);
if (!subid_nss) {
dlclose(h);
goto done;
#ident "$Id$"
#include <stdio.h>
+
+#include "alloc.h"
#include "defines.h"
#include "prototypes.h"
#include "pwio.h"
{
struct passwd *pw;
- pw = (struct passwd *) calloc (1, sizeof *pw);
+ pw = CALLOC (1, struct passwd);
if (NULL == pw) {
return NULL;
}
#include <sys/wait.h>
#include <unistd.h>
#include <lib/prototypes.h>
+
+#include "alloc.h"
#include "run_part.h"
#include "shadowlog_internal.h"
struct stat sb;
path_length=strlen(directory) + strlen(namelist[n]->d_name) + 2;
- char *s = (char*)malloc(path_length);
+ char *s = MALLOCARRAY(path_length, char);
if (!s) {
printf ("could not allocate memory\n");
for (; n<scanlist; n++) {
#include <stdio.h>
#include <sys/types.h>
#include <grp.h>
+
+#include "alloc.h"
#include "defines.h"
#include "prototypes.h"
member name, or terminating NULL). */
if (i >= size) {
size = i + 100; /* at least: i + 1 */
- members = reallocarrayf (members, size, sizeof(char *));
+ members = REALLOCARRAYF(members, size, char *);
if (!members)
return NULL;
}
allocate a larger block */
free (grpbuf);
size = strlen (buf) + 1000; /* at least: strlen(buf) + 1 */
- grpbuf = malloc (size);
+ grpbuf = MALLOCARRAY (size, char);
if (grpbuf == NULL) {
size = 0;
return NULL;
#ident "$Id$"
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
#include "commonio.h"
struct sgrp *sg;
int i;
- sg = (struct sgrp *) calloc (1, sizeof *sg);
+ sg = CALLOC (1, struct sgrp);
if (NULL == sg) {
return NULL;
}
for (i = 0; NULL != sgent->sg_adm[i]; i++);
/*@-mustfreeonly@*/
- sg->sg_adm = (char **) mallocarray (i + 1, sizeof (char *));
+ sg->sg_adm = MALLOCARRAY (i + 1, char *);
/*@=mustfreeonly@*/
if (NULL == sg->sg_adm) {
free (sg->sg_passwd);
for (i = 0; NULL != sgent->sg_mem[i]; i++);
/*@-mustfreeonly@*/
- sg->sg_mem = (char **) mallocarray (i + 1, sizeof (char *));
+ sg->sg_mem = MALLOCARRAY (i + 1, char *);
/*@=mustfreeonly@*/
if (NULL == sg->sg_mem) {
for (i = 0; NULL != sg->sg_adm[i]; i++) {
#include "defines.h"
#include <shadow.h>
#include <stdio.h>
+
+#include "alloc.h"
#include "shadowio.h"
/*@null@*/ /*@only@*/struct spwd *__spw_dup (const struct spwd *spent)
{
struct spwd *sp;
- sp = (struct spwd *) calloc (1, sizeof *sp);
+ sp = CALLOC (1, struct spwd);
if (NULL == sp) {
return NULL;
}
#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>
+
+#include "alloc.h"
#include "exitcodes.h"
#include "defines.h"
#include "prototypes.h"
const char *spawnedEnv[] = {NULL};
int i = 0;
- sss_cache_args = malloc(4);
+ sss_cache_args = MALLOCARRAY(4, char);
if (sss_cache_args == NULL) {
return -1;
}
#include <ctype.h>
#include <fcntl.h>
+#include "alloc.h"
+
#define ID_SIZE 31
/*
const struct subordinate_range *rangeent = ent;
struct subordinate_range *range;
- range = (struct subordinate_range *) malloc (sizeof *range);
+ range = MALLOC (struct subordinate_range);
if (NULL == range) {
return NULL;
}
static bool append_range(struct subid_range **ranges, const struct subordinate_range *new, int n)
{
if (!*ranges) {
- *ranges = malloc(sizeof(struct subid_range));
+ *ranges = MALLOC(struct subid_range);
if (!*ranges)
return false;
} else {
struct subid_range *alloced;
- alloced = reallocarray(*ranges, n + 1, sizeof(struct subid_range));
+ alloced = REALLOCARRAY(*ranges, n + 1, struct subid_range);
if (!alloced)
return false;
*ranges = alloced;
return n;
}
- ret = reallocarray(*uids, n + 1, sizeof(uid_t));
+ ret = REALLOCARRAY(*uids, n + 1, uid_t);
if (!ret) {
free(*uids);
return -1;
#include <stdio.h>
#include <grp.h>
#include <errno.h>
+
+#include "alloc.h"
#include "shadowlog.h"
#ident "$Id$"
i = 16;
for (;;) {
- grouplist = (gid_t *) mallocarray (i, sizeof (GETGROUPS_T));
+ grouplist = MALLOCARRAY (i, GETGROUPS_T);
if (NULL == grouplist) {
return -1;
}
fputs (_("Warning: too many groups\n"), shadow_logfd);
break;
}
- grouplist = (gid_t *) reallocarrayf (grouplist, (size_t)ngroups + 1, sizeof (GETGROUPS_T));
+ grouplist = REALLOCARRAYF(grouplist, (size_t) ngroups + 1, GETGROUPS_T);
if (grouplist == NULL) {
return -1;
}
#ident "$Id$"
+#include "alloc.h"
#include "prototypes.h"
* through malloc(3). This makes the function thread-safe, and
* also reduces the visibility of the buffer.
*
- * - agetpass() doesn't call realloc(3) internally. Some
+ * - agetpass() doesn't reallocate internally. Some
* implementations of getpass(3), such as glibc, do that, as a
* consequence of calling getline(3). That's a bug in glibc,
* which allows leaking prefixes of passwords in freed memory.
* Let's add one more byte, and if the password uses it, it
* means the introduced password was longer than PASS_MAX.
*/
- pass = malloc(PASS_MAX + 2);
+ pass = MALLOCARRAY(PASS_MAX + 2, char);
if (pass == NULL)
return NULL;
return NULL;
}
- lp = (struct link_name *) xmalloc (sizeof *lp);
+ lp = XMALLOC (struct link_name);
src_len = strlen (src_orig);
dst_len = strlen (dst_orig);
name_len = strlen (name);
lp->ln_ino = sb->st_ino;
lp->ln_count = sb->st_nlink;
len = name_len - src_len + dst_len + 1;
- lp->ln_name = (char *) xmalloc (len);
+ lp->ln_name = XMALLOCARRAY (len, char);
(void) snprintf (lp->ln_name, len, "%s%s", dst_orig, name + src_len);
lp->ln_next = links;
links = lp;
src_len += strlen (src->full_path);
dst_len += strlen (dst->full_path);
- src_name = (char *) malloc (src_len);
- dst_name = (char *) malloc (dst_len);
+ src_name = MALLOCARRAY (src_len, char);
+ dst_name = MALLOCARRAY (dst_len, char);
if ((NULL == src_name) || (NULL == dst_name)) {
err = -1;
while (true) {
ssize_t nchars;
- char *buffer = (char *) malloc (size);
+ char *buffer = MALLOCARRAY (size, char);
if (NULL == buffer) {
return NULL;
}
*/
if (strncmp (oldlink, src_orig, strlen (src_orig)) == 0) {
size_t len = strlen (dst_orig) + strlen (oldlink) - strlen (src_orig) + 1;
- char *dummy = (char *) xmalloc (len);
+ char *dummy = XMALLOCARRAY (len, char);
(void) snprintf (dummy, len, "%s%s",
dst_orig,
oldlink + strlen (src_orig));
*/
void initenv (void)
{
- newenvp = (char **) xmallocarray (NEWENVP_STEP, sizeof (char *));
+ newenvp = XMALLOCARRAY (NEWENVP_STEP, char *);
*newenvp = NULL;
}
if (NULL != value) {
size_t len = strlen (string) + strlen (value) + 2;
int wlen;
- newstring = xmalloc (len);
+ newstring = XMALLOCARRAY (len, char);
wlen = snprintf (newstring, len, "%s=%s", string, value);
assert (wlen == (int) len -1);
} else {
* happily go on, else print a message.
*/
- __newenvp = (char **) reallocarray (newenvp, newenvc + NEWENVP_STEP,
- sizeof (char *));
+ __newenvp = REALLOCARRAY(newenvp, newenvc + NEWENVP_STEP, char *);
if (NULL != __newenvp) {
/*
#include <stdio.h>
#include <errno.h>
+#include "alloc.h"
#include "prototypes.h"
#include "groupio.h"
#include "getdef.h"
*/
/* Create an array to hold all of the discovered GIDs */
- used_gids = calloc (gid_max + 1, sizeof (bool));
+ used_gids = CALLOC (gid_max + 1, bool);
if (NULL == used_gids) {
fprintf (log_get_logfd(),
_("%s: failed to allocate memory: %s\n"),
#include <stdio.h>
#include <errno.h>
+#include "alloc.h"
#include "prototypes.h"
#include "pwio.h"
#include "getdef.h"
*/
/* Create an array to hold all of the discovered UIDs */
- used_uids = mallocarray (uid_max + 1, sizeof (bool));
+ used_uids = MALLOCARRAY (uid_max + 1, bool);
if (NULL == used_uids) {
fprintf (log_get_logfd(),
_("%s: failed to allocate memory: %s\n"),
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "stpeprintf.h"
#include "idmapping.h"
return NULL;
}
- mappings = calloc(ranges, sizeof(*mappings));
+ mappings = CALLOC(ranges, struct map_range);
if (!mappings) {
fprintf(log_get_logfd(), _( "%s: Memory allocation failure\n"),
log_get_progname());
#endif
bufsize = ranges * ((ULONG_DIGITS + 1) * 3);
- pos = buf = xmalloc(bufsize);
+ pos = buf = XMALLOCARRAY(bufsize, char);
end = buf + bufsize;
/* Build the mapping command */
#ident "$Id$"
#include <assert.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
/*
* old entries, and the new entries as well.
*/
- tmp = (char **) xmallocarray (i + 2, sizeof member);
+ tmp = XMALLOCARRAY (i + 2, char *);
/*
* Copy the original list to the new list, then append the
* old entries.
*/
- tmp = (char **) xmallocarray (j + 1, sizeof member);
+ tmp = XMALLOCARRAY (j + 1, char *);
/*
* Copy the original list except the deleted members to the
for (i = 0; NULL != list[i]; i++);
- tmp = (char **) xmallocarray (i + 1, sizeof (char *));
+ tmp = XMALLOCARRAY (i + 1, char *);
i = 0;
while (NULL != *list) {
* Allocate the array we're going to store the pointers into.
*/
- array = (char **) xmallocarray (i, sizeof (char *));
+ array = XMALLOCARRAY (i, char *);
/*
* Empty list is special - 0 members, not 1 empty member. --marekm
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
#include "getdef.h"
envp[envc] = nvar;
} else {
size_t len = strlen (nvar) + 32;
- envp[envc] = xmalloc (len);
+ envp[envc] = XMALLOCARRAY (len, char);
(void) snprintf (envp[envc], len,
"L%d=%s", count++, nvar);
}
#include <stdio.h>
#include <string.h>
+#include "alloc.h"
#include "getdef.h"
#ident "$Id$"
size_t len = strlen (mailbox) + 5;
int wlen;
- newmail = xmalloc (len);
+ newmail = XMALLOCARRAY (len, char);
wlen = snprintf (newmail, len, "%s/new", mailbox);
assert (wlen == (int) len - 1);
*/
#include <ctype.h>
#include <stdio.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
#include "getdef.h"
newmono = str_lower (xstrdup (new));
oldmono = str_lower (xstrdup (old));
- wrapped = xmalloc (strlen (oldmono) * 2 + 1);
+ wrapped = XMALLOCARRAY (strlen (oldmono) * 2 + 1, char);
strcpy (wrapped, oldmono);
strcat (wrapped, oldmono);
#include <stdio.h>
#include <stdlib.h>
#include <security/pam_appl.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "shadowlog.h"
return PAM_CONV_ERR;
}
- responses = (struct pam_response *) calloc (num_msg, sizeof (*responses));
+ responses = CALLOC (num_msg, struct pam_response);
if (NULL == responses) {
return PAM_CONV_ERR;
}
#include <stdio.h>
#include <assert.h>
+
#include "defines.h"
+#include "alloc.h"
#include "prototypes.h"
/*@-exitarg@*/
#include "exitcodes.h"
}
size_t len;
len = strlen(prefix) + strlen(PASSWD_FILE) + 2;
- passwd_db_file = xmalloc(len);
+ passwd_db_file = XMALLOCARRAY(len, char);
snprintf(passwd_db_file, len, "%s/%s", prefix, PASSWD_FILE);
pw_setdbname(passwd_db_file);
len = strlen(prefix) + strlen(GROUP_FILE) + 2;
- group_db_file = xmalloc(len);
+ group_db_file = XMALLOCARRAY(len, char);
snprintf(group_db_file, len, "%s/%s", prefix, GROUP_FILE);
gr_setdbname(group_db_file);
#ifdef SHADOWGRP
len = strlen(prefix) + strlen(SGROUP_FILE) + 2;
- sgroup_db_file = xmalloc(len);
+ sgroup_db_file = XMALLOCARRAY(len, char);
snprintf(sgroup_db_file, len, "%s/%s", prefix, SGROUP_FILE);
sgr_setdbname(sgroup_db_file);
#endif
#endif
len = strlen(prefix) + strlen(SHADOW_FILE) + 2;
- spw_db_file = xmalloc(len);
+ spw_db_file = XMALLOCARRAY(len, char);
snprintf(spw_db_file, len, "%s/%s", prefix, SHADOW_FILE);
spw_setdbname(spw_db_file);
#ifdef ENABLE_SUBIDS
len = strlen(prefix) + strlen("/etc/subuid") + 2;
- suid_db_file = xmalloc(len);
+ suid_db_file = XMALLOCARRAY(len, char);
snprintf(suid_db_file, len, "%s/%s", prefix, "/etc/subuid");
sub_uid_setdbname(suid_db_file);
len = strlen(prefix) + strlen("/etc/subgid") + 2;
- sgid_db_file = xmalloc(len);
+ sgid_db_file = XMALLOCARRAY(len, char);
snprintf(sgid_db_file, len, "%s/%s", prefix, "/etc/subgid");
sub_gid_setdbname(sgid_db_file);
#endif
setdef_config_file(prefix);
#else
len = strlen(prefix) + strlen("/etc/login.defs") + 2;
- def_conf_file = xmalloc(len);
+ def_conf_file = XMALLOCARRAY(len, char);
snprintf(def_conf_file, len, "%s/%s", prefix, "/etc/login.defs");
setdef_config_file(def_conf_file);
#endif
#include <sys/stat.h>
#include <stdio.h>
#include <ctype.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
#include <pwd.h>
size_t len = strlen (dirname) + strlen (filename) + 2;
int wlen;
- buf = xmalloc (len);
+ buf = XMALLOCARRAY (len, char);
wlen = snprintf (buf, len, "%s/%s", dirname, filename);
assert (wlen == (int) len - 1);
#include <netdb.h>
#include <stdio.h>
+#include "alloc.h"
+
#ident "$Id$"
}
if (NULL != ut) {
- ret = (struct utmp *) xmalloc (sizeof (*ret));
+ ret = XMALLOC (struct utmp);
memcpy (ret, ut, sizeof (*ret));
}
if ( (NULL != host)
&& ('\0' != host[0])) {
- hostname = (char *) xmalloc (strlen (host) + 1);
+ hostname = XMALLOCARRAY (strlen (host) + 1, char);
strcpy (hostname, host);
#ifdef HAVE_STRUCT_UTMP_UT_HOST
} else if ( (NULL != ut)
&& ('\0' != ut->ut_host[0])) {
- hostname = (char *) xmalloc (sizeof (ut->ut_host) + 1);
+ hostname = XMALLOCARRAY (sizeof (ut->ut_host) + 1, char);
strncpy (hostname, ut->ut_host, sizeof (ut->ut_host));
hostname[sizeof (ut->ut_host)] = '\0';
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
}
- utent = (struct utmp *) xcalloc (1, sizeof (*utent));
+ utent = XCALLOC (1, struct utmp);
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "shadowlog.h"
/* we have to start with something */
size_t length = 0x100;
- result = malloc(sizeof(LOOKUP_TYPE));
+ result = MALLOC(LOOKUP_TYPE);
if (NULL == result) {
fprintf (log_get_logfd(), _("%s: out of memory\n"),
"x" STRINGIZE(FUNCTION_NAME));
while (true) {
int status;
LOOKUP_TYPE *resbuf = NULL;
- buffer = (char *)xreallocarray (buffer, length, sizeof(char));
+ buffer = XREALLOCARRAY (buffer, length, char);
status = REENTRANT_NAME(ARG_NAME, result, buffer,
length, &resbuf);
if ((0 == status) && (resbuf == result)) {
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
+
+#include "alloc.h"
#include "defines.h"
#include "groupio.h"
#include "nscd.h"
sg->sg_mem = dup_list (gr->gr_mem);
- sg->sg_adm = (char **) xmallocarray (2, sizeof (char *));
+ sg->sg_adm = XMALLOCARRAY (2, char *);
#ifdef FIRST_MEMBER_IS_ADMIN
if (sg->sg_mem[0]) {
sg->sg_adm[0] = xstrdup (sg->sg_mem[0]);
#include "pam_defs.h"
#endif /* USE_PAM */
#include <pwd.h>
+
+#include "alloc.h"
#include "defines.h"
#include "prototypes.h"
#include "groupio.h"
static struct sgrp sgrent;
sgrent.sg_name = xstrdup (newgrp->gr_name);
sgrent.sg_mem = dup_list (newgrp->gr_mem);
- sgrent.sg_adm = (char **) xmalloc (sizeof (char *));
+ sgrent.sg_adm = XMALLOC (char *);
#ifdef FIRST_MEMBER_IS_ADMIN
if (sgrent.sg_mem[0]) {
sgrent.sg_adm[0] = xstrdup (sgrent.sg_mem[0]);
static struct sgrp sgrent;
sgrent.sg_name = xstrdup (newgrp->gr_name);
sgrent.sg_mem = dup_list (newgrp->gr_mem);
- sgrent.sg_adm = (char **) xmalloc (sizeof (char *));
+ sgrent.sg_adm = XMALLOC (char *);
#ifdef FIRST_MEMBER_IS_ADMIN
if (sgrent.sg_mem[0]) {
sgrent.sg_adm[0] = xstrdup (sgrent.sg_mem[0]);
/* Create a shadow group based on this group */
static struct sgrp sgrent;
sgrent.sg_name = xstrdup (newgrp->gr_name);
- sgrent.sg_mem = (char **) xmalloc (sizeof (char *));
+ sgrent.sg_mem = XMALLOC (char *);
sgrent.sg_mem[0] = NULL;
- sgrent.sg_adm = (char **) xmalloc (sizeof (char *));
+ sgrent.sg_adm = XMALLOC (char *);
sgrent.sg_adm[0] = NULL;
/* Move any password to gshadow */
#include <pwd.h>
#endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */
+
+#include "alloc.h"
#include "chkname.h"
#include "defines.h"
#include "groupio.h"
// requested to replace the existing groups
if (NULL != grp.gr_mem[0])
gr_free_members(&grp);
- grp.gr_mem = (char **)xmalloc(sizeof(char *));
+ grp.gr_mem = XMALLOC(char *);
grp.gr_mem[0] = NULL;
} else {
// append to existing groups
#endif
info_passwd.name = group_name;
- gr = xmalloc (512);
+ gr = XMALLOCARRAY(512, char);
info_group.audit_msg = gr;
gr_end = gr + 512;
#ifdef SHADOWGRP
- sgr = xmalloc (512);
+ sgr = XMALLOCARRAY(512, char);
info_gshadow.audit_msg = sgr;
sgr_end = sgr + 512;
#endif
- pw = xmalloc (512);
+ pw = XMALLOCARRAY(512, char);
info_passwd.audit_msg = pw;
pw_end = pw + 512;
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
+
+#include "alloc.h"
#include "defines.h"
#include "prototypes.h"
#include "shadowlog.h"
+
/*
* Global variables
*/
GETGROUPS_T *groups;
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
- groups = (GETGROUPS_T *) mallocarray (sys_ngroups, sizeof (GETGROUPS_T));
+ groups = MALLOCARRAY (sys_ngroups, GETGROUPS_T);
(void) setlocale (LC_ALL, "");
(void) bindtextdomain (PACKAGE, LOCALEDIR);
#include <pwd.h>
#include <stdio.h>
#include <sys/types.h>
+
+#include "alloc.h"
#include "defines.h"
+
/* local function prototypes */
static void usage (void);
* work if the system library is recompiled.
*/
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
- groups = (GETGROUPS_T *) mallocarray (sys_ngroups, sizeof (GETGROUPS_T));
+ groups = MALLOCARRAY (sys_ngroups, GETGROUPS_T);
/*
* See if the -a flag has been given to print out the concurrent
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <assert.h>
+
+#include "alloc.h"
#include "defines.h"
#include "faillog.h"
#include "failure.h"
#ifdef RLOGIN
if (rflg) {
assert (NULL == username);
- username = xmalloc (USER_NAME_MAX_LENGTH + 1);
+ username = XMALLOCARRAY (USER_NAME_MAX_LENGTH + 1, char);
username[USER_NAME_MAX_LENGTH] = '\0';
if (do_rlogin (hostname, username, USER_NAME_MAX_LENGTH, term, sizeof term)) {
preauth_flag = true;
exit (1);
}
preauth_flag = false;
- username = xmalloc (USER_NAME_MAX_LENGTH + 1);
+ username = XMALLOCARRAY (USER_NAME_MAX_LENGTH + 1, char);
username[USER_NAME_MAX_LENGTH] = '\0';
login_prompt (_("\n%s login: "), username, USER_NAME_MAX_LENGTH);
#include <pwd.h>
#include <stdio.h>
#include <assert.h>
+
+#include "alloc.h"
#include "defines.h"
#include "getdef.h"
#include "prototypes.h"
/* don't use getgroups(0, 0) - it doesn't work on some systems */
i = 16;
for (;;) {
- grouplist = (GETGROUPS_T *) xmallocarray (i, sizeof (GETGROUPS_T));
+ grouplist = XMALLOCARRAY (i, GETGROUPS_T);
ngroups = getgroups (i, grouplist);
if (i > ngroups && !(ngroups == -1 && errno == EINVAL)) {
break;
#include <ctype.h>
#include <errno.h>
#include <string.h>
+
+#include "alloc.h"
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
#include "pam_defs.h"
#ifdef USE_PAM
/* keep the list of user/password for later update by PAM */
nusers++;
- lines = reallocf (lines, nusers, sizeof (lines[0]));
- usernames = reallocf (usernames, nusers, sizeof (usernames[0]));
- passwords = reallocf (passwords, nusers, sizeof (passwords[0]));
+ lines = REALLOCARRAYF(lines, nusers, int);
+ usernames = REALLOCARRAYF(usernames, nusers, char *);
+ passwords = REALLOCARRAYF(passwords, nusers, char *);
if (lines == NULL || usernames == NULL || passwords == NULL) {
fprintf (stderr,
_("%s: line %d: %s\n"),
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
+
+#include "alloc.h"
#include "defines.h"
#include "getdef.h"
#include "nscd.h"
}
if (lflg && *cp != '!') {
- char *newpw = xmalloc (strlen (cp) + 2);
+ char *newpw = XMALLOCARRAY (strlen (cp) + 2, char);
strcpy (newpw, "!");
strcat (newpw, cp);
#include <sys/stat.h>
#include <fcntl.h>
#endif /* !USE_PAM */
+
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
#include "pwauth.h"
while (NULL != args[n_args]) {
n_args++;
}
- targs = (char **) xmallocarray (n_args + 3, sizeof (args[0]));
+ targs = XMALLOCARRAY (n_args + 3, char *);
targs[0] = "sh";
targs[1] = "-";
targs[2] = xstrdup (shellname);
cp = Basename (shellstr);
}
- arg0 = xmalloc (strlen (cp) + 2);
+ arg0 = XMALLOCARRAY (strlen (cp) + 2, char);
arg0[0] = '-';
strcpy (arg0 + 1, cp);
cp = arg0;
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
+
+#include "alloc.h"
#include "chkname.h"
#include "defines.h"
#include "faillog.h"
int wlen;
len = strlen(prefix) + strlen(USER_DEFAULTS_FILE) + 2;
- default_file = malloc(len);
+ default_file = MALLOCARRAY(len, char);
if (default_file == NULL)
return;
wlen = snprintf(default_file, len, "%s/%s", prefix, USER_DEFAULTS_FILE);
char* _def_template; /* avoid const warning */
len = strlen(prefix) + strlen(cp) + 2;
- _def_template = xmalloc(len);
+ _def_template = XMALLOCARRAY(len, char);
wlen = snprintf(_def_template, len, "%s/%s", prefix, cp);
assert (wlen == (int) len -1);
def_template = _def_template;
char* _def_usrtemplate; /* avoid const warning */
len = strlen(prefix) + strlen(cp) + 2;
- _def_usrtemplate = xmalloc(len);
+ _def_usrtemplate = XMALLOCARRAY(len, char);
wlen = snprintf(_def_usrtemplate, len, "%s/%s", prefix, cp);
assert (wlen == (int) len -1);
def_usrtemplate = _def_usrtemplate;
len = strlen(prefix) + strlen(NEW_USER_FILE) + 2;
- new_file = malloc(len);
+ new_file = MALLOCARRAY(len, char);
if (new_file == NULL) {
fprintf (stderr,
_("%s: cannot create new defaults file: %s\n"),
if (prefix[0]) {
len = strlen(prefix) + strlen(USER_DEFAULTS_FILE) + 2;
- default_file = malloc(len);
+ default_file = MALLOCARRAY(len, char);
if (default_file == NULL) {
fprintf (stderr,
_("%s: cannot create new defaults file: %s\n"),
size_t len = strlen (def_home) + strlen (user_name) + 2;
int wlen;
- uh = xmalloc (len);
+ uh = XMALLOCARRAY (len, char);
wlen = snprintf (uh, len, "%s/%s", def_home, user_name);
assert (wlen == (int) len -1);
size_t len = strlen(prefix) + strlen(user_home) + 2;
int wlen;
char* _prefix_user_home; /* to avoid const warning */
- _prefix_user_home = xmalloc(len);
+ _prefix_user_home = XMALLOCARRAY(len, char);
wlen = snprintf(_prefix_user_home, len, "%s/%s", prefix, user_home);
assert (wlen == (int) len -1);
prefix_user_home = _prefix_user_home;
if (NULL == spool) {
return;
}
- file = alloca (strlen (prefix) + strlen (spool) + strlen (user_name) + 3);
+ file = ALLOCARRAY (strlen (prefix) + strlen (spool) + strlen (user_name) + 3, char);
if (prefix[0])
sprintf (file, "%s/%s/%s", prefix, spool, user_name);
else
#endif
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
- user_groups = (char **) xmallocarray (1 + sys_ngroups, sizeof (char *));
+ user_groups = XMALLOCARRAY (1 + sys_ngroups, char *);
/*
* Initialize the list to be empty
*/
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+
+#include "alloc.h"
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
#include "pam_defs.h"
}
len = strlen (prefix) + strlen (maildir) + strlen (user_name) + 2;
- mailfile = xmalloc (len);
+ mailfile = XMALLOCARRAY (len, char);
if (prefix[0]) {
(void) snprintf (mailfile, len, "%s/%s/%s",
return 0;
}
- buf = malloc (buflen);
+ buf = MALLOCARRAY (buflen, char);
if (NULL == buf) {
fprintf (stderr, _("%s: Can't allocate memory, "
"tcb entry for %s not removed.\n"),
size_t len = strlen(prefix) + strlen(pwd->pw_dir) + 2;
int wlen;
- user_home = xmalloc(len);
+ user_home = XMALLOCARRAY(len, char);
wlen = snprintf(user_home, len, "%s/%s", prefix, pwd->pw_dir);
assert (wlen == (int) len -1);
}
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
+
+#include "alloc.h"
#include "chkname.h"
#include "defines.h"
#include "faillog.h"
if (range.first > range.last)
return 0;
- entry = malloc(sizeof(*entry));
+ entry = MALLOC(struct ulong_range_list_entry);
if (!entry) {
fprintf (stderr,
_("%s: failed to allocate memory: %s\n"),
static char *new_pw_passwd (char *pw_pass)
{
if (Lflg && ('!' != pw_pass[0])) {
- char *buf = xmalloc (strlen (pw_pass) + 2);
+ char *buf = XMALLOCARRAY (strlen (pw_pass) + 2, char);
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
if (prefix[0]) {
size_t len = strlen(prefix) + strlen(user_home) + 2;
int wlen;
- prefix_user_home = xmalloc(len);
+ prefix_user_home = XMALLOCARRAY(len, char);
wlen = snprintf(prefix_user_home, len, "%s/%s", prefix, user_home);
assert (wlen == (int) len -1);
if (user_newhome) {
len = strlen(prefix) + strlen(user_newhome) + 2;
- prefix_user_newhome = xmalloc(len);
+ prefix_user_newhome = XMALLOCARRAY(len, char);
wlen = snprintf(prefix_user_newhome, len, "%s/%s", prefix, user_newhome);
assert (wlen == (int) len -1);
}
return;
}
len = strlen (prefix) + strlen (maildir) + strlen (user_name) + 2;
- mailfile = alloca (len);
+ mailfile = ALLOCARRAY (len, char);
/*
* O_NONBLOCK is to make sure open won't hang on mandatory locks.
if (lflg) {
len = strlen (prefix) + strlen (maildir) + strlen (user_newname) + 2;
- newmailfile = alloca(len);
+ newmailfile = ALLOCARRAY(len, char);
if (prefix[0]) {
(void) snprintf (newmailfile, len, "%s/%s/%s",
prefix, maildir, user_newname);
#endif
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
- user_groups = (char **) mallocarray (sys_ngroups + 1, sizeof (char *));
+ user_groups = MALLOCARRAY (sys_ngroups + 1, char *);
user_groups[0] = NULL;
is_shadow_pwd = spw_file_present ();
#include <sys/types.h>
#include <unistd.h>
#include <utime.h>
+
+#include "alloc.h"
#include "defines.h"
#include "groupio.h"
#include "nscd.h"
continue;
}
- buf = (char *) malloc (strlen (editor) + strlen (fileedit) + 2);
+ buf = MALLOCARRAY(strlen(editor) + strlen(fileedit) + 2, char);
snprintf (buf, strlen (editor) + strlen (fileedit) + 2,
"%s %s", editor, fileedit);
status = system (buf);
if (stat (file, &st1) != 0) {
vipwexit (_("failed to stat edited file"), errno, 1);
}
- to_rename = malloc (strlen (file) + 2);
+ to_rename = MALLOCARRAY (strlen (file) + 2, char);
if (NULL == to_rename) {
vipwexit (_("failed to allocate memory"), errno, 1);
}
}
static int alloc_uid(uid_t **uids, uid_t id) {
- *uids = malloc(sizeof(uid_t));
+ *uids = MALLOC(uid_t);
if (!*uids)
return -1;
*uids[0] = id;
return SUBID_STATUS_SUCCESS;
if (id_type == ID_TYPE_UID && strcmp(owner, "group1") == 0)
return SUBID_STATUS_SUCCESS;
- ranges = (struct subid_range *)malloc(sizeof(struct subid_range));
+ ranges = MALLOC(struct subid_range);
if (!ranges)
return SUBID_STATUS_ERROR;
if (strcmp(owner, "user1") == 0 || strcmp(owner, "group1") == 0) {