Patchwork opkg: Ensure we use the uname/gname fields when extracting tarballs

login
register
mail settings
Submitter Richard Purdie
Date Nov. 11, 2011, 5:22 p.m.
Message ID <1321032164.26881.5.camel@ted>
Download mbox | patch
Permalink /patch/14857/
State Not Applicable
Headers show

Comments

Richard Purdie - Nov. 11, 2011, 5:22 p.m.
When extracting packages onto the target system in particular, we really
want to ensure the name fields in the tarball are used over and above
the numerical uid/gid values. This patch adds this functionality to opkg
and ensures package upgrades work correctly permission wise

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>

---
Koen Kooi - Nov. 11, 2011, 5:57 p.m.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Op 11-11-11 18:22, Richard Purdie schreef:
> When extracting packages onto the target system in particular, we really 
> want to ensure the name fields in the tarball are used over and above the
> numerical uid/gid values. This patch adds this functionality to opkg and
> ensures package upgrades work correctly permission wise
> 
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> 
> --- diff --git a/meta/recipes-devtools/opkg/opkg/add_uname_support.patch
> b/meta/recipes-devtools/opkg/opkg/add_uname_support.patch new file mode
> 100644 index 0000000..885f75f --- a/dev/null +++
> b/meta/recipes-devtools/opkg/opkg/add_uname_support.patch @@ -0,0 +1,85
> @@ +When updating packages on the target device we ideally want to match
>  +user and group numbers from the existing file system. This patch
> encourages +opkg to lookup the uname/gname fields first and only use the
> hardcoded +numerical values if that fails.

This seems to be missing the upstream-status field

> +RP 11/11/11

UK or US date notation?

regards,

Koen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: GPGTools - http://gpgtools.org

iEYEARECAAYFAk69YgAACgkQMkyGM64RGpHBwwCfVPVYgFkPIrJRfbCprw96V7FC
kJEAn2K8LvKBG+NsStT9dCeAuvkCVX9O
=zJCW
-----END PGP SIGNATURE-----

Patch

diff --git a/meta/recipes-devtools/opkg/opkg/add_uname_support.patch b/meta/recipes-devtools/opkg/opkg/add_uname_support.patch
new file mode 100644
index 0000000..885f75f
--- a/dev/null
+++ b/meta/recipes-devtools/opkg/opkg/add_uname_support.patch
@@ -0,0 +1,85 @@ 
+When updating packages on the target device we ideally want to match 
+user and group numbers from the existing file system. This patch encourages
+opkg to lookup the uname/gname fields first and only use the hardcoded
+numerical values if that fails.
+
+RP 11/11/11
+
+Index: trunk/libbb/unarchive.c
+===================================================================
+--- trunk.orig/libbb/unarchive.c	2011-11-11 15:52:59.761674091 +0000
++++ trunk/libbb/unarchive.c	2011-11-11 17:04:56.501574419 +0000
+@@ -22,10 +22,13 @@
+ #include <stdio.h>
+ #include <errno.h>
+ #include <stdlib.h>
++#include <stdbool.h>
+ #include <string.h>
+ #include <unistd.h>
+ #include <utime.h>
+ #include <libgen.h>
++#include <grp.h>
++#include <pwd.h>
+ 
+ #include "libbb.h"
+ 
+@@ -436,6 +439,42 @@
+ 	free(ar_entry);
+ }
+ 
++static char uname_cache[32] = "";
++static uid_t uid_cache;
++
++static bool update_unamecache(char *uname) {
++	struct passwd *passwd;
++	if (!uname)
++		return FALSE;
++	if (!uname_cache[0] && strcmp(uname_cache, uname) == 0)
++		return TRUE;
++	passwd = getpwnam(uname);
++	if (passwd) {
++		uid_cache = passwd->pw_uid;
++		strncpy(uname, uname_cache, 32);
++		return TRUE;
++	}
++	return FALSE;
++}
++
++static char gname_cache[32] = "";
++static gid_t gid_cache;
++
++static bool update_gnamecache(char *gname) {
++	struct group *group;
++	if (!gname)
++		return FALSE;
++	if (!gname_cache[0] && strcmp(gname_cache, gname) == 0)
++		return TRUE;
++	group = getgrnam(gname);
++	if (group) {
++		gid_cache = group->gr_gid;
++		strncpy(gname, gname_cache, 32);
++		return TRUE;
++	}
++	return FALSE;
++}
++
+ 
+ static file_header_t *
+ get_header_tar(FILE *tar_stream)
+@@ -515,8 +554,14 @@
+ */
+         tar_entry->mode = 07777 & strtol(tar.formated.mode, NULL, 8);
+ 
+-	tar_entry->uid   = strtol(tar.formated.uid, NULL, 8);
+-	tar_entry->gid   = strtol(tar.formated.gid, NULL, 8);
++	if (update_unamecache(tar.formated.uname))
++		tar_entry->uid = uid_cache;
++	else
++		tar_entry->uid = strtol(tar.formated.uid, NULL, 8);
++	if (update_gnamecache(tar.formated.gname))
++		tar_entry->gid = gid_cache;
++	else
++		tar_entry->gid = strtol(tar.formated.gid, NULL, 8);
+ 	tar_entry->size  = strtol(tar.formated.size, NULL, 8);
+ 	tar_entry->mtime = strtol(tar.formated.mtime, NULL, 8);
+ 
diff --git a/meta/recipes-devtools/opkg/opkg_svn.bb b/meta/recipes-devtools/opkg/opkg_svn.bb
index 099a373..8f50f67 10From a781e059562e91c6467be7c4aac43561413b3703 Mon Sep 17 00:00:00 2001
From: Richard Purdie <richard.purdie@linuxfoundation.org>
Date: Fri, 11 Nov 2011 17:17:01 +0000
Subject: opkg: Ensure we use the uname/gname fields when extracting tarballs

---
diff --git a/meta/recipes-devtools/opkg/opkg/add_uname_support.patch b/meta/recipes-devtools/opkg/opkg/add_uname_support.patch
new file mode 100644
index 0000000..885f75f
--- a/dev/null
+++ b/meta/recipes-devtools/opkg/opkg/add_uname_support.patch
@@ -0,0 +1,85 @@ 
+When updating packages on the target device we ideally want to match 
+user and group numbers from the existing file system. This patch encourages
+opkg to lookup the uname/gname fields first and only use the hardcoded
+numerical values if that fails.
+
+RP 11/11/11
+
+Index: trunk/libbb/unarchive.c
+===================================================================
+--- trunk.orig/libbb/unarchive.c	2011-11-11 15:52:59.761674091 +0000
++++ trunk/libbb/unarchive.c	2011-11-11 17:04:56.501574419 +0000
+@@ -22,10 +22,13 @@
+ #include <stdio.h>
+ #include <errno.h>
+ #include <stdlib.h>
++#include <stdbool.h>
+ #include <string.h>
+ #include <unistd.h>
+ #include <utime.h>
+ #include <libgen.h>
++#include <grp.h>
++#include <pwd.h>
+ 
+ #include "libbb.h"
+ 
+@@ -436,6 +439,42 @@
+ 	free(ar_entry);
+ }
+ 
++static char uname_cache[32] = "";
++static uid_t uid_cache;
++
++static bool update_unamecache(char *uname) {
++	struct passwd *passwd;
++	if (!uname)
++		return FALSE;
++	if (!uname_cache[0] && strcmp(uname_cache, uname) == 0)
++		return TRUE;
++	passwd = getpwnam(uname);
++	if (passwd) {
++		uid_cache = passwd->pw_uid;
++		strncpy(uname, uname_cache, 32);
++		return TRUE;
++	}
++	return FALSE;
++}
++
++static char gname_cache[32] = "";
++static gid_t gid_cache;
++
++static bool update_gnamecache(char *gname) {
++	struct group *group;
++	if (!gname)
++		return FALSE;
++	if (!gname_cache[0] && strcmp(gname_cache, gname) == 0)
++		return TRUE;
++	group = getgrnam(gname);
++	if (group) {
++		gid_cache = group->gr_gid;
++		strncpy(gname, gname_cache, 32);
++		return TRUE;
++	}
++	return FALSE;
++}
++
+ 
+ static file_header_t *
+ get_header_tar(FILE *tar_stream)
+@@ -515,8 +554,14 @@
+ */
+         tar_entry->mode = 07777 & strtol(tar.formated.mode, NULL, 8);
+ 
+-	tar_entry->uid   = strtol(tar.formated.uid, NULL, 8);
+-	tar_entry->gid   = strtol(tar.formated.gid, NULL, 8);
++	if (update_unamecache(tar.formated.uname))
++		tar_entry->uid = uid_cache;
++	else
++		tar_entry->uid = strtol(tar.formated.uid, NULL, 8);
++	if (update_gnamecache(tar.formated.gname))
++		tar_entry->gid = gid_cache;
++	else
++		tar_entry->gid = strtol(tar.formated.gid, NULL, 8);
+ 	tar_entry->size  = strtol(tar.formated.size, NULL, 8);
+ 	tar_entry->mtime = strtol(tar.formated.mtime, NULL, 8);
+ 
diff --git a/meta/recipes-devtools/opkg/opkg_svn.bb b/meta/recipes-devtools/opkg/opkg_svn.bb
index 099a373..8f50f67 100644
--- a/meta/recipes-devtools/opkg/opkg_svn.bb
+++ b/meta/recipes-devtools/opkg/opkg_svn.bb
@@ -11,13 +11,14 @@  RREPLACES_${PN} = "opkg-nogpg"
 
 SRC_URI = "svn://opkg.googlecode.com/svn;module=trunk;proto=http \
            file://add_vercmp.patch \
+           file://add_uname_support.patch \
 "
 
 S = "${WORKDIR}/trunk"
 
 SRCREV = "625"
 PV = "0.1.8+svnr${SRCPV}"
-PR = "r2"
+PR = "r3"
 
 PACKAGES =+ "libopkg${PKGSUFFIX}-dev libopkg${PKGSUFFIX} update-alternatives-cworth${PKGSUFFIX}"
 
--
cgit 0.9.0.1
0644
--- a/meta/recipes-devtools/opkg/opkg_svn.bb
+++ b/meta/recipes-devtools/opkg/opkg_svn.bb
@@ -11,13 +11,14 @@  RREPLACES_${PN} = "opkg-nogpg"
 
 SRC_URI = "svn://opkg.googlecode.com/svn;module=trunk;proto=http \
            file://add_vercmp.patch \
+           file://add_uname_support.patch \
 "
 
 S = "${WORKDIR}/trunk"
 
 SRCREV = "625"
 PV = "0.1.8+svnr${SRCPV}"
-PR = "r2"
+PR = "r3"
 
 PACKAGES =+ "libopkg${PKGSUFFIX}-dev libopkg${PKGSUFFIX} update-alternatives-cworth${PKGSUFFIX}"