Esempio n. 1
0
void *ds_hash_iter_next(ds_hash_iter_t *i)
{
    void *result = NULL;
    ds_hash_t *t;

    CODA_ASSERT(DS_HASH_ITER_VALID(i));

    if (i->curiter != NULL) {
        result = ds_list_iter_next(i->curiter);

        if (result == NULL) {
            t = i->table;
            CODA_ASSERT(DS_HASH_VALID(t));

            ds_list_iter_destroy(i->curiter);
            i->curiter = NULL;
            i->curbucket++;
            while (i->curbucket < t->nbuckets) {
                if (ds_list_count((t->buckets)[i->curbucket]) > 0) {
                    i->curiter =
                        ds_list_iter_create((t->buckets)[i->curbucket]);
                    result = ds_list_iter_next(i->curiter);
                    break;
                }
                i->curbucket++;
            }
        }
    }
    return result;
}
Esempio n. 2
0
File: pdb.c Progetto: chutzimir/coda
void PDB_removeFromGroup(int32_t id, int32_t groupId)
{
	PDB_HANDLE h;
	PDB_profile r;
   
	/* sanity check arguments (groupId must be < 0) */
	CODA_ASSERT(PDB_ISGROUP(groupId) && (id != 0));

	h = PDB_db_open(O_RDWR);

	/* remove id from the group's member list */
	PDB_readProfile(h, groupId, &r);
	CODA_ASSERT(r.id != 0);
	pdb_array_del(&(r.groups_or_members), id);
	PDB_writeProfile(h, &r);
	PDB_freeProfile(&r);
   
	/* remove groupId from user's member_of list */
	PDB_readProfile(h, id, &r);
	CODA_ASSERT(r.id != 0);
	pdb_array_del(&(r.member_of), groupId);
	PDB_updateCps(h, &r);
	PDB_freeProfile(&r);

	PDB_db_close(h);
}
Esempio n. 3
0
void
ds_list_iter_destroy(ds_list_iter_t *i) {
    ds_list_iter_t *trail;
    ds_list_iter_t *cur;
    ds_list_t      *l;
    
    CODA_ASSERT(DS_LIST_ITER_VALID(i));
    l = i->list;
    CODA_ASSERT(DS_LIST_VALID(l));

    trail = NULL;
    cur = l->iter_list;
    
    while (cur != NULL) {
	if (cur == i) break;
	trail = cur;
	cur = cur->next_iter;
    }

    CODA_ASSERT(cur != NULL);
    if (trail == NULL) 
	l->iter_list = cur->next_iter;
    else
	trail->next_iter = cur->next_iter;

    i->magic = 0;
    i->list = NULL;
    i->next_elt = NULL;
    i->next_iter = NULL;
    FREE(i);
}
Esempio n. 4
0
int
main(int argc, char **argv)
{
    struct DiskPartition *dp;
    Inode testcreate;
    Device devno;
    int fd, count;
    char *buff="This is a test string";
    Partent pe, pf;
    FILE *vtab;
    int rc;
    char host[256];

    /* write a vicetab file */
    hostname(host);

    /* set up a simple partition & ftree partition */
    /* they must be on different diskpartions */
    pe = Partent_create(host, "simpled", "simple","");
    pf = Partent_create(host, "/tmp/f", "ftree","width=8,depth=5");
    unlink("vicetab");
    rc = creat("vicetab", 00600);
    CODA_ASSERT( rc != -1 );
    vtab = Partent_set("vicetab", "r+");
    rc = Partent_add(vtab, pe);
    CODA_ASSERT( rc == 0 );
    rc = Partent_add(vtab, pf);
    CODA_ASSERT( rc == 0 );
    Partent_free(&pe);
    Partent_free(&pf);
    Partent_end(vtab);
    printf("Make sure to run makeftree vicetab /tmp/f before continuing!\n");
    return 0;
    
}
Esempio n. 5
0
void *
ds_list_last(ds_list_t *l) {
    CODA_ASSERT(DS_LIST_VALID(l));
    if (l->tail) {
	CODA_ASSERT(DS_LIST_ELT_VALID(l->tail));
	return l->tail->contents;
    } else {
	return NULL;
    }
}
Esempio n. 6
0
void *
ds_list_first(ds_list_t *l) {
    CODA_ASSERT(DS_LIST_VALID(l));
    if (l->head) {
	CODA_ASSERT(DS_LIST_ELT_VALID(l->head));
	return l->head->contents;
    } else {
	return NULL;
    }
}
Esempio n. 7
0
void *
ds_list_member(ds_list_t *l, void *e) {
    ds_list_elt_t *elt;

    CODA_ASSERT(DS_LIST_VALID(l));    
    CODA_ASSERT(e != NULL);
    elt = ds_list_find_member(l,e);
    if (elt)
	return elt->contents;
    else
	return NULL;
}
Esempio n. 8
0
void *
ds_list_append(ds_list_t *l, void *i) {
    ds_list_elt_t *result;

    CODA_ASSERT(DS_LIST_VALID(l));
    CODA_ASSERT(i != NULL);

    /* test for duplicates */
    if (!l->has_dups) 
	if (ds_list_find_member(l,i))
	    return NULL;

    result = ds_list_elt_create(i);

    /* Is the list empty? */
    if (l->head == NULL) {
	l->head = result;
	l->tail = result;
    } else {
	/* Is the list unsorted? */
	if (l->cmpfn == NULL) {
	    CODA_ASSERT(DS_LIST_ELT_VALID(l->tail));
	    result->p = l->tail;
	    l->tail->n = result;
	    l->tail = result;
	} else {
	    /* Walk backwards, checking for the insertion point */
	    ds_list_elt_t *cur = l->tail;
	    while (cur != NULL
		   && DS_LIST_ELT_VALID(cur)
		   && l->cmpfn(result->contents,cur->contents) < 0)
	    {
		cur = cur->p;
	    }
	    if (cur == NULL) { /* new element at beginning of list */
		result->n = l->head;
		l->head->p = result;
		l->head = result;
	    } else {
		CODA_ASSERT(DS_LIST_ELT_VALID(cur));
		result->p = cur;
		result->n = cur->n;
		result->p->n = result;
		if (result->n) 
		    result->n->p = result;
		else                          /* new element at end of list */
		    l->tail = result;
	    }
	}
    }
    l->count++;
    return i;
}
Esempio n. 9
0
/* Initializes the access list package. Version should always be AL_VERSION.
   
   This routine may be called many times -- it will perform reinitialization
   each time.  Synchronization code here guarantees that the .pdb and .pcf
   files are mutually consistent, provided all updaters follow the locking
   discipline.  */
int AL_Initialize(IN const char *Version)
{
	LogMsg(1,AL_DebugLevel,stdout,"AL_Initialize(%s)", Version);
	LogMsg(4,AL_DebugLevel,stdout,
	       "Library version: '%s'\tHeader version: '%s'\t",
	       AL_VERSION,Version);

	CODA_ASSERT(strcmp(Version, AL_VERSION) == 0);
	CODA_ASSERT(PDB_db_exists());

	return(0);
}
Esempio n. 10
0
File: pdb.c Progetto: chutzimir/coda
void PDB_deleteGroup(int32_t id)
{
	PDB_HANDLE h;
	PDB_profile r,p;
	int32_t nextid;
	pdb_array_off off;
	
	h=PDB_db_open(O_RDWR);
	PDB_readProfile(h, id, &r);
	if(r.id == 0){
		PDB_db_close(h);
		return;
	}
	PDB_deleteProfile(h, &r);

	/* remove from owner's list */
	PDB_readProfile(h, r.owner_id, &p);
	CODA_ASSERT(p.id != 0);
	pdb_array_del(&(p.groups_or_members), id);
	PDB_writeProfile(h, &p);
	PDB_freeProfile(&p);

	/* remove from groups if memberof */
	nextid = pdb_array_head(&(r.member_of), &off);
	while(nextid != 0){
		PDB_readProfile(h, nextid, &p);
		CODA_ASSERT(p.id == 0);
		pdb_array_del(&(p.groups_or_members), id);
		PDB_writeProfile(h, &p);
		PDB_freeProfile(&p);
		nextid = pdb_array_next(&(r.member_of), &off);
	}

	/* remove from members */
	nextid = pdb_array_head(&(r.groups_or_members), &off);
	while(nextid != 0){
		PDB_readProfile(h, nextid, &p);
		CODA_ASSERT(p.id != 0);
		pdb_array_del(&(p.member_of), id);
		PDB_updateCps(h, &p);
		PDB_freeProfile(&p);
		nextid = pdb_array_next(&(r.groups_or_members), &off);
	}

	/* Now fix the owner's cps */
	PDB_readProfile(h, r.owner_id, &p);
	CODA_ASSERT(p.id != 0);
	PDB_updateCps(h, &p);
	PDB_freeProfile(&p);

	PDB_freeProfile(&r);
	PDB_db_close(h);
}
Esempio n. 11
0
void InitPW(int firsttime)
{
    int fd, i;
    struct stat stbuf;
    char *fbuf;
    char *admin = PRS_ADMINGROUP;

    if (firsttime == PWFIRSTTIME) {
        memcpy(FileKey, DefKey, RPC2_KEYSIZE);

        /* moved from void main in auth2: */
        PWLen   = 100; /* length of PW array; this is an initial guess,
                          may increase below */
        PWArray = (RPC2_EncryptionKey *)malloc(PWLen * RPC2_KEYSIZE);
        CODA_ASSERT(PWArray != NULL);
    }
    /* now back to the old InitPW */

    /* Reads in contents of PWFile and builds a sorted list of passwords
       in PWArray.  Frees existing storage coor to PWArray.
     */
    if (PWFile == NULL)
        PWFile = strdup(vice_config_path("db/auth2.pw"));
    if ((fd = open(PWFile, O_RDONLY, 0)) < 0 ||
        myflock(fd, MYFLOCK_SH, MYFLOCK_BL) < 0 /* locking is superstitious */
        || fstat(fd, &stbuf)) {
        perror(PWFile);
        abort();
    }

    /* make sure the auth2.pw file is not world readable */
    if (stbuf.st_mode & 077)
        chmod(PWFile, 0600);

    CODA_ASSERT((fbuf = (char *)malloc(1 + stbuf.st_size)) != NULL);
    CODA_ASSERT(stbuf.st_size ==
                read(fd, fbuf, stbuf.st_size)); /* entirefile */

    PWTime = stbuf.st_mtime; /* time on file to check for changes */
    fbuf[stbuf.st_size] = 0; /* sentinel to stop sscanf() later */

    /* and unlock the file */
    myflock(fd, MYFLOCK_UN, MYFLOCK_BL);
    close(fd);

    CODA_ASSERT(AL_NameToId(admin, &AdminID) == 0);
    for (i = 0; i < RPC2_KEYSIZE; i++)
        DeleteKey[i] = 0xff;

    BuildPWArray(fbuf);
    free(fbuf);
}
Esempio n. 12
0
void
ds_list_destroy(ds_list_t *l) {
    CODA_ASSERT(DS_LIST_VALID(l));

    /* Either the list must be unsafe, or there must be nothing in it. */
    CODA_ASSERT(!(l->is_safe) || (l->count == 0));

    l->magic = 0;
    l->cmpfn = NULL;
    l->head = l->tail = NULL;
    l->count = 0;

    FREE(l);
}
Esempio n. 13
0
void ds_hash_print(ds_hash_t *t, void (*printer)(void *))
{
    int i;

    CODA_ASSERT(DS_HASH_VALID(t));
    CODA_ASSERT(printer != NULL);

    for (i = 0; i < t->nbuckets; i++) {
        if (DS_HASH_DEBUG) {
            fprintf(stderr, "**** bucket %d\n", i);
        }
        ds_list_print((t->buckets)[i], TRUE, printer);
    }
}
Esempio n. 14
0
static void BuildPWArray(char *fileBuf)
{
    /* fileBuf: pointer to in-core contents of PWFile parses the file buffer
     * and builds up PWArray; sets PWLen and PWCount */

    char *nextline, *kk;
    int thisid, i;
    RPC2_EncryptionKey thiskey;
    char holder[3];

    PWCount = 0; /* no of valid entries in PWArray */
    memset((char *)PWArray, 0, PWLen * RPC2_KEYSIZE);
    nextline = fileBuf; /* index into start of next line  in fbuf */

    while (TRUE) {
        if (strchr(nextline, '\t') == NULL)
            break;
        thisid = atoi(nextline);
        if (thisid < 0)
            goto nextline;
        CODA_ASSERT((kk = strchr(nextline, '\t')) != NULL);
        kk++;
        for (i = 0; i < RPC2_KEYSIZE; i++) {
            int x;
            holder[0] = *(kk++);
            holder[1] = *(kk++);
            holder[2] = '\0';
            CODA_ASSERT(1 == sscanf(holder, "%2x", &x));
            thiskey[i] = x;
        }

        if (AuthDebugLevel) {
            printf("%d\t", thisid);
            for (i = 0; i < RPC2_KEYSIZE; i++)
                printf("%02x", thiskey[i]);
            printf("\n");
            fflush(stdout);
        }

        if (thisid >= PWLen)
            EnlargePW(2 * thisid);
        /*factor of 2 to prevent frequent realloc() */

        memcpy(PWArray[thisid], thiskey, RPC2_KEYSIZE);
        PWCount++;
    nextline:
        CODA_ASSERT((nextline = strchr(nextline, '\n')) != NULL);
        nextline++; /* safe, since fileBuf is NULL-terminated */
    }
}
Esempio n. 15
0
File: pdb.c Progetto: 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);
}
Esempio n. 16
0
/* get boolean (starting with YyNn; loop forever */
int Parser_getbool(const char *prompt, int deft)
{
    int result = 0;
    char *line;
    int size = strlen(prompt) + 8;
    char *theprompt = malloc(size);
    CODA_ASSERT(theprompt);

    fflush(stdout);
    
    if ( deft != 0 && deft != 1 ) {
	fprintf(stderr, "Error: Parser_getbool given bad default (%d).\n",
		deft);
	CODA_ASSERT ( 0 );
    }
    sprintf(theprompt, "%s [%s]: ", prompt, (deft==0)? "N" : "Y");

    do {
	line = NULL;
	line = readline(theprompt);
	if ( line == NULL ) {
	    result = deft;
	    break;
	}
	if ( *line == '\0' ) {
	    result = deft;
	    break;
	}
	if ( *line == 'y' || *line == 'Y' ) {
	    result = 1;
	    break;
	}
	if ( *line == 'n' || *line == 'N' ) {
	    result = 0;
	    break;
	}
	if ( line ) 
	    free(line);
	fprintf(stdout, "Invalid string. Must start with yY or nN\n");
	fflush(stdout);
    } while ( 1 );

    if ( line ) 
	free(line);
    if ( theprompt ) 
	free(theprompt);
    return result;
}
Esempio n. 17
0
File: pdb.c Progetto: 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);
}
Esempio n. 18
0
void PDB_deleteProfile(PDB_HANDLE h, PDB_profile *r)
{
	/* sanity check arguments */
	CODA_ASSERT(r && h);

	PDB_db_delete(h, r->id, r->name);
}
Esempio n. 19
0
File: pdb.c Progetto: chutzimir/coda
void PDB_deleteUser(int32_t id)
{
	PDB_HANDLE h;
	PDB_profile r,p;
	int32_t nextid;
	pdb_array_off off;
	
	h=PDB_db_open(O_RDWR);
	PDB_readProfile(h, id, &r);
	if(r.id == 0){
		PDB_db_close(h);
		return;
	}
	PDB_deleteProfile(h, &r);

	/* Remove from groups */
	nextid = pdb_array_head(&(r.member_of), &off);
	while(nextid != 0){
		PDB_readProfile(h, nextid, &p);
		CODA_ASSERT(p.id != 0);
		pdb_array_del(&(p.groups_or_members), id);
		PDB_writeProfile(h, &p);
		PDB_freeProfile(&p);
		nextid = pdb_array_next(&(r.member_of), &off);
	}
	PDB_freeProfile(&r);
	PDB_db_close(h);
}
Esempio n. 20
0
File: fid.c Progetto: chutzimir/coda
void FID_VFid2DFid(const struct ViceFid *vf, DirFid *df)
{
	CODA_ASSERT( vf && df );
	df->Vnode = vf->Vnode;
	df->Unique = vf->Unique;

}
Esempio n. 21
0
char *Parser_getstr(const char *prompt, const char *deft, char *res, 
		    size_t len)
{
    char *line = NULL;
    int size = strlen(prompt) + strlen(deft) + 8;
    char *theprompt;
    theprompt = malloc(size);
    CODA_ASSERT(theprompt);

    sprintf(theprompt, "%s [%s]: ", prompt, deft);

    line  = readline(theprompt);
    free(theprompt);

    if ( line == NULL || *line == '\0' ) {
	strncpy(res, deft, len);
    } else {
	strncpy(res, line, len);
    }

    if ( line ) {
	free(line);
	return res;
    } else {
	return NULL;
    }
}
Esempio n. 22
0
static ds_list_elt_t *
ds_list_find_member(ds_list_t *l, void *e) {
    ds_list_elt_t *cur;
    bool           found = FALSE;

    /* calling functions must test validity of l */
    cur = l->head;

    while (!found && cur != NULL) {
	CODA_ASSERT(DS_LIST_ELT_VALID(cur));
	/* test is different for sorted, unsorted lists */
	if (l->cmpfn != NULL) {
	    if (l->cmpfn(e,cur->contents) == 0) {
		found = TRUE;
	    } else {
		cur = cur->n;
	    }
	} else {
	    if (e == cur->contents) {
		found = TRUE;
	    } else {
		cur = cur->n;
	    }
	}
    }
    return cur;
}
Esempio n. 23
0
void *
ds_list_iter_next(ds_list_iter_t *i) {
    ds_list_t      *l;
    void           *result = NULL;

    CODA_ASSERT(DS_LIST_ITER_VALID(i));
    l = i->list;
    CODA_ASSERT(DS_LIST_VALID(l));

    if (i->next_elt) {
	CODA_ASSERT(DS_LIST_ELT_VALID(i->next_elt));
	result = i->next_elt->contents;
	i->next_elt = i->next_elt->n;
    }
    
    return result;
}
Esempio n. 24
0
File: fid.c Progetto: chutzimir/coda
void FID_Int2DFid(DirFid *fid, const int vnode, const int unique)
{
	CODA_ASSERT(fid);

	fid->Vnode = vnode;
	fid->Unique = unique;
	return;
}
Esempio n. 25
0
static
void
ds_list_elt_destroy(ds_list_elt_t *e) {
    CODA_ASSERT(DS_LIST_ELT_VALID(e));
    e->p = e->n = NULL;
    e->contents = NULL;
    e->magic = 0;
    FREE(e);
}
Esempio n. 26
0
void *ds_hash_member(ds_hash_t *t, void *e)
{
    int bucket;
    ds_list_t *chain;

    CODA_ASSERT(DS_HASH_VALID(t));
    bucket = (t->hfn(e)) % t->nbuckets;
    chain  = (t->buckets)[bucket];
    return (ds_list_member(chain, e));
}
Esempio n. 27
0
void ds_hash_iter_destroy(ds_hash_iter_t *i)
{
    CODA_ASSERT(DS_HASH_ITER_VALID(i));
    if (i->curiter)
        ds_list_iter_destroy(i->curiter);
    i->magic     = 0;
    i->table     = NULL;
    i->curbucket = 0;
    i->curiter   = NULL;
    FREE(i->curiter);
}
Esempio n. 28
0
static void
ds_list_advance_iters(ds_list_elt_t *dropping, 
		      ds_list_iter_t *iter) {
    
    while (iter != NULL) {
	CODA_ASSERT(DS_LIST_ITER_VALID(iter));
	if (iter->next_elt == dropping) 
	    iter->next_elt = iter->next_elt->n;
	iter = iter->next_iter;
    }
}
Esempio n. 29
0
void PDB_readProfile_byname(PDB_HANDLE h, const char *name, PDB_profile *r)
{
	void  *data;
	size_t size;

	/* sanity check arguments */
	CODA_ASSERT(r && h);

	PDB_db_read(h, 0, name, &data, &size);
	
	pdb_unpack(r, data, size);
}
Esempio n. 30
0
void
ds_list_print(ds_list_t *l, bool forward, void (*printer)(void *)) {
    ds_list_elt_t *cur;

    CODA_ASSERT(DS_LIST_VALID(l));
    CODA_ASSERT(printer != NULL);

    if (forward) {
	cur = l->head;
	while (cur != NULL) {
	    printer(cur->contents);
	    cur = cur->n;
	}
    } else {
	cur = l->tail;
	while (cur != NULL) {
	    printer(cur->contents);
	    cur = cur->p;
	}
    }
}