change to allow names or numbers to be used for uid and gid.
[rsync.git] / util.c
diff --git a/util.c b/util.c
index 9b28cb03d353f7e5dc3ff9f5dc184cc353d8202a..67308cd2d22e74be57b831b034730ff25f0d0f35 100644 (file)
--- a/util.c
+++ b/util.c
@@ -455,3 +455,30 @@ void strlcpy(char *d, char *s, int maxlen)
        memcpy(d, s, len);
        d[len] = 0;
 }
+
+/* turn a user name into a uid */
+int name_to_uid(char *name, uid_t *uid)
+{
+       struct passwd *pass;
+       if (!name || !*name) return 0;
+       pass = getpwnam(name);
+       if (pass) {
+               *uid = pass->pw_uid;
+               return 1;
+       }
+       return 0;
+}
+
+/* turn a group name into a gid */
+int name_to_gid(char *name, gid_t *gid)
+{
+       struct group *grp;
+       if (!name || !*name) return 0;
+       grp = getgrnam(name);
+       if (grp) {
+               *gid = grp->gr_gid;
+               return 1;
+       }
+       return 0;
+}
+