示例#1
0
/* SHOW MAXIDS */
void tool_get_maxids(int argc, char *argv[])
{
    PDB_HANDLE h;
    int maxuid, maxgid;
    if (check_args_num(argc, 1)) {
        printf("Usage: get_maxids\n");
    }
    h = PDB_db_open(O_RDONLY);
    PDB_db_maxids(h, &maxuid, &maxgid);
    PDB_db_close(h);
    printf("maxuid %d maxgid %d\n", maxuid, maxgid);
}
示例#2
0
文件: pdb.c 项目: chutzimir/coda
void PDB_createGroup(char *name, int32_t owner, int32_t *newGroupId)
{
	PDB_HANDLE h;
	int32_t maxId, minGroupId;
	PDB_profile r, p;
   
	/* sanity check arguments */
	CODA_ASSERT(name && (name[0] != '\0') && newGroupId
		    && PDB_ISUSER(owner));
   
	/* MAKE SURE NO GROUP WITH THAT NAME ALREADY EXISTS */
	CODA_ASSERT(PDB_nameInUse(name) == 0);

	h=PDB_db_open(O_RDWR);

	PDB_readProfile(h, owner, &p);
	CODA_ASSERT(p.id != 0);
	
	/* subtract one from the lowest group id -- that's new group's id */
	PDB_db_maxids(h, &maxId, &minGroupId);
	r.id = minGroupId - 1;
	*newGroupId = r.id;
	PDB_db_update_maxids(h, maxId, r.id, PDB_MAXID_SET);
   
   	/* CREATE A NEW GROUP WITH SPECIFIED NAME AND OWNER */
	
	/* create the new group's profile */
	r.name = strdup(name);
	r.owner_id = owner;
	r.owner_name = strdup(p.name);
	pdb_array_init(&(r.member_of));
	pdb_array_init(&(r.cps));
	pdb_array_add(&(r.cps),r.id);
	pdb_array_init(&(r.groups_or_members));
	pdb_array_add(&(r.groups_or_members),owner);
	/* write the new group's information to the databases */
	PDB_writeProfile(h, &r);
   
	/* add the new group's id to owner's groups_or_members list */
	pdb_array_add(&(p.groups_or_members), r.id);
	pdb_array_add(&(p.member_of), r.id);
	pdb_array_add(&(p.cps), r.id);
	PDB_writeProfile(h, &p);

	PDB_freeProfile(&r);
	PDB_freeProfile(&p);
	PDB_db_close(h);
}
示例#3
0
文件: pdb.c 项目: chutzimir/coda
void PDB_cloneUser(char *name, int32_t cloneid, int32_t *newId)
{
	PDB_HANDLE h;
	int32_t nextid, maxId, minGroupId;
	PDB_profile r, p;
	pdb_array_off off;

	/* sanity check arguments */
	CODA_ASSERT(name && (name[0] != '\0') && newId && (cloneid != 0));
   
	/* MAKE SURE NO USER WITH THAT NAME ALREADY EXISTS */
	CODA_ASSERT(PDB_nameInUse(name) == 0);

	h=PDB_db_open(O_RDWR);

	/* Read the profile we are cloning */
	PDB_readProfile(h, cloneid, &r);
	CODA_ASSERT(r.id != 0);
	
	/* add one to the highest user id -- that's our new user's id */
	PDB_db_maxids(h, &maxId, &minGroupId);
	r.id = maxId + 1;
	PDB_db_update_maxids(h, r.id, minGroupId, PDB_MAXID_SET);
   
	/* CREATE A NEW USER WITH SPECIFIED NAME, ALL OTHER FIELDS EMPTY */
   
	/* create the new user's profile */
	free(r.name);
	r.name = strdup(name);

	/* MAKE THE NEW USER A MEMBER OF THE SAME GROUPS AS THE OLD USER */
	nextid = pdb_array_head(&(r.member_of), &off);
	while(nextid != 0){
		PDB_readProfile(h, nextid, &p);
		CODA_ASSERT(r.id != 0);
		pdb_array_add(&(p.groups_or_members), r.id);
		PDB_writeProfile(h, &p);
		PDB_freeProfile(&p);
		nextid = pdb_array_next(&(r.member_of), &off);
	}
   
	/* updateCps also writes the new user's information to the databases */
	PDB_updateCps(h, &r);
	PDB_db_close(h);

	*newId = r.id;
	PDB_freeProfile(&r);
}
示例#4
0
文件: pdb.c 项目: chutzimir/coda
void PDB_createUser(char *name, int32_t *newId)
{
	PDB_HANDLE h;
	int32_t maxId, minGroupId;
	PDB_profile r;
   
	/* sanity check arguments */
	CODA_ASSERT(name && (name[0] != '\0') && newId);
   
	/* MAKE SURE NO USER WITH THAT NAME ALREADY EXISTS */
	CODA_ASSERT(PDB_nameInUse(name) == 0);

	h=PDB_db_open(O_RDWR);
	
	/* add one to the highest user id -- that's our new user's id */
	PDB_db_maxids(h, &maxId, &minGroupId);
	r.id = maxId + 1;
	PDB_db_update_maxids(h, r.id, minGroupId, PDB_MAXID_SET);
   
	/* CREATE A NEW USER WITH SPECIFIED NAME, ALL OTHER FIELDS EMPTY */
   
	/* create the new user's profile */
	r.name = strdup(name);
	r.owner_id = 0;
	r.owner_name = NULL;
	pdb_array_init(&(r.member_of));
	pdb_array_init(&(r.cps));
	pdb_array_add(&(r.cps),r.id);
	pdb_array_init(&(r.groups_or_members));
   
	/* write the new user's information to the databases */
	PDB_writeProfile(h, &r);
	PDB_db_close(h);

	*newId = r.id;
	PDB_freeProfile(&r);
}