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

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