Skip to content

allow uid/gid to be specified numerically #217

@cgzones

Description

@cgzones

From https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=415857:

Logrotate should allow the user to specify the create uid/gid
numerically.  This is useful with network filesystems which have their
own set of uids that don't map to a system username.

Attached patch:

diff -ur logrotate-3.7.1/config.c new/config.c
--- logrotate-3.7.1/config.c	2003-08-07 06:13:14.000000000 -0500
+++ new/config.c	2007-03-22 11:36:47.000000000 -0500
@@ -14,6 +14,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <assert.h>
+#include <limits.h>
 
 #include "basenames.h"
 #include "log.h"
@@ -544,24 +555,38 @@
 		    newlog->createMode = createMode;
 		
 		if (rc > 1) {
-		    pw = getpwnam(createOwner);
-		    if (!pw) {
-			message(MESS_ERROR, "%s:%d unknown user '%s'\n", 
-				configFile, lineNum, createOwner);
-			return 1;
-		    } 
-		    newlog->createUid = pw->pw_uid;
-		    endpwent();
+		    char* endptr;
+		    uid_t myuid;
+		    myuid = strtoul(createOwner, &endptr, 10);
+		    if (createOwner[0] != '\0' && *endptr == '\0' && myuid != ULONG_MAX)
+			newlog->createUid = myuid;
+		    else {
+			pw = getpwnam(createOwner);
+			if (!pw) {
+			    message(MESS_ERROR, "%s:%d unknown user '%s'\n", 
+				    configFile, lineNum, createOwner);
+			    return 1;
+			} 
+			newlog->createUid = pw->pw_uid;
+			endpwent();
+		    }
 		} 
 		if (rc > 2) {
-		    group = getgrnam(createGroup);
-		    if (!group) {
-			message(MESS_ERROR, "%s:%d unknown group '%s'\n", 
-				configFile, lineNum, createGroup);
-			return 1;
-		    } 
-		    newlog->createGid = group->gr_gid;
-		    endgrent();
+		    char* endptr;
+		    gid_t mygid;
+		    mygid = strtoul(createGroup, &endptr, 10);
+		    if (createGroup[0] != '\0' && *endptr == '\0' && mygid != ULONG_MAX)
+			newlog->createGid = mygid;
+		    else {
+			group = getgrnam(createGroup);
+			if (!group) {
+			    message(MESS_ERROR, "%s:%d unknown group '%s'\n", 
+				    configFile, lineNum, createGroup);
+			    return 1;
+			} 
+			newlog->createGid = group->gr_gid;
+			endgrent();
+		    }
 		} 
 
 		newlog->flags |= LOG_FLAG_CREATE;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions