#include <stdlib.h>
#include <stdio.h>
#include "prototypes.h"
+#include "stpeprintf.h"
#include "idmapping.h"
#if HAVE_SYS_CAPABILITY_H
#include <sys/prctl.h>
int idx;
const struct map_range *mapping;
size_t bufsize;
- char *buf, *pos;
+ char *buf, *pos, *end;
int fd;
#if HAVE_SYS_CAPABILITY_H
bufsize = ranges * ((ULONG_DIGITS + 1) * 3);
pos = buf = xmalloc(bufsize);
+ end = buf + bufsize;
/* Build the mapping command */
mapping = mappings;
for (idx = 0; idx < ranges; idx++, mapping++) {
/* Append this range to the string that will be written */
- int written = snprintf(pos, bufsize - (pos - buf),
- "%lu %lu %lu\n",
- mapping->upper,
- mapping->lower,
- mapping->count);
- if ((written <= 0) || ((size_t)written >= (bufsize - (pos - buf)))) {
- fprintf(log_get_logfd(), _("%s: snprintf failed!\n"), log_get_progname());
- exit(EXIT_FAILURE);
- }
- pos += written;
+ pos = stpeprintf(pos, end, "%lu %lu %lu\n",
+ mapping->upper,
+ mapping->lower,
+ mapping->count);
+ }
+ if (pos == end || pos == NULL) {
+ fprintf(log_get_logfd(), _("%s: stpeprintf failed!\n"), log_get_progname());
+ exit(EXIT_FAILURE);
}
/* Write the mapping to the mapping file */
#include "sgroupio.h"
#endif
#include "shadowlog.h"
+#include "stpeprintf.h"
/*
* exit status values
*/
*/
static void prepare_failure_reports (void)
{
+ char *gr, *gr_end;
+#ifdef SHADOWGRP
+ char *sgr, *sgr_end;
+#endif
+ char *pw, *pw_end;
+
info_group.name = group_name;
#ifdef SHADOWGRP
info_gshadow.name = group_name;
#endif
info_passwd.name = group_name;
- info_group.audit_msg = xmalloc (512);
+ gr = xmalloc (512);
+ info_group.audit_msg = gr;
+ gr_end = gr + 512;
#ifdef SHADOWGRP
- info_gshadow.audit_msg = xmalloc (512);
+ sgr = xmalloc (512);
+ info_gshadow.audit_msg = sgr;
+ sgr_end = sgr + 512;
#endif
- info_passwd.audit_msg = xmalloc (512);
+ pw = xmalloc (512);
+ info_passwd.audit_msg = pw;
+ pw_end = pw + 512;
- (void) snprintf (info_group.audit_msg, 512,
- "changing %s; ", gr_dbname ());
+ gr = stpeprintf(gr, gr_end, "changing %s; ", gr_dbname ());
#ifdef SHADOWGRP
- (void) snprintf (info_gshadow.audit_msg, 512,
- "changing %s; ", sgr_dbname ());
+ sgr = stpeprintf(sgr, sgr_end, "changing %s; ", sgr_dbname ());
#endif
- (void) snprintf (info_passwd.audit_msg, 512,
- "changing %s; ", pw_dbname ());
+ pw = stpeprintf(pw, pw_end, "changing %s; ", pw_dbname ());
- info_group.action = info_group.audit_msg
- + strlen (info_group.audit_msg);
+ info_group.action = gr;
#ifdef SHADOWGRP
- info_gshadow.action = info_gshadow.audit_msg
- + strlen (info_gshadow.audit_msg);
+ info_gshadow.action = sgr;
#endif
- info_passwd.action = info_passwd.audit_msg
- + strlen (info_passwd.audit_msg);
+ info_passwd.action = pw;
- (void) snprintf (info_group.action,
- 512 - strlen (info_group.audit_msg),
+ gr = stpeprintf(gr, gr_end,
"group %s/%ju", group_name, (uintmax_t) group_id);
#ifdef SHADOWGRP
- (void) snprintf (info_gshadow.action,
- 512 - strlen (info_gshadow.audit_msg),
+ sgr = stpeprintf(sgr, sgr_end,
"group %s", group_name);
#endif
- (void) snprintf (info_passwd.action,
- 512 - strlen (info_passwd.audit_msg),
+ pw = stpeprintf(pw, pw_end,
"group %s/%ju", group_name, (uintmax_t) group_id);
if (nflg) {
if (gflg) {
strncat (info_group.action, ", new gid: ",
511 - strlen (info_group.audit_msg));
- (void) snprintf (info_group.action+strlen (info_group.action),
- 512 - strlen (info_group.audit_msg),
- "%ju", (uintmax_t) group_newid);
+ stpeprintf(info_group.action+strlen (info_group.action),
+ gr_end, "%ju", (uintmax_t) group_newid);
strncat (info_passwd.action, ", new gid: ",
511 - strlen (info_passwd.audit_msg));
- (void) snprintf (info_passwd.action+strlen (info_passwd.action),
- 512 - strlen (info_passwd.audit_msg),
- "%ju", (uintmax_t) group_newid);
+ stpeprintf(info_passwd.action+strlen (info_passwd.action),
+ pw_end, "%ju", (uintmax_t) group_newid);
}
info_group.audit_msg[511] = '\0';
#ifdef SHADOWGRP