aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo_util.c
diff options
context:
space:
mode:
authorPeter Seebach <seebs@eee12.(none)>2010-03-29 17:58:46 -0500
committerPeter Seebach <seebs@eee12.(none)>2010-03-29 17:58:46 -0500
commitfa580977cc4fa8b58a47c483c1a59df66645a120 (patch)
tree42e77c1592e7fa56af0df2d2b86f398a24e119ee /pseudo_util.c
parent2b57c61b7eeb203cfcda848cc93113ec39a639cc (diff)
downloadpseudo-fa580977cc4fa8b58a47c483c1a59df66645a120.tar.gz
pseudo-fa580977cc4fa8b58a47c483c1a59df66645a120.tar.bz2
pseudo-fa580977cc4fa8b58a47c483c1a59df66645a120.zip
Add password/group call emulation.
This is a first pass at handling password/group calls, allowing the use of custom password/group files. In particular, when chroot()ed to a particular directory, pseudo picks files in that directory by default, to improve support for the typical use case where pseudo uses chroot() only to jump into a virtual target filesystem.
Diffstat (limited to 'pseudo_util.c')
-rw-r--r--pseudo_util.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index bb60edb..8af3020 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -614,3 +614,47 @@ pseudo_access_fopen(const char *mode) {
}
return access;
}
+
+/* find a passwd/group file to use
+ * uses in order:
+ * - PSEUDO_CHROOT/etc/<file> (only if CHROOT is set)
+ * - PSEUDO_PASSWD/etc/<file>
+ * - /etc/<file>
+ */
+
+int
+pseudo_etc_file(char *file, char **search_dirs, int dircount) {
+ char filename[pseudo_path_max()];
+ int rc;
+
+ if (!file) {
+ pseudo_diag("pseudo_etc_file: needs argument, usually passwd/group\n");
+ return 0;
+ }
+ 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, O_RDONLY);
+ if (rc >= 0) {
+ pseudo_debug(2, "using <%s> for <%s>\n",
+ filename, file);
+ return rc;
+ } else {
+ pseudo_debug(3, "didn't find <%s>\n",
+ filename);
+ }
+ }
+ } else {
+ pseudo_debug(2, "pseudo_etc_file: no search dirs.\n");
+ }
+ snprintf(filename, pseudo_path_max(), "/etc/%s", file);
+ pseudo_debug(2, "falling back on <%s> for <%s>\n",
+ filename, file);
+ return open(filename, O_RDONLY);
+}