[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-coda
Subject:    Re: assert message
From:       Dan Gohman <gohmandj () mrs ! umn ! edu>
Date:       2000-10-09 21:48:58
[Download RAW message or body]

On Mon, Oct 09, 2000 at 03:26:41PM -0400, Jan Harkes wrote:
> On Mon, Oct 09, 2000 at 02:10:54PM -0500, Dan Gohman wrote:
> > venus was still running. Looking at the source, pdbtool
> > wants to remove the group from the owner's list, but this
> > is not possible as the owner no longer exists.
> 
> Ouch, if the owner is removed, who should become the owner the groups?
> Or should the removal of a group-owner be denied until he has no groups
> left. But there also is no way of changing the group owner to someone
> else.

I've written up code to change the owner of a group from pdbtool. With
it, I was able to take the change the group's owner and then remove the
group. Attatched is the patch (apply from within the coda-src dir). It
modifies only the pdbtool program, and I'm not yet familiar enough with
Coda to know if anything else would need to be changed to accept changing
group owners.

-Dan

-- 
Dan Gohman
gohmandj@mrs.umn.edu


diff -ur al.orig/pdb.c al/pdb.c
--- al.orig/pdb.c	Mon Oct  9 16:32:29 2000
+++ al/pdb.c	Mon Oct  9 16:05:51 2000
@@ -44,6 +44,30 @@
 #include "pdb.h"
 #include "prs.h"
 
+void PDB_changeOwner(int32_t id, int32_t groupId)
+{
+	PDB_HANDLE h;
+	PDB_profile r;
+	char *name;
+
+	/* sanity check arguments */
+	CODA_ASSERT(PDB_ISGROUP(groupId) && PDB_ISUSER(id));
+
+	h = PDB_db_open(O_RDWR);
+
+	/* change the owner of the group */
+	PDB_readProfile(h, groupId, &r);
+	CODA_ASSERT(r.id != 0);
+	r.owner_id = id;
+	free(r.owner_name);
+	PDB_lookupById(id, &name);
+	r.owner_name = name;
+	PDB_writeProfile(h, &r);
+	PDB_freeProfile(&r);
+
+	PDB_db_close(h);
+}
+
 void PDB_addToGroup(int32_t id, int32_t groupId)
 {
 	PDB_HANDLE h;
diff -ur al.orig/pdb.h al/pdb.h
--- al.orig/pdb.h	Mon Oct  9 16:32:29 2000
+++ al/pdb.h	Mon Oct  9 15:50:18 2000
@@ -69,6 +69,7 @@
 void PDB_lookupById(int32_t id, char **name);
 int PDB_nameInUse(char *name);
 void PDB_changeId(int32_t oldid, int32_t newid);
+void PDB_changeOwner(int32_t id, int32_t groupId);
 
 /* internal packing functions */
 void pdb_pack(PDB_profile *r, void **data, size_t *size);
diff -ur al.orig/pdbtool.c al/pdbtool.c
--- al.orig/pdbtool.c	Mon Oct  9 16:32:29 2000
+++ al/pdbtool.c	Mon Oct  9 16:30:21 2000
@@ -163,7 +163,7 @@
 }
 
 
-/* CREATE NEW USER */
+/* CHANGE A NAME */
 void tool_changeName(int argc,char *argv[]){
 	int32_t arg1;
 	if(check_args_num(argc,3)){
@@ -180,6 +180,39 @@
 }
 
 
+/* CHANGE THE OWNER OF A GROUP */
+void tool_changeOwner(int argc,char *argv[]){
+	char *s;
+	int32_t id;
+	int32_t groupId;
+	if(check_args_num(argc,3)){
+		printf("Usage: co user group\n"
+		       "user\t\tname or id of user to be the new owner\n"
+		       "group\t\tname or id of the group to change\n");
+		return;
+	}
+	id = get_id(argv[1]);
+	PDB_lookupById(id, &s);
+	if(!PDB_ISUSER(id) || s == NULL){
+		printf("Owner must be a valid username/id, %s not found!\n",
+		       argv[1]);
+		if (s) free(s);
+		return;
+	}
+	free(s);
+	groupId = get_id(argv[2]);
+	PDB_lookupById(groupId, &s);
+	if(!PDB_ISGROUP(groupId) || s == NULL){
+		printf("Group must be a valid groupname/id, %s not found!\n",
+		       argv[2]);
+		if (s) free(s);
+		return;
+	}
+	free(s);
+	PDB_changeOwner(id, groupId);
+}
+
+
 /* CREATE NEW GROUP */
 void tool_newGroup(int argc,char *argv[]){
 	char *s;
@@ -192,7 +225,7 @@
 		return;
 	}
 	arg2 = get_id(argv[2]);
-	PDB_lookupById((int32_t) arg2, &s);
+	PDB_lookupById(arg2, &s);
 	if(!PDB_ISUSER(arg2) || s == NULL){
 		printf("Owner must be a valid username/id, %s not found!\n",
 		       argv[2]);
@@ -722,6 +755,7 @@
 	printf("cm\t\t\t\tcompact the database (RARE)\n");
 	printf("ci <name> <newid>\t\tchange the Id of a user or group\n");
 	printf("cn <id> <newname>\t\tchange the Name of a user or group\n");
+	printf("co <id/name> <groupid/name>\t\tchange the owner of a group\n");
 	printf("u <id/name>\t\t\tupdate an id/name\n");
 	printf("ids\t\t\t\tget the database maxids\n");
 	printf("maxids <userid> <groupid>\tset the database maxids\n");
@@ -750,6 +784,7 @@
 	{"cm", tool_compact, 0, "compact the database (RARE)"},
 	{"ci", tool_changeId, 0, "change the Id of a user or group"},
 	{"cn", tool_changeName, 0, "change the Name of a user"},
+	{"co", tool_changeOwner, 0, "change the owner of a group"},
 	{"u", tool_update, 0, "update an id"},
 	{"ids", tool_get_maxids, 0, "get the database maxids"},
 	{"maxids", tool_maxids, 0, "set the database maxids"},


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic