From 5d85539960b4bc313310752816bcc23b4e9cf03e Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 30 Nov 2010 15:22:07 -0500 Subject: [PATCH] Use %u to print uid/gid, not %lu and adjust casts to match. --HG-- branch : 1.7 --- auth/kerb4.c | 4 ++-- check.c | 22 +++++++++++----------- env.c | 4 ++-- pwutil.c | 14 ++++++++------ sudo.c | 12 ++++++------ 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/auth/kerb4.c b/auth/kerb4.c index f3107a063..86bfc03d5 100644 --- a/auth/kerb4.c +++ b/auth/kerb4.c @@ -83,8 +83,8 @@ kerb4_verify(pw, pass, auth) * Set the ticket file to be in sudo sudo timedir so we don't * wipe out other (real) kerberos tickets. */ - (void) snprintf(tkfile, sizeof(tkfile), "%s/tkt%lu", - _PATH_SUDO_TIMEDIR, (unsigned long) pw->pw_uid); + (void) snprintf(tkfile, sizeof(tkfile), "%s/tkt%u", + _PATH_SUDO_TIMEDIR, (unsigned int) pw->pw_uid); (void) krb_set_tkt_string(tkfile); /* Convert the password to a ticket given. */ diff --git a/check.c b/check.c index e40e1238c..b324c06bd 100644 --- a/check.c +++ b/check.c @@ -453,9 +453,9 @@ timestamp_status(timestampdir, timestampfile, user, flags) log_error(NO_EXIT, "%s exists but is not a directory (0%o)", dirparent, (unsigned int) sb.st_mode); else if (sb.st_uid != timestamp_uid) - log_error(NO_EXIT, "%s owned by uid %lu, should be uid %lu", - dirparent, (unsigned long) sb.st_uid, - (unsigned long) timestamp_uid); + log_error(NO_EXIT, "%s owned by uid %u, should be uid %u", + dirparent, (unsigned int) sb.st_uid, + (unsigned int) timestamp_uid); else if ((sb.st_mode & 0000022)) log_error(NO_EXIT, "%s writable by non-owner (0%o), should be mode 0700", @@ -500,9 +500,9 @@ timestamp_status(timestampdir, timestampfile, user, flags) log_error(NO_EXIT, "%s exists but is not a directory (0%o)", timestampdir, (unsigned int) sb.st_mode); } else if (sb.st_uid != timestamp_uid) - log_error(NO_EXIT, "%s owned by uid %lu, should be uid %lu", - timestampdir, (unsigned long) sb.st_uid, - (unsigned long) timestamp_uid); + log_error(NO_EXIT, "%s owned by uid %u, should be uid %u", + timestampdir, (unsigned int) sb.st_uid, + (unsigned int) timestamp_uid); else if ((sb.st_mode & 0000022)) log_error(NO_EXIT, "%s writable by non-owner (0%o), should be mode 0700", @@ -545,9 +545,9 @@ timestamp_status(timestampdir, timestampfile, user, flags) /* If bad uid or file mode, complain and kill the bogus file. */ if (sb.st_uid != timestamp_uid) { log_error(NO_EXIT, - "%s owned by uid %lu, should be uid %lu", - timestampfile, (unsigned long) sb.st_uid, - (unsigned long) timestamp_uid); + "%s owned by uid %u, should be uid %u", + timestampfile, (unsigned int) sb.st_uid, + (unsigned int) timestamp_uid); (void) unlink(timestampfile); } else if ((sb.st_mode & 0000022)) { log_error(NO_EXIT, @@ -717,8 +717,8 @@ get_authpw() log_error(0, "unknown user: %s", def_runas_default); } else if (def_targetpw) { if (runas_pw->pw_name == NULL) - log_error(NO_MAIL|MSG_ONLY, "unknown uid: %lu", - (unsigned long) runas_pw->pw_uid); + log_error(NO_MAIL|MSG_ONLY, "unknown uid: %u", + (unsigned int) runas_pw->pw_uid); pw_addref(runas_pw); pw = runas_pw; } else { diff --git a/env.c b/env.c index 8bc586743..c26e0e041 100644 --- a/env.c +++ b/env.c @@ -820,9 +820,9 @@ rebuild_env(noexec) /* Add the SUDO_USER, SUDO_UID, SUDO_GID environment variables. */ sudo_setenv("SUDO_USER", user_name, TRUE); - snprintf(idbuf, sizeof(idbuf), "%lu", (unsigned long) user_uid); + snprintf(idbuf, sizeof(idbuf), "%u", (unsigned int) user_uid); sudo_setenv("SUDO_UID", idbuf, TRUE); - snprintf(idbuf, sizeof(idbuf), "%lu", (unsigned long) user_gid); + snprintf(idbuf, sizeof(idbuf), "%u", (unsigned int) user_gid); sudo_setenv("SUDO_GID", idbuf, TRUE); /* Free old environment. */ diff --git a/pwutil.c b/pwutil.c index d09e684a1..26696fe70 100644 --- a/pwutil.c +++ b/pwutil.c @@ -251,15 +251,16 @@ sudo_getpwuid(uid) if ((key.d.pw = getpwuid(uid)) != NULL) { item = make_pwitem(key.d.pw, NULL); if (rbinsert(pwcache_byuid, item) != NULL) - errorx(1, "unable to cache uid %lu (%s), already exists", - uid, item->d.pw->pw_name); + errorx(1, "unable to cache uid %u (%s), already exists", + (unsigned int) uid, item->d.pw->pw_name); } else { item = emalloc(sizeof(*item)); item->refcnt = 1; item->k.uid = uid; item->d.pw = NULL; if (rbinsert(pwcache_byuid, item) != NULL) - errorx(1, "unable to cache uid %lu, already exists", uid); + errorx(1, "unable to cache uid %u, already exists", + (unsigned int) uid); } #ifdef HAVE_SETAUTHDB aix_restoreauthdb(); @@ -528,15 +529,16 @@ sudo_getgrgid(gid) if ((key.d.gr = getgrgid(gid)) != NULL) { item = make_gritem(key.d.gr, NULL); if (rbinsert(grcache_bygid, item) != NULL) - errorx(1, "unable to cache gid %lu (%s), already exists", - gid, key.d.gr->gr_name); + errorx(1, "unable to cache gid %u (%s), already exists", + (unsigned int) gid, key.d.gr->gr_name); } else { item = emalloc(sizeof(*item)); item->refcnt = 1; item->k.gid = gid; item->d.gr = NULL; if (rbinsert(grcache_bygid, item) != NULL) - errorx(1, "unable to cache gid %lu, already exists, gid"); + errorx(1, "unable to cache gid %u, already exists", + (unsigned int) gid); } done: item->refcnt++; diff --git a/sudo.c b/sudo.c index 9c3c944e9..185e1ee03 100644 --- a/sudo.c +++ b/sudo.c @@ -646,8 +646,8 @@ init_vars(envp) char pw_name[MAX_UID_T_LEN + 1]; pw.pw_uid = getuid(); - (void) snprintf(pw_name, sizeof(pw_name), "%lu", - (unsigned long) pw.pw_uid); + (void) snprintf(pw_name, sizeof(pw_name), "%u", + (unsigned int) pw.pw_uid); pw.pw_name = pw_name; sudo_user.pw = &pw; @@ -1013,11 +1013,11 @@ open_sudoers(sudoers, doedit, keepopen) (unsigned int) (statbuf.st_mode & 07777), (unsigned int) SUDOERS_MODE); else if (statbuf.st_uid != SUDOERS_UID) - log_error(NO_EXIT, "%s is owned by uid %lu, should be %lu", sudoers, - (unsigned long) statbuf.st_uid, (unsigned long) SUDOERS_UID); + log_error(NO_EXIT, "%s is owned by uid %u, should be %u", sudoers, + (unsigned int) statbuf.st_uid, (unsigned int) SUDOERS_UID); else if (statbuf.st_gid != SUDOERS_GID) - log_error(NO_EXIT, "%s is owned by gid %lu, should be %lu", sudoers, - (unsigned long) statbuf.st_gid, (unsigned long) SUDOERS_GID); + log_error(NO_EXIT, "%s is owned by gid %u, should be %u", sudoers, + (unsigned int) statbuf.st_gid, (unsigned int) SUDOERS_GID); else if ((fp = fopen(sudoers, "r")) == NULL) log_error(USE_ERRNO|NO_EXIT, "can't open %s", sudoers); else { -- 2.40.0