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

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