Przeglądaj źródła

dpkg-statoverride: Do not abort when user and group names are unknown

When parsing the statoverride database from dpkg-statoverride do
not consider it an error and refuse to operate at all if the user
or group names are not known to the system, just preserve them.

Closes: #563307
Guillem Jover 16 lat temu
rodzic
commit
e4d6db177f
6 zmienionych plików z 53 dodań i 10 usunięć
  1. 3 0
      debian/changelog
  2. 5 0
      lib/dpkg/file.h
  3. 1 1
      src/archives.c
  4. 6 1
      src/filesdb.h
  5. 13 1
      src/statcmd.c
  6. 25 7
      src/statdb.c

+ 3 - 0
debian/changelog

@@ -18,6 +18,9 @@ dpkg (1.17.11) UNRELEASED; urgency=low
   * Do not disable the stack-protector build flags on arm64 in Debian and
     derivatives, the toolchain supports them now.
     Thanks to Adam Conrad <adconrad@debian.org>. Closes: #751032
+  * When parsing the statoverride database from dpkg-statoverride do not
+    consider it an error and refuse to operate at all if the user or group
+    names are not known to the system, just preserve them. Closes: #563307
 
   [ Updated programs translations ]
   * Danish (Joe Dalton). Closes: #754127

+ 5 - 0
lib/dpkg/file.h

@@ -39,6 +39,11 @@ struct file_stat {
 	uid_t uid;
 	gid_t gid;
 	mode_t mode;
+
+	/* Used by dpkg-statoverride when parsing the database to preserve the
+	 * user and group names in case the system does not know about them. */
+	const char *uname;
+	const char *gname;
 };
 
 void file_copy_perms(const char *src, const char *dst);

+ 1 - 1
src/archives.c

@@ -1643,7 +1643,7 @@ archivefiles(const char *const *argv)
   fnameidlu= fnamevb.used;
 
   ensure_diversions();
-  ensure_statoverrides();
+  ensure_statoverrides(STATDB_PARSE_NORMAL);
 
   while ((thisarg = *argp++) != NULL) {
     if (setjmp(ejbuf)) {

+ 6 - 1
src/filesdb.h

@@ -155,10 +155,15 @@ void ensure_package_clientdata(struct pkginfo *pkg);
 
 void ensure_diversions(void);
 
+enum statdb_parse_flags {
+	STATDB_PARSE_NORMAL = 0,
+	STATDB_PARSE_LAX = 1,
+};
+
 uid_t statdb_parse_uid(const char *str);
 gid_t statdb_parse_gid(const char *str);
 mode_t statdb_parse_mode(const char *str);
-void ensure_statoverrides(void);
+void ensure_statoverrides(enum statdb_parse_flags flags);
 
 #define LISTFILE           "list"
 #define HASHFILE           "md5sums"

+ 13 - 1
src/statcmd.c

@@ -122,7 +122,15 @@ statdb_node_new(const char *user, const char *group, const char *mode)
 	filestat = nfmalloc(sizeof(*filestat));
 
 	filestat->uid = statdb_parse_uid(user);
+	if (filestat->uid == (uid_t)-1)
+		filestat->uname = user;
+	else
+		filestat->uname = NULL;
 	filestat->gid = statdb_parse_gid(group);
+	if (filestat->gid == (gid_t)-1)
+		filestat->gname = group;
+	else
+		filestat->gname = NULL;
 	filestat->mode = statdb_parse_mode(mode);
 
 	return filestat;
@@ -174,12 +182,16 @@ statdb_node_print(FILE *out, struct filenamenode *file)
 	pw = getpwuid(filestat->uid);
 	if (pw)
 		fprintf(out, "%s ", pw->pw_name);
+	else if (filestat->uname)
+		fprintf(out, "%s ", filestat->uname);
 	else
 		fprintf(out, "#%d ", filestat->uid);
 
 	gr = getgrgid(filestat->gid);
 	if (gr)
 		fprintf(out, "%s ", gr->gr_name);
+	else if (filestat->gname)
+		fprintf(out, "%s ", filestat->gname);
 	else
 		fprintf(out, "#%d ", filestat->gid);
 
@@ -356,7 +368,7 @@ main(int argc, const char *const *argv)
 		badusage(_("need an action option"));
 
 	filesdbinit();
-	ensure_statoverrides();
+	ensure_statoverrides(STATDB_PARSE_LAX);
 
 	ret = cipaction->action(argv);
 

+ 25 - 7
src/statdb.c

@@ -60,10 +60,11 @@ statdb_parse_uid(const char *str)
 		uid = (uid_t)value;
 	} else {
 		struct passwd *pw = getpwnam(str);
+
 		if (pw == NULL)
-			ohshit(_("syntax error: unknown user '%s' in statoverride file"),
-			       str);
-		uid = pw->pw_uid;
+			uid = (uid_t)-1;
+		else
+			uid = pw->pw_uid;
 	}
 
 	return uid;
@@ -85,10 +86,11 @@ statdb_parse_gid(const char *str)
 		gid = (gid_t)value;
 	} else {
 		struct group *gr = getgrnam(str);
+
 		if (gr == NULL)
-			ohshit(_("syntax error: unknown group '%s' in statoverride file"),
-			       str);
-		gid = gr->gr_gid;
+			gid = (gid_t)-1;
+		else
+			gid = gr->gr_gid;
 	}
 
 	return gid;
@@ -108,7 +110,7 @@ statdb_parse_mode(const char *str)
 }
 
 void
-ensure_statoverrides(void)
+ensure_statoverrides(enum statdb_parse_flags flags)
 {
 	static struct stat sb_prev;
 	struct stat sb_next;
@@ -201,6 +203,14 @@ ensure_statoverrides(void)
 		*ptr = '\0';
 
 		fso->uid = statdb_parse_uid(thisline);
+		if (fso->uid == (uid_t)-1)
+			fso->uname = thisline;
+		else
+			fso->uname = NULL;
+
+		if (fso->uid == (uid_t)-1 && !(flags & STATDB_PARSE_LAX))
+			ohshit(_("unknown user '%s' in statoverride file"),
+			       thisline);
 
 		/* Move to the next bit */
 		thisline = ptr + 1;
@@ -214,6 +224,14 @@ ensure_statoverrides(void)
 		*ptr = '\0';
 
 		fso->gid = statdb_parse_gid(thisline);
+		if (fso->gid == (gid_t)-1)
+			fso->gname = thisline;
+		else
+			fso->gname = NULL;
+
+		if (fso->gid == (gid_t)-1 && !(flags & STATDB_PARSE_LAX))
+			ohshit(_("unknown group '%s' in statoverride file"),
+			       thisline);
 
 		/* Move to the next bit */
 		thisline = ptr + 1;