aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2014-01-22 16:20:35 -0600
committerPeter Seebach <peter.seebach@windriver.com>2014-01-22 16:22:46 -0600
commit97705dccbf9ed86698729faa0c82cbf2d28d6949 (patch)
tree69501defbc2369ce6fe91b8cd6bc9fd18680ea9a /pseudo_util.c
parent4759b592c3dc9a3386192d7d1ae5c3857850247e (diff)
downloadpseudo-97705dccbf9ed86698729faa0c82cbf2d28d6949.tar.gz
pseudo-97705dccbf9ed86698729faa0c82cbf2d28d6949.tar.bz2
pseudo-97705dccbf9ed86698729faa0c82cbf2d28d6949.zip
Don't automatically fall back to /etc/passwd.
In some cases, we'd rather pseudo fail than fall back to using /etc/passwd or /etc/group. Make the determination of what to fall back to when neither PSEUDO_PASSWD nor a chroot directory contains passwd/group files controllable by a configure-time flag, controlled by --with-passwd-fallback= or --without-passwd-fallback.
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c78
1 files changed, 39 insertions, 39 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index 0d80008..277b058 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -1245,53 +1245,53 @@ FILE *pseudo_host_etc_group_file = &pseudo_fake_group_file;
#endif
int
-pseudo_etc_file(const char *file, char *realname, int flags, char **search_dirs, int dircount) {
+pseudo_etc_file(const char *file, char *realname, int flags, char *search_dirs[], int dircount) {
char filename[pseudo_path_max()];
- int rc;
+ int rc = -1;
if (!file) {
- pseudo_diag("pseudo_etc_file: needs argument, usually passwd/group\n");
- return 0;
+ pseudo_debug(PDBGF_CHROOT, "pseudo_etc_file: needs argument, usually passwd/group\n");
+ errno = ENOENT;
+ return -1;
}
- if (search_dirs) {
- char *s;
- int i;
- for (i = 0; i < dircount; ++i) {
- s = search_dirs[i];
- if (!s)
- continue;
- snprintf(filename, pseudo_path_max(), "%s/etc/%s",
- s, file);
- rc = open(filename, flags, 0600);
- if (rc >= 0) {
- if (realname)
- strcpy(realname, filename);
- pseudo_debug(PDBGF_CHROOT, "using <%s> for <%s>\n",
- filename, file);
- return rc;
- } else {
- pseudo_debug(PDBGF_CHROOT, "didn't find <%s>\n",
- filename);
- }
- }
- } else {
+ int i;
+ if (!search_dirs || dircount == 0) {
pseudo_debug(PDBGF_CHROOT, "pseudo_etc_file: no search dirs.\n");
+ errno = ENOENT;
+ return -1;
}
+ for (i = 0; i < dircount; ++i) {
+ char *s = search_dirs[i];
+ if (!s)
+ continue;
#if PSEUDO_PORT_DARWIN
- if (!strcmp("passwd", file)) {
- pseudo_debug(PDBGF_CHROOT, "Darwin hackery: pseudo_etc_passwd returning magic passwd fd\n");
- return pseudo_host_etc_passwd_fd;
- } else if (!strcmp("group", file)) {
- pseudo_debug(PDBGF_CHROOT, "Darwin hackery: pseudo_etc_passwd returning magic group fd\n");
- return pseudo_host_etc_group_fd;
- }
+ /* special magic: empty string implies our emulation
+ * of the passwd/group files.
+ */
+ if (!*s) {
+ if (!strcmp("passwd", file)) {
+ pseudo_debug(PDBGF_CHROOT, "Darwin hackery: pseudo_etc_passwd returning magic passwd fd\n");
+ return pseudo_host_etc_passwd_fd;
+ } else if (!strcmp("group", file)) {
+ pseudo_debug(PDBGF_CHROOT, "Darwin hackery: pseudo_etc_passwd returning magic group fd\n");
+ return pseudo_host_etc_group_fd;
+ }
+ }
#endif
- snprintf(filename, pseudo_path_max(), "/etc/%s", file);
- pseudo_debug(PDBGF_CHROOT, "falling back on <%s> for <%s>\n",
- filename, file);
- rc = open(filename, flags, 0600);
- if (rc >= 0 && realname)
- strcpy(realname, filename);
+ snprintf(filename, pseudo_path_max(), "%s/etc/%s",
+ s, file);
+ rc = open(filename, flags, 0600);
+ if (rc >= 0) {
+ if (realname)
+ strcpy(realname, filename);
+ pseudo_debug(PDBGF_CHROOT, "pseudo_etc_file: using '%s' for '%s'.\n",
+ filename, file);
+ return rc;
+ } else {
+ pseudo_debug(PDBGF_CHROOT | PDBGF_VERBOSE, "didn't find <%s>\n",
+ filename);
+ }
+ }
return rc;
}