]> code.ossystems Code Review - openembedded-core.git/blob
e6c6284a24bf275f9096a5b306cd568e5b02a468
[openembedded-core.git] /
1 From 09f04dc36f21c179235109b3dcddce9dda9a8ba8 Mon Sep 17 00:00:00 2001
2 From: "Peter A. Bigot" <pab@pabigot.com>
3 Date: Sun, 12 Oct 2014 12:17:48 -0500
4 Subject: [PATCH 3/3] pseudo_client.c: support multiple directories in
5  PSEUDO_PASSWD
6
7 For OpenEmbedded it is highly unlikely that using the build host passwd
8 file is the right approach.  Most packages can be built with a pseudo
9 that was configured --without-passwd-fallback, since
10 PSEUDO_PASSWD=${STAGING_DIR_TARGET} suffices.
11
12 This fails when building images, because image.bbclass (correctly)
13 overrides to PSEUDO_PASSWD=${IMAGE_ROOTFS}.  However, the rootfs
14 /etc/passwd is not created until the post-install phase of base-passwd,
15 which is long after a passwd file is required.  For example, the smart
16 RPM interface wants to look up uid 0 right away.  The right solution
17 here is to look first in ${IMAGE_ROOTFS}, then fallback to
18 a location holding immutable files with the minimum user/group settings
19 necessary to successfully get base-passwd onto the target.
20
21 Rather than rework pseudo to change PSEUDO_PASSWD_FALLBACK to be a
22 run-time rather than compile-time specification, rework the handling of
23 PSEUDO_PASSWD so that it is a colon-separated list of directories that
24 are processed in order.
25
26 Upstream-Status: Pending
27 Signed-off-by: Peter A. Bigot <pab@pabigot.com>
28 ---
29  pseudo_client.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
30  1 file changed, 49 insertions(+), 1 deletion(-)
31
32 diff --git a/pseudo_client.c b/pseudo_client.c
33 index 7a4d7fa..b52b86a 100644
34 --- a/pseudo_client.c
35 +++ b/pseudo_client.c
36 @@ -75,6 +75,8 @@ int pseudo_umask = 022;
37  
38  static char **fd_paths = NULL;
39  static int nfds = 0;
40 +static const char **passwd_paths = NULL;
41 +static int npasswd_paths = 0;
42  static int messages = 0;
43  static struct timeval message_time = { .tv_sec = 0 };
44  static int pseudo_inited = 0;
45 @@ -93,7 +95,7 @@ gid_t pseudo_egid;
46  gid_t pseudo_sgid;
47  gid_t pseudo_fgid;
48  
49 -#define PSEUDO_ETC_FILE(filename, realname, flags) pseudo_etc_file(filename, realname, flags, (const char *[]) { pseudo_chroot, pseudo_passwd, PSEUDO_PASSWD_FALLBACK }, PSEUDO_PASSWD_FALLBACK ? 3 : 2)
50 +#define PSEUDO_ETC_FILE(filename, realname, flags) pseudo_etc_file(filename, realname, flags, passwd_paths, npasswd_paths)
51  
52  /* helper function to make a directory, just like mkdir -p.
53   * Can't use system() because the child shell would end up trying
54 @@ -117,6 +119,42 @@ mkdir_p(char *path) {
55         (void) mkdir(path, 0755);
56  }
57  
58 +static int
59 +build_passwd_paths(const char **paths)
60 +{
61 +       int np = 0;
62 +       
63 +       if (pseudo_chroot) {
64 +               if (paths) {
65 +                       paths[np] = pseudo_chroot;
66 +               }
67 +               ++np;
68 +       }
69 +       if (pseudo_passwd) {
70 +               const char *cp = pseudo_passwd;
71 +               const char *next = strchr(cp, ':');
72 +               while (next) {
73 +                       if (paths) {
74 +                               paths[np] = strndup(cp, next-cp);
75 +                       }
76 +                       ++np;
77 +                       cp = next+1;
78 +                       next = strchr(cp, ':');
79 +               }
80 +               if (paths) {
81 +                       paths[np] = strdup(cp);
82 +               }
83 +               ++np;
84 +       }
85 +       if (PSEUDO_PASSWD_FALLBACK) {
86 +               if (paths) {
87 +                       paths[np] = PSEUDO_PASSWD_FALLBACK;
88 +               }
89 +               ++np;
90 +       }
91 +       return np;
92 +}
93 +
94  void
95  pseudo_init_client(void) {
96         char *env;
97 @@ -329,6 +367,16 @@ pseudo_init_client(void) {
98                 }
99                 free(env);
100  
101 +               npasswd_paths = build_passwd_paths(NULL);
102 +               if (npasswd_paths) {
103 +                       passwd_paths = malloc(npasswd_paths * sizeof(*passwd_paths));
104 +                       if (!passwd_paths) {
105 +                               pseudo_diag("couldn't allocate space for passwd paths.\n");
106 +                               exit(1);
107 +                       }
108 +                       build_passwd_paths(passwd_paths);
109 +               }
110 +
111                 pseudo_inited = 1;
112         }
113         if (!pseudo_disabled)
114 -- 
115 1.8.5.5
116