Acked-by: Latchesar Ionkov <[EMAIL PROTECTED]>

On Nov 10, 2008, at 11:10 AM, Abhishek Kulkarni wrote:

1 file changed, 25 insertions(+), 9 deletions(-)
xcpufs/xcpufs.c |   34 +++++++++++++++++++++++++---------


# HG changeset patch
# User Abhishek Kulkarni <[EMAIL PROTECTED]>
# Date 1226340441 25200
# Node ID 2b4c0adacc655282c40f1ee3356dc00d68712b15
# Parent  16f112a860d446fcf705837be163b7ef943c4aaa
pwent now lists users and their associated groups too.
the format for a pwent entry is:

uname:uid:dfltgid:dfltgname,gname,gname

changed file permissions for ctl,pwent,grent files so that only users belonging to the "xcpu-admin" group can write to ctl
and/or read from pwent/grent

added new 'ctl' commands : user-add-group, user-del-group

also fixed a bug with xcpu-admin user not being added to the xcpu- admin group.

Signed-off-by: Abhishek Kulkarni <[EMAIL PROTECTED]>

diff --git a/xcpufs/xcpufs.c b/xcpufs/xcpufs.c
--- a/xcpufs/xcpufs.c
+++ b/xcpufs/xcpufs.c
@@ -945,14 +945,14 @@
        sp_group_incref(user->dfltgroup);

        create_file(root, "clone", 0444, Qclone, &clone_ops, NULL, NULL);
-       create_file(root, "ctl", 0664, Qctl, &ctl_ops, NULL, NULL);
+       create_file(root, "ctl", 0660, Qctl, &ctl_ops, NULL, NULL);
        create_file(root, "arch", 0444, Qarch, &fbuf_ops, NULL, &archbuf);
        create_file(root, "env", 0664, Qenv, &fbuf_ops, NULL, &envbuf);
        create_file(root, "procs", 0444, Qprocs, &procs_ops, NULL, NULL);
create_file(root, "state", 0664, Qstate, &state_ops, NULL, &statebuf);
        create_file(root, "passkey", 0444, Qpkey, &pkey_ops, NULL, NULL);
-       create_file(root, "pwent", 0444, Qpwent, &pwent_ops, NULL, NULL);
-       create_file(root, "grent", 0444, Qgrent, &grent_ops, NULL, NULL);
+       create_file(root, "pwent", 0440, Qpwent, &pwent_ops, NULL, NULL);
+       create_file(root, "grent", 0440, Qgrent, &grent_ops, NULL, NULL);
}

static Spfile*
@@ -1175,6 +1175,12 @@
                        ret = 1;
        } else if (strcmp("user-flush", cmd) == 0) {
                if (!ukey_flush(up))
+                       ret = 1;
+       } else if (strcmp("user-add-group", cmd) == 0) {
+               if (!ukey_add_group(up, args[0], args[1]))
+                       ret = 1;
+       } else if (strcmp("user-del-group", cmd) == 0) {
+               if (!ukey_del_group(up, args[0], args[1]))
                        ret = 1;
        } else if (strcmp("group-add", cmd) == 0) {
                if (nargs != 3) {
@@ -1975,7 +1981,7 @@
pwent_read(Spfilefid *fid, u64 offset, u32 count, u8 *data, Spreq *req)
{
        char *buf;
-       int ret, boff, blen;
+       int ret, boff, blen, i;
        Spuser *user;
        
        boff = 0;
@@ -1988,13 +1994,23 @@
        }

        for (; user != NULL; user = user->next) {
-               blen = strlen(user->uname) + 10*sizeof(char) +
-                       10*sizeof(char) + 4*sizeof(char);
+               blen = strlen(user->uname) + 12; /* uname:uid:gid */
+
+               for(i=0; i < user->ngroups; i++)
+                       blen += strlen(user->groups[i]->gname)+1;
+
+               blen += 2; /* \n\0 */
                buf = sp_malloc(blen);
                if (!buf)
                        return -1;
-               snprintf(buf, blen, "%s:%u:%u\n", user->uname, user->uid,
+               sprintf(buf, "%s:%u:%u", user->uname, user->uid,
                         user->dfltgroup->gid);
+
+               for(i=0; i < user->ngroups; i++) {
+                       strcat(buf, i?",":":");
+                       strcat(buf, user->groups[i]->gname);
+               }               
+               strcat(buf, "\n");
                blen = strlen(buf);
                ret =+ cutbuf(data, offset, count, buf, boff, blen);
                boff += blen;
@@ -2021,8 +2037,7 @@
        }               

        for (; group != NULL; group = group->next) {
-               blen = strlen(group->gname) + 10*sizeof(char) +
-                       + 3*sizeof(char);
+               blen = strlen(group->gname) + 8; /* gname:gid\n\0 */
                buf = sp_malloc(blen);
                if (!buf)
                        return -1;
@@ -2669,6 +2684,7 @@
        if (!admingroup)
                goto error;

+       sp_priv_group_adduser(admingroup, adminuser);
        sp_priv_user_setdfltgroup(adminuser, admingroup);

        fsinit();

Reply via email to