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 \t\tchange the Id of a user or group\n"); printf("cn \t\tchange the Name of a user or group\n"); + printf("co \t\tchange the owner of a group\n"); printf("u \t\t\tupdate an id/name\n"); printf("ids\t\t\t\tget the database maxids\n"); printf("maxids \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"},