Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libp2k Add "wizardmode", which allows to specify the uid...



details:   https://anonhg.NetBSD.org/src/rev/963cf15d9580
branches:  trunk
changeset: 749173:963cf15d9580
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Nov 20 14:11:38 2009 +0000

description:
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

diffstat:

 lib/libp2k/p2k.c |  20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diffs (55 lines):

diff -r 67d85c06493e -r 963cf15d9580 lib/libp2k/p2k.c
--- a/lib/libp2k/p2k.c  Fri Nov 20 13:42:43 2009 +0000
+++ b/lib/libp2k/p2k.c  Fri Nov 20 14:11:38 2009 +0000
@@ -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)



Home | Main Index | Thread Index | Old Index