libsubid: don't print error messages on stderr by default

Closes #325

Add a new subid_init() function which can be used to specify the
stream on which error messages should be printed.  (If you want to
get fancy you can redirect that to memory :)  If subid_init() is
not called, use stderr.  If NULL is passed, then /dev/null will
be used.

This patch also fixes up the 'Prog', which previously had to be
defined by any program linking against libsubid.  Now, by default
in libsubid it will show (subid).  Once subid_init() is called,
it will use the first variable passed to subid_init().

Signed-off-by: Serge Hallyn <serge@hallyn.com>
This commit is contained in:
Serge Hallyn
2021-05-08 17:42:14 -05:00
parent 3ac8d97825
commit 2b22a6909d
75 changed files with 311 additions and 191 deletions

View File

@ -93,7 +93,7 @@ int add_groups (const char *list)
grp = getgrnam (token); /* local, no need for xgetgrnam */
if (NULL == grp) {
fprintf (stderr, _("Warning: unknown group %s\n"),
fprintf (shadow_logfd, _("Warning: unknown group %s\n"),
token);
continue;
}
@ -105,7 +105,7 @@ int add_groups (const char *list)
}
if (ngroups >= sysconf (_SC_NGROUPS_MAX)) {
fputs (_("Warning: too many groups\n"), stderr);
fputs (_("Warning: too many groups\n"), shadow_logfd);
break;
}
tmp = (gid_t *) realloc (grouplist, (size_t)(ngroups + 1) * sizeof (GETGROUPS_T));

View File

@ -59,7 +59,7 @@ void audit_help_open (void)
return;
}
(void) fputs (_("Cannot open audit interface - aborting.\n"),
stderr);
shadow_logfd);
exit (EXIT_FAILURE);
}
}

View File

@ -75,7 +75,7 @@ void chown_tty (const struct passwd *info)
|| (fchmod (STDIN_FILENO, (mode_t)getdef_num ("TTYPERM", 0600)) != 0)) {
int err = errno;
fprintf (stderr,
fprintf (shadow_logfd,
_("Unable to change owner or mode of tty stdin: %s"),
strerror (err));
SYSLOG ((LOG_WARN,

View File

@ -203,7 +203,7 @@ void cleanup_report_del_group_gshadow (void *group_name)
void cleanup_unlock_group (unused void *arg)
{
if (gr_unlock () == 0) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: failed to unlock %s\n"),
Prog, gr_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
@ -223,7 +223,7 @@ void cleanup_unlock_group (unused void *arg)
void cleanup_unlock_gshadow (unused void *arg)
{
if (sgr_unlock () == 0) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: failed to unlock %s\n"),
Prog, sgr_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));

View File

@ -120,7 +120,7 @@ void cleanup_report_add_user_shadow (void *user_name)
void cleanup_unlock_passwd (unused void *arg)
{
if (pw_unlock () == 0) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: failed to unlock %s\n"),
Prog, pw_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
@ -139,7 +139,7 @@ void cleanup_unlock_passwd (unused void *arg)
void cleanup_unlock_shadow (unused void *arg)
{
if (spw_unlock () == 0) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: failed to unlock %s\n"),
Prog, spw_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));

View File

@ -125,11 +125,11 @@ static void error_acl (struct error_context *ctx, const char *fmt, ...)
}
va_start (ap, fmt);
(void) fprintf (stderr, _("%s: "), Prog);
if (vfprintf (stderr, fmt, ap) != 0) {
(void) fputs (_(": "), stderr);
(void) fprintf (shadow_logfd, _("%s: "), Prog);
if (vfprintf (shadow_logfd, fmt, ap) != 0) {
(void) fputs (_(": "), shadow_logfd);
}
(void) fprintf (stderr, "%s\n", strerror (errno));
(void) fprintf (shadow_logfd, "%s\n", strerror (errno));
va_end (ap);
}
@ -248,7 +248,7 @@ int copy_tree (const char *src_root, const char *dst_root,
}
if (!S_ISDIR (sb.st_mode)) {
fprintf (stderr,
fprintf (shadow_logfd,
"%s: %s is not a directory",
Prog, src_root);
return -1;

View File

@ -171,7 +171,7 @@ void addenv (const char *string, /*@null@*/const char *value)
}
newenvp = __newenvp;
} else {
(void) fputs (_("Environment overflow\n"), stderr);
(void) fputs (_("Environment overflow\n"), shadow_logfd);
newenvc--;
free (newenvp[newenvc]);
}

View File

@ -74,7 +74,7 @@ static int get_ranges (bool sys_group, gid_t *min_id, gid_t *max_id,
/* Check that the ranges make sense */
if (*max_id < *min_id) {
(void) fprintf (stderr,
(void) fprintf (shadow_logfd,
_("%s: Invalid configuration: SYS_GID_MIN (%lu), "
"GID_MIN (%lu), SYS_GID_MAX (%lu)\n"),
Prog, (unsigned long) *min_id,
@ -97,7 +97,7 @@ static int get_ranges (bool sys_group, gid_t *min_id, gid_t *max_id,
/* Check that the ranges make sense */
if (*max_id < *min_id) {
(void) fprintf (stderr,
(void) fprintf (shadow_logfd,
_("%s: Invalid configuration: GID_MIN (%lu), "
"GID_MAX (%lu)\n"),
Prog, (unsigned long) *min_id,
@ -213,7 +213,7 @@ int find_new_gid (bool sys_group,
* more likely to want to stop and address the
* issue.
*/
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Encountered error attempting to use "
"preferred GID: %s\n"),
Prog, strerror (result));
@ -243,7 +243,7 @@ int find_new_gid (bool sys_group,
/* Create an array to hold all of the discovered GIDs */
used_gids = malloc (sizeof (bool) * (gid_max +1));
if (NULL == used_gids) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: failed to allocate memory: %s\n"),
Prog, strerror (errno));
return -1;
@ -323,7 +323,7 @@ int find_new_gid (bool sys_group,
*
*/
if (!nospam) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique system GID (%s). "
"Suppressing additional messages.\n"),
Prog, strerror (result));
@ -366,7 +366,7 @@ int find_new_gid (bool sys_group,
*
*/
if (!nospam) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique system GID (%s). "
"Suppressing additional messages.\n"),
Prog, strerror (result));
@ -426,7 +426,7 @@ int find_new_gid (bool sys_group,
*
*/
if (!nospam) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique GID (%s). "
"Suppressing additional messages.\n"),
Prog, strerror (result));
@ -469,7 +469,7 @@ int find_new_gid (bool sys_group,
*
*/
if (!nospam) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique GID (%s). "
"Suppressing additional messages.\n"),
Prog, strerror (result));
@ -488,7 +488,7 @@ int find_new_gid (bool sys_group,
}
/* The code reached here and found no available IDs in the range */
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique GID (no more available GIDs)\n"),
Prog);
SYSLOG ((LOG_WARN, "no more available GIDs on the system"));

View File

@ -60,7 +60,7 @@ int find_new_sub_gids (gid_t *range_start, unsigned long *range_count)
count = getdef_ulong ("SUB_GID_COUNT", 65536);
if (min > max || count >= max || (min + count - 1) > max) {
(void) fprintf (stderr,
(void) fprintf (shadow_logfd,
_("%s: Invalid configuration: SUB_GID_MIN (%lu),"
" SUB_GID_MAX (%lu), SUB_GID_COUNT (%lu)\n"),
Prog, min, max, count);
@ -69,7 +69,7 @@ int find_new_sub_gids (gid_t *range_start, unsigned long *range_count)
start = sub_gid_find_free_range(min, max, count);
if (start == (gid_t)-1) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique subordinate GID range\n"),
Prog);
SYSLOG ((LOG_WARN, "no more available subordinate GIDs on the system"));

View File

@ -60,7 +60,7 @@ int find_new_sub_uids (uid_t *range_start, unsigned long *range_count)
count = getdef_ulong ("SUB_UID_COUNT", 65536);
if (min > max || count >= max || (min + count - 1) > max) {
(void) fprintf (stderr,
(void) fprintf (shadow_logfd,
_("%s: Invalid configuration: SUB_UID_MIN (%lu),"
" SUB_UID_MAX (%lu), SUB_UID_COUNT (%lu)\n"),
Prog, min, max, count);
@ -69,7 +69,7 @@ int find_new_sub_uids (uid_t *range_start, unsigned long *range_count)
start = sub_uid_find_free_range(min, max, count);
if (start == (uid_t)-1) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique subordinate UID range\n"),
Prog);
SYSLOG ((LOG_WARN, "no more available subordinate UIDs on the system"));

View File

@ -74,7 +74,7 @@ static int get_ranges (bool sys_user, uid_t *min_id, uid_t *max_id,
/* Check that the ranges make sense */
if (*max_id < *min_id) {
(void) fprintf (stderr,
(void) fprintf (shadow_logfd,
_("%s: Invalid configuration: SYS_UID_MIN (%lu), "
"UID_MIN (%lu), SYS_UID_MAX (%lu)\n"),
Prog, (unsigned long) *min_id,
@ -97,7 +97,7 @@ static int get_ranges (bool sys_user, uid_t *min_id, uid_t *max_id,
/* Check that the ranges make sense */
if (*max_id < *min_id) {
(void) fprintf (stderr,
(void) fprintf (shadow_logfd,
_("%s: Invalid configuration: UID_MIN (%lu), "
"UID_MAX (%lu)\n"),
Prog, (unsigned long) *min_id,
@ -213,7 +213,7 @@ int find_new_uid(bool sys_user,
* more likely to want to stop and address the
* issue.
*/
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Encountered error attempting to use "
"preferred UID: %s\n"),
Prog, strerror (result));
@ -243,7 +243,7 @@ int find_new_uid(bool sys_user,
/* Create an array to hold all of the discovered UIDs */
used_uids = malloc (sizeof (bool) * (uid_max +1));
if (NULL == used_uids) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: failed to allocate memory: %s\n"),
Prog, strerror (errno));
return -1;
@ -323,7 +323,7 @@ int find_new_uid(bool sys_user,
*
*/
if (!nospam) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique system UID (%s). "
"Suppressing additional messages.\n"),
Prog, strerror (result));
@ -366,7 +366,7 @@ int find_new_uid(bool sys_user,
*
*/
if (!nospam) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique system UID (%s). "
"Suppressing additional messages.\n"),
Prog, strerror (result));
@ -426,7 +426,7 @@ int find_new_uid(bool sys_user,
*
*/
if (!nospam) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique UID (%s). "
"Suppressing additional messages.\n"),
Prog, strerror (result));
@ -469,7 +469,7 @@ int find_new_uid(bool sys_user,
*
*/
if (!nospam) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique UID (%s). "
"Suppressing additional messages.\n"),
Prog, strerror (result));
@ -488,7 +488,7 @@ int find_new_uid(bool sys_user,
}
/* The code reached here and found no available IDs in the range */
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: Can't get unique UID (no more available UIDs)\n"),
Prog);
SYSLOG ((LOG_WARN, "no more available UIDs on the system"));

View File

@ -61,23 +61,23 @@
epoch = strtoull (source_date_epoch, &endptr, 10);
if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
|| (errno != 0 && epoch == 0)) {
fprintf (stderr,
fprintf (shadow_logfd,
_("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n"),
strerror(errno));
} else if (endptr == source_date_epoch) {
fprintf (stderr,
fprintf (shadow_logfd,
_("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n"),
endptr);
} else if (*endptr != '\0') {
fprintf (stderr,
fprintf (shadow_logfd,
_("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n"),
endptr);
} else if (epoch > ULONG_MAX) {
fprintf (stderr,
fprintf (shadow_logfd,
_("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to %lu but was found to be: %llu\n"),
ULONG_MAX, epoch);
} else if (epoch > fallback) {
fprintf (stderr,
fprintf (shadow_logfd,
_("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to the current time (%lu) but was found to be: %llu\n"),
fallback, epoch);
} else {

View File

@ -47,19 +47,19 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv)
int idx, argidx;
if (ranges < 0 || argc < 0) {
fprintf(stderr, "%s: error calculating number of arguments\n", Prog);
fprintf(shadow_logfd, "%s: error calculating number of arguments\n", Prog);
return NULL;
}
if (ranges != ((argc + 2) / 3)) {
fprintf(stderr, "%s: ranges: %u is wrong for argc: %d\n", Prog, ranges, argc);
fprintf(shadow_logfd, "%s: ranges: %u is wrong for argc: %d\n", Prog, ranges, argc);
return NULL;
}
if ((ranges * 3) > argc) {
fprintf(stderr, "ranges: %u argc: %d\n",
fprintf(shadow_logfd, "ranges: %u argc: %d\n",
ranges, argc);
fprintf(stderr,
fprintf(shadow_logfd,
_( "%s: Not enough arguments to form %u mappings\n"),
Prog, ranges);
return NULL;
@ -67,7 +67,7 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv)
mappings = calloc(ranges, sizeof(*mappings));
if (!mappings) {
fprintf(stderr, _( "%s: Memory allocation failure\n"),
fprintf(shadow_logfd, _( "%s: Memory allocation failure\n"),
Prog);
exit(EXIT_FAILURE);
}
@ -88,24 +88,24 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv)
return NULL;
}
if (ULONG_MAX - mapping->upper <= mapping->count || ULONG_MAX - mapping->lower <= mapping->count) {
fprintf(stderr, _( "%s: subuid overflow detected.\n"), Prog);
fprintf(shadow_logfd, _( "%s: subuid overflow detected.\n"), Prog);
exit(EXIT_FAILURE);
}
if (mapping->upper > UINT_MAX ||
mapping->lower > UINT_MAX ||
mapping->count > UINT_MAX) {
fprintf(stderr, _( "%s: subuid overflow detected.\n"), Prog);
fprintf(shadow_logfd, _( "%s: subuid overflow detected.\n"), Prog);
exit(EXIT_FAILURE);
}
if (mapping->lower + mapping->count > UINT_MAX ||
mapping->upper + mapping->count > UINT_MAX) {
fprintf(stderr, _( "%s: subuid overflow detected.\n"), Prog);
fprintf(shadow_logfd, _( "%s: subuid overflow detected.\n"), Prog);
exit(EXIT_FAILURE);
}
if (mapping->lower + mapping->count < mapping->lower ||
mapping->upper + mapping->count < mapping->upper) {
/* this one really shouldn't be possible given previous checks */
fprintf(stderr, _( "%s: subuid overflow detected.\n"), Prog);
fprintf(shadow_logfd, _( "%s: subuid overflow detected.\n"), Prog);
exit(EXIT_FAILURE);
}
}
@ -176,19 +176,19 @@ void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings,
} else if (strcmp(map_file, "gid_map") == 0) {
cap = CAP_SETGID;
} else {
fprintf(stderr, _("%s: Invalid map file %s specified\n"), Prog, map_file);
fprintf(shadow_logfd, _("%s: Invalid map file %s specified\n"), Prog, map_file);
exit(EXIT_FAILURE);
}
/* Align setuid- and fscaps-based new{g,u}idmap behavior. */
if (geteuid() == 0 && geteuid() != ruid) {
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) {
fprintf(stderr, _("%s: Could not prctl(PR_SET_KEEPCAPS)\n"), Prog);
fprintf(shadow_logfd, _("%s: Could not prctl(PR_SET_KEEPCAPS)\n"), Prog);
exit(EXIT_FAILURE);
}
if (seteuid(ruid) < 0) {
fprintf(stderr, _("%s: Could not seteuid to %d\n"), Prog, ruid);
fprintf(shadow_logfd, _("%s: Could not seteuid to %d\n"), Prog, ruid);
exit(EXIT_FAILURE);
}
}
@ -204,7 +204,7 @@ void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings,
data[0].effective |= CAP_TO_MASK(CAP_SETFCAP);
data[0].permitted = data[0].effective;
if (capset(&hdr, data) < 0) {
fprintf(stderr, _("%s: Could not set caps\n"), Prog);
fprintf(shadow_logfd, _("%s: Could not set caps\n"), Prog);
exit(EXIT_FAILURE);
}
#endif
@ -222,7 +222,7 @@ void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings,
mapping->lower,
mapping->count);
if ((written <= 0) || (written >= (bufsize - (pos - buf)))) {
fprintf(stderr, _("%s: snprintf failed!\n"), Prog);
fprintf(shadow_logfd, _("%s: snprintf failed!\n"), Prog);
exit(EXIT_FAILURE);
}
pos += written;
@ -231,12 +231,12 @@ void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings,
/* Write the mapping to the mapping file */
fd = openat(proc_dir_fd, map_file, O_WRONLY);
if (fd < 0) {
fprintf(stderr, _("%s: open of %s failed: %s\n"),
fprintf(shadow_logfd, _("%s: open of %s failed: %s\n"),
Prog, map_file, strerror(errno));
exit(EXIT_FAILURE);
}
if (write(fd, buf, pos - buf) != (pos - buf)) {
fprintf(stderr, _("%s: write to %s failed: %s\n"),
fprintf(shadow_logfd, _("%s: write to %s failed: %s\n"),
Prog, map_file, strerror(errno));
exit(EXIT_FAILURE);
}

View File

@ -548,7 +548,7 @@ void setup_limits (const struct passwd *info)
#ifdef LIMITS
if (info->pw_uid != 0) {
if ((setup_user_limits (info->pw_name) & LOGIN_ERROR_LOGIN) != 0) {
(void) fputs (_("Too many logins.\n"), stderr);
(void) fputs (_("Too many logins.\n"), shadow_logfd);
(void) sleep (2); /* XXX: Should be FAIL_DELAY */
exit (EXIT_FAILURE);
}

View File

@ -59,20 +59,20 @@ void do_pam_passwd (const char *user, bool silent, bool change_expired)
ret = pam_start ("passwd", user, &conv, &pamh);
if (ret != PAM_SUCCESS) {
fprintf (stderr,
fprintf (shadow_logfd,
_("passwd: pam_start() failed, error %d\n"), ret);
exit (10); /* XXX */
}
ret = pam_chauthtok (pamh, flags);
if (ret != PAM_SUCCESS) {
fprintf (stderr, _("passwd: %s\n"), pam_strerror (pamh, ret));
fputs (_("passwd: password unchanged\n"), stderr);
fprintf (shadow_logfd, _("passwd: %s\n"), pam_strerror (pamh, ret));
fputs (_("passwd: password unchanged\n"), shadow_logfd);
pam_end (pamh, ret);
exit (10); /* XXX */
}
fputs (_("passwd: password updated successfully\n"), stderr);
fputs (_("passwd: password updated successfully\n"), shadow_logfd);
(void) pam_end (pamh, PAM_SUCCESS);
}
#else /* !USE_PAM */

View File

@ -76,7 +76,7 @@ static int ni_conv (int num_msg,
switch (msg[count]->msg_style) {
case PAM_PROMPT_ECHO_ON:
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: PAM modules requesting echoing are not supported.\n"),
Prog);
goto failed_conversation;
@ -88,7 +88,7 @@ static int ni_conv (int num_msg,
break;
case PAM_ERROR_MSG:
if ( (NULL == msg[count]->msg)
|| (fprintf (stderr, "%s\n", msg[count]->msg) <0)) {
|| (fprintf (shadow_logfd, "%s\n", msg[count]->msg) <0)) {
goto failed_conversation;
}
responses[count].resp = NULL;
@ -101,7 +101,7 @@ static int ni_conv (int num_msg,
responses[count].resp = NULL;
break;
default:
(void) fprintf (stderr,
(void) fprintf (shadow_logfd,
_("%s: conversation type %d not supported.\n"),
Prog, msg[count]->msg_style);
goto failed_conversation;
@ -143,7 +143,7 @@ int do_pam_passwd_non_interactive (const char *pam_service,
ret = pam_start (pam_service, username, &non_interactive_pam_conv, &pamh);
if (ret != PAM_SUCCESS) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: (user %s) pam_start failure %d\n"),
Prog, username, ret);
return 1;
@ -152,7 +152,7 @@ int do_pam_passwd_non_interactive (const char *pam_service,
non_interactive_password = password;
ret = pam_chauthtok (pamh, 0);
if (ret != PAM_SUCCESS) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: (user %s) pam_chauthtok() failed, error:\n"
"%s\n"),
Prog, username, pam_strerror (pamh, ret));

View File

@ -83,7 +83,7 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char **
&& (val = argv[i] + 9))
|| (strcmp (argv[i], short_opt) == 0)) {
if (NULL != prefix) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: multiple --prefix options\n"),
Prog);
exit (E_BAD_ARG);
@ -92,7 +92,7 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char **
if (val) {
prefix = val;
} else if (i + 1 == argc) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: option '%s' requires an argument\n"),
Prog, argv[i]);
exit (E_BAD_ARG);

View File

@ -51,7 +51,7 @@ void passwd_check (const char *user, const char *passwd, unused const char *prog
if (pw_auth (passwd, user, PW_LOGIN, (char *) 0) != 0) {
SYSLOG ((LOG_WARN, "incorrect password for `%s'", user));
(void) sleep (1);
fprintf (stderr, _("Incorrect password for %s.\n"), user);
fprintf (shadow_logfd, _("Incorrect password for %s.\n"), user);
exit (EXIT_FAILURE);
}
}

View File

@ -65,7 +65,7 @@ extern void process_root_flag (const char* short_opt, int argc, char **argv)
&& (val = argv[i] + 7))
|| (strcmp (argv[i], short_opt) == 0)) {
if (NULL != newroot) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: multiple --root options\n"),
Prog);
exit (E_BAD_ARG);
@ -74,7 +74,7 @@ extern void process_root_flag (const char* short_opt, int argc, char **argv)
if (val) {
newroot = val;
} else if (i + 1 == argc) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: option '%s' requires an argument\n"),
Prog, argv[i]);
exit (E_BAD_ARG);
@ -94,34 +94,34 @@ static void change_root (const char* newroot)
/* Drop privileges */
if ( (setregid (getgid (), getgid ()) != 0)
|| (setreuid (getuid (), getuid ()) != 0)) {
fprintf (stderr, _("%s: failed to drop privileges (%s)\n"),
fprintf (shadow_logfd, _("%s: failed to drop privileges (%s)\n"),
Prog, strerror (errno));
exit (EXIT_FAILURE);
}
if ('/' != newroot[0]) {
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: invalid chroot path '%s'\n"),
Prog, newroot);
exit (E_BAD_ARG);
}
if (access (newroot, F_OK) != 0) {
fprintf(stderr,
fprintf(shadow_logfd,
_("%s: cannot access chroot directory %s: %s\n"),
Prog, newroot, strerror (errno));
exit (E_BAD_ARG);
}
if (chdir (newroot) != 0) {
fprintf(stderr,
fprintf(shadow_logfd,
_("%s: cannot chdir to chroot directory %s: %s\n"),
Prog, newroot, strerror (errno));
exit (E_BAD_ARG);
}
if (chroot (newroot) != 0) {
fprintf(stderr,
fprintf(shadow_logfd,
_("%s: unable to chroot to directory %s: %s\n"),
Prog, newroot, strerror (errno));
exit (E_BAD_ARG);

View File

@ -426,7 +426,7 @@ static /*@observer@*/const char *gensalt (size_t salt_size)
salt_len = (size_t) shadow_random (8, 16);
#endif /* USE_SHA_CRYPT */
} else if (0 != strcmp (method, "DES")) {
fprintf (stderr,
fprintf (shadow_logfd,
_("Invalid ENCRYPT_METHOD value: '%s'.\n"
"Defaulting to DES.\n"),
method);

View File

@ -219,7 +219,7 @@ void setup_env (struct passwd *info)
static char temp_pw_dir[] = "/";
if (!getdef_bool ("DEFAULT_HOME") || chdir ("/") == -1) {
fprintf (stderr, _("Unable to cd to '%s'\n"),
fprintf (shadow_logfd, _("Unable to cd to '%s'\n"),
info->pw_dir);
SYSLOG ((LOG_WARN,
"unable to cd to `%s' for user `%s'\n",

View File

@ -96,7 +96,7 @@ static int user_busy_utmp (const char *name)
continue;
}
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: user %s is currently logged in\n"),
Prog, name);
return 1;
@ -249,7 +249,7 @@ static int user_busy_processes (const char *name, uid_t uid)
#ifdef ENABLE_SUBIDS
sub_uid_close();
#endif
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: user %s is currently used by process %d\n"),
Prog, name, pid);
return 1;
@ -272,7 +272,7 @@ static int user_busy_processes (const char *name, uid_t uid)
#ifdef ENABLE_SUBIDS
sub_uid_close();
#endif
fprintf (stderr,
fprintf (shadow_logfd,
_("%s: user %s is currently used by process %d\n"),
Prog, name, pid);
return 1;

View File

@ -74,7 +74,7 @@
result = malloc(sizeof(LOOKUP_TYPE));
if (NULL == result) {
fprintf (stderr, _("%s: out of memory\n"),
fprintf (shadow_logfd, _("%s: out of memory\n"),
"x" STRINGIZE(FUNCTION_NAME));
exit (13);
}
@ -84,7 +84,7 @@
LOOKUP_TYPE *resbuf = NULL;
buffer = (char *)realloc (buffer, length);
if (NULL == buffer) {
fprintf (stderr, _("%s: out of memory\n"),
fprintf (shadow_logfd, _("%s: out of memory\n"),
"x" STRINGIZE(FUNCTION_NAME));
exit (13);
}
@ -132,7 +132,7 @@
if (result) {
result = DUP_FUNCTION(result);
if (NULL == result) {
fprintf (stderr, _("%s: out of memory\n"),
fprintf (shadow_logfd, _("%s: out of memory\n"),
"x" STRINGIZE(FUNCTION_NAME));
exit (13);
}

View File

@ -54,7 +54,7 @@
ptr = (char *) malloc (size);
if (NULL == ptr) {
(void) fprintf (stderr,
(void) fprintf (shadow_logfd,
_("%s: failed to allocate memory: %s\n"),
Prog, strerror (errno));
exit (13);