Blame SOURCES/0020-Use-unsigned-int-for-uid-and-gid-representation.patch

90e381
From dcaaf1e0dd3985e229a87de18b83f301d30b6ce9 Mon Sep 17 00:00:00 2001
90e381
From: Martin Sehnoutka <msehnout@redhat.com>
90e381
Date: Thu, 17 Nov 2016 10:31:39 +0100
90e381
Subject: [PATCH 20/59] Use unsigned int for uid and gid representation.
90e381
90e381
---
90e381
 ls.c      |  4 ++--
90e381
 privops.c |  3 +--
90e381
 session.h |  6 +++---
90e381
 sysutil.c | 44 ++++++++++++++------------------------------
90e381
 sysutil.h | 20 ++++++++++----------
90e381
 5 files changed, 30 insertions(+), 47 deletions(-)
90e381
90e381
diff --git a/ls.c b/ls.c
90e381
index b840136..3c0988c 100644
90e381
--- a/ls.c
90e381
+++ b/ls.c
90e381
@@ -503,7 +503,7 @@ build_dir_line(struct mystr* p_str, const struct mystr* p_filename_str,
90e381
   }
90e381
   else
90e381
   {
90e381
-    int uid = vsf_sysutil_statbuf_get_uid(p_stat);
90e381
+    unsigned int uid = vsf_sysutil_statbuf_get_uid(p_stat);
90e381
     struct vsf_sysutil_user* p_user = 0;
90e381
     if (tunable_text_userdb_names)
90e381
     {
90e381
@@ -528,7 +528,7 @@ build_dir_line(struct mystr* p_str, const struct mystr* p_filename_str,
90e381
   }
90e381
   else
90e381
   {
90e381
-    int gid = vsf_sysutil_statbuf_get_gid(p_stat);
90e381
+    unsigned int gid = vsf_sysutil_statbuf_get_gid(p_stat);
90e381
     struct vsf_sysutil_group* p_group = 0;
90e381
     if (tunable_text_userdb_names)
90e381
     {
90e381
diff --git a/privops.c b/privops.c
90e381
index 21d7267..f27c5c4 100644
90e381
--- a/privops.c
90e381
+++ b/privops.c
90e381
@@ -236,8 +236,7 @@ vsf_privop_do_file_chown(struct vsf_session* p_sess, int fd)
90e381
   /* Drop it like a hot potato unless it's a regular file owned by
90e381
    * the the anonymous ftp user
90e381
    */
90e381
-  if (p_sess->anon_upload_chown_uid == -1 ||
90e381
-      !vsf_sysutil_statbuf_is_regfile(s_p_statbuf) ||
90e381
+  if (!vsf_sysutil_statbuf_is_regfile(s_p_statbuf) ||
90e381
       (vsf_sysutil_statbuf_get_uid(s_p_statbuf) != p_sess->anon_ftp_uid &&
90e381
        vsf_sysutil_statbuf_get_uid(s_p_statbuf) != p_sess->guest_user_uid))
90e381
   {
90e381
diff --git a/session.h b/session.h
90e381
index 27a488f..956bfb7 100644
90e381
--- a/session.h
90e381
+++ b/session.h
90e381
@@ -54,9 +54,9 @@ struct vsf_session
90e381
   struct mystr_list* p_visited_dir_list;
90e381
 
90e381
   /* Details of userids which are interesting to us */
90e381
-  int anon_ftp_uid;
90e381
-  int guest_user_uid;
90e381
-  int anon_upload_chown_uid;
90e381
+  unsigned int anon_ftp_uid;
90e381
+  unsigned int guest_user_uid;
90e381
+  unsigned int anon_upload_chown_uid;
90e381
 
90e381
   /* Things we need to cache before we chroot() */
90e381
   struct mystr banned_email_str;
90e381
diff --git a/sysutil.c b/sysutil.c
90e381
index 2abdd13..9881a66 100644
90e381
--- a/sysutil.c
90e381
+++ b/sysutil.c
90e381
@@ -1454,14 +1454,14 @@ vsf_sysutil_statbuf_get_size(const struct vsf_sysutil_statbuf* p_statbuf)
90e381
   return p_stat->st_size;
90e381
 }
90e381
 
90e381
-int
90e381
+unsigned int
90e381
 vsf_sysutil_statbuf_get_uid(const struct vsf_sysutil_statbuf* p_statbuf)
90e381
 {
90e381
   const struct stat* p_stat = (const struct stat*) p_statbuf;
90e381
   return p_stat->st_uid;
90e381
 }
90e381
 
90e381
-int
90e381
+unsigned int
90e381
 vsf_sysutil_statbuf_get_gid(const struct vsf_sysutil_statbuf* p_statbuf)
90e381
 {
90e381
   const struct stat* p_stat = (const struct stat*) p_statbuf;
90e381
@@ -1502,7 +1502,7 @@ vsf_sysutil_statbuf_get_sortkey_mtime(
90e381
 }
90e381
 
90e381
 void
90e381
-vsf_sysutil_fchown(const int fd, const int uid, const int gid)
90e381
+vsf_sysutil_fchown(const int fd, const unsigned int uid, const unsigned int gid)
90e381
 {
90e381
   if (fchown(fd, uid, gid) != 0)
90e381
   {
90e381
@@ -2320,13 +2320,9 @@ vsf_sysutil_dns_resolve(struct vsf_sysutil_sockaddr** p_sockptr,
90e381
 }
90e381
 
90e381
 struct vsf_sysutil_user*
90e381
-vsf_sysutil_getpwuid(const int uid)
90e381
+vsf_sysutil_getpwuid(const unsigned int uid)
90e381
 {
90e381
-  if (uid < 0)
90e381
-  {
90e381
-    bug("negative uid in vsf_sysutil_getpwuid");
90e381
-  }
90e381
-  return (struct vsf_sysutil_user*) getpwuid((unsigned int) uid);
90e381
+  return (struct vsf_sysutil_user*) getpwuid(uid);
90e381
 }
90e381
 
90e381
 struct vsf_sysutil_user*
90e381
@@ -2349,14 +2345,14 @@ vsf_sysutil_user_get_homedir(const struct vsf_sysutil_user* p_user)
90e381
   return p_passwd->pw_dir;
90e381
 }
90e381
 
90e381
-int
90e381
+unsigned int
90e381
 vsf_sysutil_user_getuid(const struct vsf_sysutil_user* p_user)
90e381
 {
90e381
   const struct passwd* p_passwd = (const struct passwd*) p_user;
90e381
   return p_passwd->pw_uid;
90e381
 }
90e381
 
90e381
-int
90e381
+unsigned int
90e381
 vsf_sysutil_user_getgid(const struct vsf_sysutil_user* p_user)
90e381
 { 
90e381
   const struct passwd* p_passwd = (const struct passwd*) p_user;
90e381
@@ -2364,13 +2360,9 @@ vsf_sysutil_user_getgid(const struct vsf_sysutil_user* p_user)
90e381
 }
90e381
 
90e381
 struct vsf_sysutil_group*
90e381
-vsf_sysutil_getgrgid(const int gid)
90e381
+vsf_sysutil_getgrgid(const unsigned int gid)
90e381
 {
90e381
-  if (gid < 0)
90e381
-  {
90e381
-    die("negative gid in vsf_sysutil_getgrgid");
90e381
-  }
90e381
-  return (struct vsf_sysutil_group*) getgrgid((unsigned int) gid);
90e381
+  return (struct vsf_sysutil_group*) getgrgid(gid);
90e381
 }
90e381
 
90e381
 const char*
90e381
@@ -2445,25 +2437,17 @@ vsf_sysutil_setgid_numeric(int gid)
90e381
   }
90e381
 }
90e381
 
90e381
-int
90e381
+unsigned int
90e381
 vsf_sysutil_geteuid(void)
90e381
 {
90e381
-  int retval = geteuid();
90e381
-  if (retval < 0)
90e381
-  {
90e381
-    die("geteuid");
90e381
-  }
90e381
+  unsigned int retval = geteuid();
90e381
   return retval;
90e381
 }
90e381
 
90e381
-int
90e381
+unsigned int
90e381
 vsf_sysutil_getegid(void)
90e381
 {
90e381
-  int retval = getegid();
90e381
-  if (retval < 0)
90e381
-  {
90e381
-    die("getegid");
90e381
-  }
90e381
+  unsigned int retval = getegid();
90e381
   return retval;
90e381
 }
90e381
 
90e381
@@ -2854,7 +2838,7 @@ vsf_sysutil_ftruncate(int fd)
90e381
   }
90e381
 }
90e381
 
90e381
-int
90e381
+unsigned int
90e381
 vsf_sysutil_getuid(void)
90e381
 {
90e381
   return getuid();
90e381
diff --git a/sysutil.h b/sysutil.h
90e381
index bfc92cb..79b5514 100644
90e381
--- a/sysutil.h
90e381
+++ b/sysutil.h
90e381
@@ -129,15 +129,15 @@ const char* vsf_sysutil_statbuf_get_numeric_date(
90e381
   const struct vsf_sysutil_statbuf* p_stat, int use_localtime);
90e381
 unsigned int vsf_sysutil_statbuf_get_links(
90e381
   const struct vsf_sysutil_statbuf* p_stat);
90e381
-int vsf_sysutil_statbuf_get_uid(const struct vsf_sysutil_statbuf* p_stat);
90e381
-int vsf_sysutil_statbuf_get_gid(const struct vsf_sysutil_statbuf* p_stat);
90e381
+unsigned int vsf_sysutil_statbuf_get_uid(const struct vsf_sysutil_statbuf* p_stat);
90e381
+unsigned int vsf_sysutil_statbuf_get_gid(const struct vsf_sysutil_statbuf* p_stat);
90e381
 int vsf_sysutil_statbuf_is_readable_other(
90e381
   const struct vsf_sysutil_statbuf* p_stat);
90e381
 const char* vsf_sysutil_statbuf_get_sortkey_mtime(
90e381
   const struct vsf_sysutil_statbuf* p_stat);
90e381
 
90e381
 int vsf_sysutil_chmod(const char* p_filename, unsigned int mode);
90e381
-void vsf_sysutil_fchown(const int fd, const int uid, const int gid);
90e381
+void vsf_sysutil_fchown(const int fd, const unsigned int uid, const unsigned int gid);
90e381
 void vsf_sysutil_fchmod(const int fd, unsigned int mode);
90e381
 int vsf_sysutil_readlink(const char* p_filename, char* p_dest,
90e381
                          unsigned int bufsiz);
90e381
@@ -290,15 +290,15 @@ int vsf_sysutil_inet_aton(
90e381
 struct vsf_sysutil_user;
90e381
 struct vsf_sysutil_group;
90e381
 
90e381
-struct vsf_sysutil_user* vsf_sysutil_getpwuid(const int uid);
90e381
+struct vsf_sysutil_user* vsf_sysutil_getpwuid(const unsigned int uid);
90e381
 struct vsf_sysutil_user* vsf_sysutil_getpwnam(const char* p_user);
90e381
 const char* vsf_sysutil_user_getname(const struct vsf_sysutil_user* p_user);
90e381
 const char* vsf_sysutil_user_get_homedir(
90e381
   const struct vsf_sysutil_user* p_user);
90e381
-int vsf_sysutil_user_getuid(const struct vsf_sysutil_user* p_user);
90e381
-int vsf_sysutil_user_getgid(const struct vsf_sysutil_user* p_user);
90e381
+unsigned int vsf_sysutil_user_getuid(const struct vsf_sysutil_user* p_user);
90e381
+unsigned int vsf_sysutil_user_getgid(const struct vsf_sysutil_user* p_user);
90e381
 
90e381
-struct vsf_sysutil_group* vsf_sysutil_getgrgid(const int gid);
90e381
+struct vsf_sysutil_group* vsf_sysutil_getgrgid(const unsigned int gid);
90e381
 const char* vsf_sysutil_group_getname(const struct vsf_sysutil_group* p_group);
90e381
 
90e381
 /* More random things */
90e381
@@ -316,7 +316,7 @@ void vsf_sysutil_qsort(void* p_base, unsigned int num_elem,
90e381
 char* vsf_sysutil_getenv(const char* p_var);
90e381
 typedef void (*exitfunc_t)(void);
90e381
 void vsf_sysutil_set_exit_func(exitfunc_t exitfunc);
90e381
-int vsf_sysutil_getuid(void);
90e381
+unsigned int vsf_sysutil_getuid(void);
90e381
 
90e381
 /* Syslogging (bah) */
90e381
 void vsf_sysutil_openlog(int force);
90e381
@@ -329,8 +329,8 @@ void vsf_sysutil_setuid(const struct vsf_sysutil_user* p_user);
90e381
 void vsf_sysutil_setgid(const struct vsf_sysutil_user* p_user);
90e381
 void vsf_sysutil_setuid_numeric(int uid);
90e381
 void vsf_sysutil_setgid_numeric(int gid);
90e381
-int vsf_sysutil_geteuid(void);
90e381
-int vsf_sysutil_getegid(void);
90e381
+unsigned int vsf_sysutil_geteuid(void);
90e381
+unsigned int vsf_sysutil_getegid(void);
90e381
 void vsf_sysutil_seteuid(const struct vsf_sysutil_user* p_user);
90e381
 void vsf_sysutil_setegid(const struct vsf_sysutil_user* p_user);
90e381
 void vsf_sysutil_seteuid_numeric(int uid);
90e381
-- 
90e381
2.14.4
90e381