/* * Call to get a page of memory at a location. */ vaddr_t mman_get_page(spdid_t spd, vaddr_t addr, int flags) { struct mem_cell *c; struct mapping_info *m; c = find_unused(); if (!c) { printc("mm: no more available pages!\n"); goto err; } c->naliases++; m = c->map; m->owner_spd = spd; m->addr = addr; m->parent = -1; /* Here we check for overwriting an already established mapping. */ if (cos_mmap_cntl(COS_MMAP_GRANT, 0, spd, addr, cell_index(c))) { printc("mm: could not grant page @ %x to spd %d\n", (unsigned int)addr, (unsigned int)spd); m->owner_spd = m->addr = 0; goto err; } return addr; err: return 0; }
/* * Call to get a page of memory at a location. */ vaddr_t mman_get_page(spdid_t spd, vaddr_t addr, int flags) { struct mem_cell *c; c = find_unused(); if (!c) { printc("mh: no more available pages!\n"); goto err; } c->map[0].owner_spd = spd; c->map[0].addr = addr; #ifdef ZERO_OUT memset(c->local_addr, 0, 4096); #endif if (!parent_mman_alias_page(cos_spd_id(), (vaddr_t)c->local_addr, spd, addr)) { printc("mh: could not grant page @ %x to spd %d\n", (unsigned int)addr, (unsigned int)spd); c->map[0].owner_spd = 0; c->map[0].addr = 0; goto err; } return addr; err: return 0; }
alpm_list_t SYMEXPORT *alpm_pkg_unused_deltas(pmpkg_t *pkg) { off_t pkgsize = alpm_pkg_get_size(pkg); alpm_list_t *unused = find_unused( alpm_pkg_get_deltas(pkg), alpm_pkg_get_filename(pkg), pkgsize * MAX_DELTA_RATIO); return unused; }
int buffer_share_add_id(struct buffer_share *mix, unsigned int id, void *data) { struct id_offset *o; o = find_id(mix, id); if (o) return -EEXIST; o = find_unused(mix); if (!o) alloc_more_ids(mix); o = find_unused(mix); o->used = 1; o->id = id; o->offset = 0; o->data = data; return 0; }
void main() { char foo[64]; char uname[9],person[32],passwd[9],dir[32],shell[32],salt[3]; unsigned int group,uid; int bad=0,i,correct=0; time_t tm; struct passwd *pw; FILE *passwd_file; /* Yep, it's a file allright */ unused_uid = FIRST; if (getuid()!=0) { printf("You don't have access to add a new user.\n"); printf("Only root can add new users to the system.\n"); exit(1); } if ((bull=fopen("/etc/shadow","r"))!=NULL) found_shadow(); if ((bull=fopen("/etc/passwd","r"))==NULL) { printf("Fatal error: password file not found.\n"); exit(1); } while (!correct) { /* loop until a "good" uname is chosen */ getlogin: printf("\nLogin to add (^C to quit): "); fflush(stdout); gets(uname); if (strlen(uname)>8) { printf("The login name must be maximum 8 characters long.\n"); goto getlogin; } for (i=0;i<strlen(uname);i++) { if (!(((uname[i]>='A') && (uname[i]<='Z')) || ((uname[i]>='a') && (uname[i]<='z')) || ((uname[i]>='0') && (uname[i]<='9')))) { printf("Invalid character in login.\n"); goto getlogin; } } if (nag=getpwnam(uname) != NULL) { printf("Login in use. Choose another one.\n"); goto getlogin; } putchar('\n'); unused_uid = find_unused(++unused_uid); printf("\nEditing information for new user [%s]:\n",uname); printf("\nFull name: "); fflush(stdout); gets(person); printf("GID [%d]: ",DEFAULT_GROUP); fflush(stdout); gets(foo); group=atoi(foo); if (group==0) group=DEFAULT_GROUP; printf("UID [%d]: ",unused_uid); fflush(stdout); gets(foo); uid=atoi(foo); if (uid==0) uid=unused_uid; if ((pw=getpwuid(uid))!=NULL) { printf("\nWarning: UID [%d] already in use, this would conflict with\n",uid); printf("who already owns this user ID. [%s]'s UID has been reset to\n",uname); printf("the last unused UID: [%d].\n",unused_uid); uid=unused_uid; } fflush(stdin); printf("Home Directory [%s/%s]: ",DEFAULT_HOME,uname); fflush(stdout); gets(dir); if (!strcmp(dir,"")) sprintf(dir,"%s/%s",DEFAULT_HOME,uname); fflush(stdin); printf("Shell [%s]: ",DEFAULT_SHELL); fflush(stdout); gets(shell); if (!strcmp(shell,"")) sprintf(shell,"%s",DEFAULT_SHELL); fflush(stdin); printf("Password [%s]: ",uname); fflush(stdout); gets(passwd); if (!strcmp(passwd,"")) sprintf(passwd,"%s",uname); time(&tm); salt[0]=(tm.t_time & 0x0f)+'A'; salt[1]=((tm.t_time & 0xf0) >> 4)+'a'; salt[2]=0; printf("\nInformation for new user [%s]:\n",uname); printf("Home directory: [%s]\nShell: [%s]\n",dir,shell); printf("Password: [%s]\nUID: [%d]\nGID: [%d]\n",passwd,uid,group); printf("\nIs this correct? [y/N]: "); fflush(stdout); fflush(stdin); gets(foo); bad=correct=(foo[0]=='y'||foo[0]=='Y'); if (bad!=1) printf("\nUser [%s] not added.\n",uname); } printf("\nAdding login [%s]...\n",uname); strcpy(foo,PASSWD_FILE); strcat(foo,".old"); if ((passwd_file=fopen(foo,"w")) == NULL) { printf("Error creating password backup file.\n"); exit(1); } setpwent(); for (i=0;(pw=getpwent())!=NULL;++i) { if (putpwent(pw,passwd_file)==-1) { printf("Error writing password backup file.\n"); exit(1); } } endpwent(); fclose(passwd_file); if (i<1) printf("Can't backup password file.\n"); passwd_file=fopen(PASSWD_FILE,"a"); fprintf(passwd_file,"%s:%s:%d:%d:%s:%s:%s\n" ,uname,crypt(passwd,salt),uid,group,person,dir,shell); fflush(passwd_file); fclose(passwd_file); printf("Making directory [%s]...\n",dir); mkdir(dir,DEFAULT_PERMS); chown(dir,uid,group); printf("Done.\n"); }