Module Name:    src
Committed By:   pooka
Date:           Fri Nov 20 14:11:38 UTC 2009

Modified Files:
        src/lib/libp2k: p2k.c

Log Message:
Add "wizardmode", which allows to specify the uid which is used to
access the file system instead of using the caller uid.  This is
useful for example when modifying the root fs image for an OS
installation without wanting to dance around as root on the host.

idspispopd


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/lib/libp2k/p2k.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libp2k/p2k.c
diff -u src/lib/libp2k/p2k.c:1.27 src/lib/libp2k/p2k.c:1.28
--- src/lib/libp2k/p2k.c:1.27	Mon Oct 19 17:34:07 2009
+++ src/lib/libp2k/p2k.c	Fri Nov 20 14:11:38 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: p2k.c,v 1.27 2009/10/19 17:34:07 pooka Exp $	*/
+/*	$NetBSD: p2k.c,v 1.28 2009/11/20 14:11:38 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009  Antti Kantee.  All Rights Reserved.
@@ -93,6 +93,9 @@
 
 #define OPC2VP(opc) (((struct p2k_node *)opc)->p2n_vp)
 
+static int haswizard;
+static uid_t wizarduid;
+
 static kauth_cred_t
 cred_create(const struct puffs_cred *pcr)
 {
@@ -101,8 +104,12 @@
 	gid_t gid;
 	short ngroups = 0;
 
-	if (puffs_cred_getuid(pcr, &uid) == -1)
-		uid = 0;
+	if (haswizard) {
+		uid = wizarduid;
+	} else {
+		if (puffs_cred_getuid(pcr, &uid) == -1)
+			uid = 0;
+	}
 	if (puffs_cred_getgid(pcr, &gid) == -1)
 		gid = 0;
 	puffs_cred_getgroups(pcr, groups, &ngroups);
@@ -257,6 +264,7 @@
 {
 	struct puffs_ops *pops;
 	struct p2k_mount *p2m;
+	char *envbuf;
 	bool dodaemon;
 
 	PUFFSOP_INIT(pops);
@@ -313,6 +321,12 @@
 	if (getenv("P2K_NOCACHE") != NULL) {
 		puffs_flags |= PUFFS_KFLAG_NOCACHE;
 	}
+	if ((envbuf = getenv("P2K_WIZARDUID")) != NULL) {
+		/* default to 0 in error cases */
+		wizarduid = atoi(envbuf);
+		haswizard = 1;
+		printf("P2K WIZARD MODE: using uid %d\n", wizarduid);
+	}
 
 	p2m = allocp2m();
 	if (p2m == NULL)

Reply via email to