int user_db_init (void) { if (create_user ((char *)"guest", (char *)"guest", 5) < 0) { cli_printf ("Default User \"guest\" creation failed\n"); return -1; } if (create_user ((char *)"linux", (char *)"linux", 0) < 0) { cli_printf ("Default User \"linux\" creation failed\n"); return -1; } return 0; }
/* * cmd_newu() - create a new user account and log in as that user */ void cmd_newu(char *cmdbuf) { int a; long len; char username[SIZ]; if (CtdlGetConfigInt("c_auth_mode") != AUTHMODE_NATIVE) { cprintf("%d This system does not use native mode authentication.\n", ERROR + NOT_HERE); return; } if (CtdlGetConfigInt("c_disable_newu")) { cprintf("%d Self-service user account creation " "is disabled on this system.\n", ERROR + NOT_HERE); return; } if (CC->logged_in) { cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN); return; } if (CC->nologin) { cprintf("%d %s: Too many users are already online (maximum is %d)\n", ERROR + MAX_SESSIONS_EXCEEDED, CtdlGetConfigStr("c_nodename"), CtdlGetConfigInt("c_maxsessions")); return; } extract_token(username, cmdbuf, 0, '|', sizeof username); strproc(username); len = cutuserkey(username); if (IsEmptyStr(username)) { cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED); return; } if ((!strcasecmp(username, "bbs")) || (!strcasecmp(username, "new")) || (!strcasecmp(username, "."))) { cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username); return; } a = create_user(username, len, 1); if (a == 0) { logged_in_response(); } else if (a == ERROR + ALREADY_EXISTS) { cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username); return; } else if (a == ERROR + INTERNAL_ERROR) { cprintf("%d Internal error - user record disappeared?\n", ERROR + INTERNAL_ERROR); return; } else { cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR); } }
user *retrieve_graph_user(const char *access_token) { int id; const char *name; char *url = create_url("https://graph.facebook.com/me?fields=name&access_token=", access_token); json_object *jobj; json_object *name_obj; json_object *id_obj; user *u; jobj = http_get_request_json(url); json_object_object_get_ex(jobj, "name", &name_obj); json_object_object_get_ex(jobj, "id", &id_obj); name = json_object_get_string(name_obj); id = (unsigned long) atoi(json_object_get_string(id_obj)); user *me = create_user(id, name); json_object_put(jobj); free(url); return me; }
int main() { int do_what; int power; while (1) { printf("Please choose what to do:\n1--------->create a new user\n2--------->start server\n3--------->input command\n4--------->exit\n"); scanf("%d",&do_what); switch (do_what) { case 1: create_user(); break; case 2: init(); int listenfd; power = interaction(listen_port,&listenfd); s_get_client(power,listenfd); break; case 3: get_command(); break; case 4: exit(0); } } }
int main(void){ pci_init(); #ifdef ENABLE_FASTCGI while(FCGI_Accept() >= 0) { #endif qentry_t *req = qcgireq_parse(NULL, 0); char *name = req->getstr(req, "username", true); if(name == NULL){ qcgires_redirect(req, BAD_REGISTER); goto end; } char *admin = req->getstr(req, "adminpassword", true); if(admin == NULL){ qcgires_redirect(req, BAD_REGISTER); free(name); goto end; } if(strncmp(admin, ADMIN_SECRET, strlen(ADMIN_SECRET)) != 0){ fprintf(stderr, "%s%s\n", "Invalid Registration Attempt: ", admin); qcgires_redirect(req, BAD_REGISTER); free(name); free(admin); goto end; } if( create_user(name) == 1 ){ /* Log the User in */ qentry_t *sess = NULL; sess = qcgisess_init(req, NULL); qcgisess_settimeout(sess, SESSION_TIME); if(sess){ sess->putstr(sess, "username", name, true); qcgisess_save(sess); sess->free(sess); } qcgires_redirect(req, APPLICATION); }else{ fprintf(stderr, "%s%s\n", "Could not create user: "******"text/html"); // De-allocate memories req->free(req); #ifdef ENABLE_FASTCGI } #endif return 0; }
void send_icqpage(UR_OBJECT user, char *inpstr) { char fname[FNAME_LEN], icqnum[ICQ_LEN+1], subj[100], addr[100]; int on; UR_OBJECT ur; FILE *fp; if (word_count<3) { write_usage(user, "%s <user>/<ICQ#> <text>", command_table[ICQPAGE].name); return; } icqnum[0]='\0'; if (is_number(word[1])) strncpy(icqnum, word[1], ICQ_LEN); else { if (!(ur=get_user_name(user, word[1]))) { if (!(ur=create_user())) { vwrite_user(user, "%s: nemozem vytvorit docasny user objekt.\n", syserror); write_syslog(ERRLOG, 1, "Unable to create temp user object in send_icqpage()\n"); return; } strcpy(ur->name, word[1]); if (!load_user_details(ur)) { write_user(user, nosuchuser); destruct_user(ur); destructed=0; return; } on=0; } else on=1; strcpy(icqnum, ur->icq); if (!on) { destruct_user(ur); destructed=0; } } if (icqnum[0]=='\0') { write_user(user, "sprava neposlana, chybne alebo nezistitelne ICQ cislo\n"); return; } sprintf(fname, "%s/%s.icq", TEMPFILES, user->name); if (!(fp=fopen(fname, "w"))) { write_user(user, "nemozem vytvorit docasny subor pre spravu\n"); write_syslog(ERRLOG, 1, "unable to open file in send_icqpage()\n"); return; } fprintf(fp, icq_page_email); fprintf(fp, "%s\n", remove_first(inpstr)); fclose(fp); sprintf(addr, "*****@*****.**", icqnum); sprintf(subj, "ICQ page from %s", user->name); send_email(addr, subj, fname); write_user(user, "sprava bola odoslana\n"); }
int main(void){ int fd; init_users(); numberOfUsers=51; printf("%d\n",create_user(5,"HELLBOY")); fd=open_log(21,WRITE); write_log(fd,"Hello guys"); close_log(fd); fd=open_log(21,READ); read_log(fd); close_log(fd); return 0; }
void task_manager::user_init_thread( ) { create_user( ); for(;;) { bool release = false; Sleep( 1000 ); init_lock.Enter(); release = _release; init_lock.Leave(); if( release ) break; } release_user(); }
/* * cmd_creu() - administratively create a new user account (do not log in to it) */ void cmd_creu(char *cmdbuf) { int a; long len; char username[SIZ]; char password[SIZ]; struct ctdluser tmp; if (CtdlAccessCheck(ac_aide)) { return; } extract_token(username, cmdbuf, 0, '|', sizeof username); strproc(username); strproc(password); if (IsEmptyStr(username)) { cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED); return; } len = cutuserkey(username); extract_token(password, cmdbuf, 1, '|', sizeof password); a = create_user(username, len, 0); if (a == 0) { if (!IsEmptyStr(password)) { CtdlGetUserLock(&tmp, username); safestrncpy(tmp.password, password, sizeof(tmp.password)); CtdlPutUserLock(&tmp); } cprintf("%d User '%s' created %s.\n", CIT_OK, username, (!IsEmptyStr(password)) ? "and password set" : "with no password"); return; } else if (a == ERROR + ALREADY_EXISTS) { cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username); return; } else if ( (CtdlGetConfigInt("c_auth_mode") != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) { cprintf("%d User accounts are not created within Citadel in host authentication mode.\n", ERROR + NO_SUCH_USER); return; } else { cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR); } }
static void handle_create_new_game (DskHttpServerRequest *request) { DskCgiVariable *game_var = dsk_http_server_request_lookup_cgi (request, "game"); DskCgiVariable *user_var = dsk_http_server_request_lookup_cgi (request, "user"); char buf[512]; Game *game; User *user; DskJsonValue *state_json; unsigned width, height; if (game_var == NULL) { dsk_http_server_request_respond_error (request, DSK_HTTP_STATUS_BAD_REQUEST, "missing game="); return; } if (user_var == NULL) { dsk_http_server_request_respond_error (request, DSK_HTTP_STATUS_BAD_REQUEST, "missing user="******"game %s already exists", game_var->value); dsk_http_server_request_respond_error (request, DSK_HTTP_STATUS_BAD_REQUEST, buf); return; } user = find_user (user_var->value); if (user != NULL) { snprintf (buf, sizeof (buf), "user %s already found in %s", user->name, user->base.game->name); dsk_http_server_request_respond_error (request, DSK_HTTP_STATUS_BAD_REQUEST, buf); return; } game = create_game (game_var->value, DEFAULT_UNIVERSE_WIDTH, DEFAULT_UNIVERSE_HEIGHT); width = 700; height = 400; user = create_user (game, user_var->value, width, height); state_json = create_user_update (user); respond_take_json (request, state_json); }
/*** Get all users from the user directories and add them to the user lists. If verbose mode is on, then attempt to get date string as well ***/ void process_users(void) { char name[USER_NAME_LEN+3]; DIR *dirp; struct dirent *dp; UR_OBJECT u; set_crash(); /* open the directory file up */ dirp=opendir(USERFILES); if (dirp==NULL) { fprintf(stderr,"Lotos: Directory open failure in process_users().\n"); boot_exit(12); } if ((u=create_user())==NULL) { fprintf(stderr,"Lotos: Create user failure in process_users().\n"); (void) closedir(dirp); boot_exit(17); } /* count up how many files in the directory - this include . and .. */ while((dp=readdir(dirp))!=NULL) { if (!strcmp(dp->d_name,".") || !strcmp(dp->d_name,"..")) continue; if (strstr(dp->d_name,".D")) { strcpy(name,dp->d_name); name[strlen(name)-2]='\0'; strcpy(u->name,name); if (load_user_details(u)) { add_user_node(u->name,u->level); if (u->level>=WIZ) add_wiz_node(u->name,u->level); add_user_date_node(u->name,u->date); } /* end if */ else { fprintf(stderr,"Lotos: Could not load userfile for '%s' in process_users().\n",name); (void) closedir(dirp); boot_exit(18); } } /* end if */ reset_user(u); } /* end while */ destruct_user(u); closedir(dirp); }
void com_nick_grm(UR_OBJECT user) { UR_OBJECT u; int on; set_crash(); if ((word_count<2) || (user->level<GOD)) { u=user; on=1; } else { if (!(u=get_user(word[1]))) { if ((u=create_user())==NULL) { vwrite_user(user,"%s: nemozem vytvorit docasny user objekt.\n",syserror); write_syslog(ERRLOG,1,"Unable to create temporary user object in examine().\n"); return; } strcpy(u->name,word[1]); if (!load_user_details(u)) { write_user(user,nosuchuser); destruct_user(u); destructed=0; return; } on=0; } else on=1; } vwrite_user(user, "2. p - G: %s\n", u->nameg); vwrite_user(user, "3. p - D: %s\n", u->named); vwrite_user(user, "4. p - A: %s\n", u->namea); vwrite_user(user, "6. p - L: %s\n", u->namel); vwrite_user(user, "7. p - I: %s\n", u->namei); vwrite_user(user, "privl. pre muzsky rod : %s\n", u->namex); vwrite_user(user, "privl. pre zensky rod : %s\n", u->namey); vwrite_user(user, "privl. pre stredny rod: %s\n", u->namez); if (!on) { destruct_user(u); destructed=0; } return; }
/* * Envoi de la liste des joueurs en broadcast * @param the_players Liste des joueurs */ void send_user(Players the_players) { size_t i = 0; Frame user_frame; Player current_player; /* Envoi a tous les clients de la trame User * qui decrit chaque joueur connecte */ for(i=0; i < the_players->size; i++) { current_player = the_players->player[i]; if(current_player->is_connected) { user_frame = create_user(current_player); send_broadcast(the_players, user_frame); } } /* Fin de la liste de joueurs */ send_end(the_players); }
/* * Attempt to auto-create a new Citadel account using the nickname from Attribute Exchange */ int openid_create_user_via_ax(StrBuf *claimed_id, HashList *sreg_keys) { char *nickname = NULL; char *firstname = NULL; char *lastname = NULL; char new_password[32]; long len; const char *Key; void *Value; if (CtdlGetConfigInt("c_auth_mode") != AUTHMODE_NATIVE) return(1); if (CtdlGetConfigInt("c_disable_newu")) return(2); if (CC->logged_in) return(3); HashPos *HashPos = GetNewHashPos(sreg_keys, 0); while (GetNextHashPos(sreg_keys, HashPos, &len, &Key, &Value) != 0) { syslog(LOG_DEBUG, "%s = %s", Key, (char *)Value); if (cbmstrcasestr(Key, "value.nickname") != NULL) { nickname = (char *)Value; } else if ( (nickname == NULL) && (cbmstrcasestr(Key, "value.nickname") != NULL)) { nickname = (char *)Value; } else if (cbmstrcasestr(Key, "value.firstname") != NULL) { firstname = (char *)Value; } else if (cbmstrcasestr(Key, "value.lastname") != NULL) { lastname = (char *)Value; } } DeleteHashPos(&HashPos); if (nickname == NULL) { if ((firstname != NULL) || (lastname != NULL)) { char fullname[1024] = ""; if (firstname) strcpy(fullname, firstname); if (firstname && lastname) strcat(fullname, " "); if (lastname) strcat(fullname, lastname); nickname = fullname; } } if (nickname == NULL) { return(4); } syslog(LOG_DEBUG, "The desired account name is <%s>", nickname); len = cutuserkey(nickname); if (!CtdlGetUser(&CC->user, nickname)) { syslog(LOG_DEBUG, "<%s> is already taken by another user.", nickname); memset(&CC->user, 0, sizeof(struct ctdluser)); return(5); } /* The desired account name is available. Create the account and log it in! */ if (create_user(nickname, len, 1)) return(6); /* Generate a random password. * The user doesn't care what the password is since he is using OpenID. */ snprintf(new_password, sizeof new_password, "%08lx%08lx", random(), random()); CtdlSetPassword(new_password); /* Now attach the verified OpenID to this account. */ attach_openid(&CC->user, claimed_id); return(0); }
Game* create_game(GtkWidget* widget, GdkPixmap* pixmap) { Game* game = (Game*)malloc(sizeof(Game)); game->board = create_board(); game->red = create_user(red); game->black = create_user(black); //create all chessman int index = 0; int i = 0; //create the red soldiers for(i=0; i<5; i++) { game->man[index] = create_chessman(red, soldier, index, game->board, game->red, red_soldier_image,3, i*2); index ++; } //create the red cannons for(i = 0; i < 2; i ++) { game->man[index] = create_chessman(red, cannon, index, game->board, game->red, red_cannon_image,2, 6*i + 1); index ++; } //create the red tanks for(i = 0; i < 2; i ++) { game->man[index] = create_chessman(red, tank, index, game->board, game->red, red_tank_image,0, 8*i); index ++; } //create the red horses for(i = 0; i < 2; i ++) { game->man[index] = create_chessman(red, horse, index, game->board, game->red, red_horse_image, 0, 6*i +1); index ++; } //create the red chancellors for(i = 0; i < 2; i ++) { game->man[index] = create_chessman(red, chancellor, index, game->board, game->red, red_chancellor_image, 0, 4*i +2); index ++; } //create the red scholars for(i = 0; i < 2; i ++) { game->man[index] = create_chessman(red, scholar, index, game->board, game->red, red_scholar_image, 0, 2*i +3); index ++; } game->man[index] = create_chessman(red, general, index, game->board, game->red, red_general_image, 0, 4); index ++; //create the black soldiers for(i=0; i<5; i++) { game->man[index] = create_chessman(black, soldier, index, game->board, game->black, black_soldier_image, 6, i*2); index ++; } //create the black cannons for(i = 0; i < 2; i ++) { game->man[index] = create_chessman(black, cannon, index, game->board, game->black, black_cannon_image, 7, 6*i + 1); index ++; } //create the black tanks for(i = 0; i < 2; i ++) { game->man[index] = create_chessman(black, tank, index, game->board, game->black, black_tank_image, 9, 8*i); index ++; } //create the black horses for(i = 0; i < 2; i ++) { game->man[index] = create_chessman(black, horse, index, game->board, game->black, black_horse_image, 9, 6*i +1); index ++; } //create the black chancellors for(i = 0; i < 2; i ++) { game->man[index] = create_chessman(black, chancellor, index, game->board, game->black, black_chancellor_image, 9, 4*i +2); index ++; } //create the black scholars for(i = 0; i < 2; i ++) { game->man[index] = create_chessman(black, scholar, index, game->board, game->black, black_scholar_image, 9, 2*i +3); index ++; } game->man[index] = create_chessman(black, general, index, game->board, game->black, black_general_image, 9, 4); index ++; game->current_user = game->red; game->current_man = NULL; game->level = 0; game->mode = 0; draw_game(game, pixmap); gtk_widget_draw(widget, NULL); return game; }
/** * Telnet register interface. */ void new_register(void) { char userid[IDLEN + 1], passwd[PASSLEN], passbuf[PASSLEN], log[STRLEN]; const char *errmsg; if (register_closed()) { ansimore("NOREGISTER", NA); pressreturn(); return; } ansimore("etc/register", NA); #ifndef FDQUAN //% if (!askyn("您是否同意本站Announce版精华区x-3目录所列站规?", false, false)) if (!askyn("\xc4\xfa\xca\xc7\xb7\xf1\xcd\xac\xd2\xe2\xb1\xbe\xd5\xbe""Announce\xb0\xe6\xbe\xab\xbb\xaa\xc7\xf8x-3\xc4\xbf\xc2\xbc\xcb\xf9\xc1\xd0\xd5\xbe\xb9\xe6?", false, false)) return; #endif int tried = 0; prints("\n"); while (1) { if (++tried >= MAX_NEW_TRIES) { //% outs("\n拜拜,按太多下 <Enter> 了...\n"); outs("\n\xb0\xdd\xb0\xdd\xa3\xac\xb0\xb4\xcc\xab\xb6\xe0\xcf\xc2 <Enter> \xc1\xcb...\n"); screen_flush(); return; } //% getdata(0, 0, "请输入帐号名称 (Enter User ID, \"0\" to abort): ", getdata(0, 0, "\xc7\xeb\xca\xe4\xc8\xeb\xd5\xca\xba\xc5\xc3\xfb\xb3\xc6 (Enter User ID, \"0\" to abort): ", userid, sizeof(userid), DOECHO, YEA); if (userid[0] == '0') return; errmsg = register_invalid_user_name(userid); if (errmsg != NULL) { outs(errmsg); continue; } char path[HOMELEN]; sethomepath(path, userid); if (dosearchuser(userid, ¤tuser, &usernum) || dashd(path)) { //% outs("此帐号已经有人使用\n"); outs("\xb4\xcb\xd5\xca\xba\xc5\xd2\xd1\xbe\xad\xd3\xd0\xc8\xcb\xca\xb9\xd3\xc3\n"); continue; } #ifndef REG_CAPTCHA break; #else char link[STRLEN], attempt[CAPTCHA_LEN + 1], answer[CAPTCHA_LEN + 1]; int lnum; int pos = gen_captcha_link(link, sizeof(link), &lnum); if (pos < 0) return; prints("http://"BBSHOST"/captcha/%d.gif\n", lnum); //% getdata(0, 0, "请输入上图所包含的英文字母: ", attempt, sizeof(attempt), getdata(0, 0, "\xc7\xeb\xca\xe4\xc8\xeb\xc9\xcf\xcd\xbc\xcb\xf9\xb0\xfc\xba\xac\xb5\xc4\xd3\xa2\xce\xc4\xd7\xd6\xc4\xb8: ", attempt, sizeof(attempt), DOECHO, YEA); unlink(link); get_captcha_answer(pos, answer, sizeof(answer)); if (strcasecmp(answer, attempt) != 0) { //% outs("验证码输入错误...\n"); outs("\xd1\xe9\xd6\xa4\xc2\xeb\xca\xe4\xc8\xeb\xb4\xed\xce\xf3...\n"); continue; } else { break; } #endif // REG_CAPTCHA } for (tried = 0; tried <= MAX_SET_PASSWD_TRIES; ++tried) { passbuf[0] = '\0'; //% getdata(0, 0, "请设定您的密码 (Setup Password): ", passbuf, getdata(0, 0, "\xc7\xeb\xc9\xe8\xb6\xa8\xc4\xfa\xb5\xc4\xc3\xdc\xc2\xeb (Setup Password): ", passbuf, sizeof(passbuf), NOECHO, YEA); errmsg = register_invalid_password(passbuf, userid); if (errmsg) { outs(errmsg); continue; } strlcpy(passwd, passbuf, PASSLEN); //% getdata(0, 0, "请再输入一次您的密码 (Confirm Password): ", passbuf, getdata(0, 0, "\xc7\xeb\xd4\xd9\xca\xe4\xc8\xeb\xd2\xbb\xb4\xce\xc4\xfa\xb5\xc4\xc3\xdc\xc2\xeb (Confirm Password): ", passbuf, PASSLEN, NOECHO, YEA); if (strncmp(passbuf, passwd, PASSLEN) != 0) { //% prints("密码输入错误, 请重新输入密码\n"); prints("\xc3\xdc\xc2\xeb\xca\xe4\xc8\xeb\xb4\xed\xce\xf3, \xc7\xeb\xd6\xd8\xd0\xc2\xca\xe4\xc8\xeb\xc3\xdc\xc2\xeb\n"); continue; } passwd[8] = '\0'; break; } if (tried > MAX_SET_PASSWD_TRIES) return; struct userec user; init_userec(&user, userid, passwd, true); strlcpy(user.lasthost, fromhost, sizeof(user.lasthost)); if (create_user(&user) < 0) { outs("Failed to create user.\n"); return; } snprintf(log, sizeof(log), "new account from %s", fromhost); report(log, currentuser.userid); //% prints("请重新登录 %s 并填写注册信息\n", user.userid); prints("\xc7\xeb\xd6\xd8\xd0\xc2\xb5\xc7\xc2\xbc %s \xb2\xa2\xcc\xee\xd0\xb4\xd7\xa2\xb2\xe1\xd0\xc5\xcf\xa2\n", user.userid); pressanykey(); return; }
/* * retrieve_user() and done_retrieve() by Ardant ([email protected]) * basically the above two functions rolled into one easy function * modified to allow for NULL user object */ UR_OBJECT retrieve_user(UR_OBJECT user, const char *name) { UR_OBJECT u; UD_OBJECT entry, last; int found; size_t len; len = strlen(name); last = NULL; found = 0; *text = '\0'; for (entry = first_user_entry; entry; entry = entry->next) { if (!strncasecmp(entry->name, name, len)) { if (strlen(entry->name) == len) { break; } /* FIXME: Bounds checking */ strcat(text, found++ % 8 ? " " : "\n "); strcat(text, entry->name); last = entry; } } if (entry) { found = 1; last = entry; } if (found > 1) { if (user) { vwrite_user(user, "\n~FR~OLName is not unique. \"~FT%s~RS~FR~OL\" also matches:\n", name); vwrite_user(user, " %s\n\n", text); } retrieve_user_type = 0; *text = '\0'; return NULL; } *text = '\0'; if (!found) { if (user) { write_user(user, nosuchuser); } retrieve_user_type = 0; return NULL; } u = get_user(last->name); if (u) { retrieve_user_type = 1; return u; } u = create_user(); if (!u) { sprintf(text, "%s: unable to create temporary user object.\n", syserror); if (user) { write_user(user, text); } write_syslog(SYSLOG, 1, text); *text = '\0'; retrieve_user_type = 0; return NULL; } strcpy(u->name, last->name); if (!load_user_details(u)) { destruct_user(u); destructed = 0; if (user) { write_user(user, nosuchuser); } retrieve_user_type = 0; return NULL; } retrieve_user_type = 2; return u; }
int main() { int totalTime; totalTime = 0; int quantum; int op; int cpp = 0; pcbCtrl *ctrl; pcbStates *states; groupsCtrl *ctrlG; usersCtrl *ctrlU; ctrl = malloc(sizeof(pcbCtrl)); states = malloc(sizeof(pcbStates)); states->readys = malloc(sizeof(pcbCtrl)); states->waiting = malloc(sizeof(pcbCtrl)); states->sleeping = malloc(sizeof(pcbCtrl)); ctrlG = malloc(sizeof(groupsCtrl)); ctrlU = malloc(sizeof(usersCtrl)); printf("\n"); quantum = set_int("Quantum del programa", 1); if(val_npos(quantum, 1) != FAIL) { do { printf("\n \t\t<< SIMULACION DE ALGORITMO DE DESPACHO RONUD-ROBIN >>\n"); print_options(0); printf("\n>"); scanf("%i",&op); getchar(); switch(op) { case 1: printf("\n"); create_group(ctrlG); break; case 2: printf("\n"); create_user(ctrlU); break; case 3: printf("\n"); create_process(cpp,ctrl,states,ctrlG,ctrlU); cpp++; break; case 4: printf("\n"); state_change(ctrl,states); break; case 5: printf("\n"); show_everything(ctrl,states,ctrlG,ctrlU); break; case 6: printf("\n"); rr(states, ctrl, quantum, &totalTime); break; case 7: printf("\n"); del_option(ctrl,states,ctrlG,ctrlU); break; case 8: break; default: printf("Opcion invalida, vuelva a intentarlo.\n"); } }while(op != 8); if(ctrl->front != NULL) { pcb *aux = ctrl->front; while( next_pcb(&aux,ctrl->front) != FAIL ) free(aux); } if(ctrlG->front != NULL) { groups *aux = ctrlG->front; while( next_group(&aux,ctrlG->front) != FAIL ) free(aux); } if(ctrlU->front != NULL) { users *aux = ctrlU->front; while( next_user(&aux,ctrlU->front) != FAIL ) free(aux); } free(ctrl->front); free(ctrlG->front); free(ctrlU->front); free(ctrl); free(ctrlG); free(ctrlU); } return 0; }
/*** send smail to the email ccount ***/ void forward_email(char *name, char *from, char *message) { FILE *fp; UR_OBJECT u; char fname[FNAME_LEN]; int on=0; set_crash(); if (!amsys->forwarding) return; if ((u=get_user(name))) { on=1; goto SKIP; } /* Have to create temp user if not logged on to check if email verified, etc */ if ((u=create_user())==NULL) { write_syslog(ERRLOG,1,"Unable to create temporary user object in forward_email().\n"); return; } strcpy(u->name,name); if (!load_user_details(u)) { destruct_user(u); destructed=0; return; } on=0; SKIP: if (!u->mail_verified) { if (!on) { destruct_user(u); destructed=0; } return; } if (!u->autofwd){ if (!on) { destruct_user(u); destructed=0; } return; } sprintf(fname,"%s/%s.FWD",MAILSPOOL,u->name); if (!(fp=fopen(fname,"w"))) { write_syslog(SYSLOG,0,"Unable to open forward mail file in set_forward_email()\n"); return; } fprintf(fp,"From: %s\n",reg_sysinfo[TALKERNAME]); fprintf(fp,"To: %s <%s>\n\n",u->name,u->email); from=colour_com_strip(from); fputs(from,fp); fputs("\n",fp); message=colour_com_strip(message); fputs(message,fp); fputs("\n\n",fp); fputs(talker_signature,fp); fclose(fp); send_email(u->email, "Auto-forward of smail", fname); write_syslog(SYSLOG,1,"%s had mail sent to their email address.\n",u->name); if (!on) { destruct_user(u); destructed=0; } return; }
/* * Delete a user */ void delete_user(UR_OBJECT user, int this_user) { char name[USER_NAME_LEN + 1]; UR_OBJECT u; if (this_user) { /* * User structure gets destructed in disconnect_user(), need to keep a * copy of the name */ strcpy(name, user->name); write_user(user, "\n~FR~LI~OLACCOUNT DELETED!\n"); vwrite_room_except(user->room, user, "~OL~LI%s commits suicide!\n", user->name); write_syslog(SYSLOG, 1, "%s SUICIDED.\n", name); disconnect_user(user); clean_files(name); rem_user_node(name); return; } if (word_count < 2) { write_user(user, "Usage: nuke <user>\n"); return; } *word[1] = toupper(*word[1]); if (!strcmp(word[1], user->name)) { write_user(user, "Trying to delete yourself is the eleventh sign of madness.\n"); return; } if (get_user(word[1])) { /* Safety measure just in case. Will have to .kill them first */ write_user(user, "You cannot delete a user who is currently logged on.\n"); return; } u = create_user(); if (!u) { vwrite_user(user, "%s: unable to create temporary user object.\n", syserror); write_syslog(SYSLOG | ERRLOG, 0, "ERROR: Unable to create temporary user object in delete_user().\n"); return; } strcpy(u->name, word[1]); if (!load_user_details(u)) { write_user(user, nosuchuser); destruct_user(u); destructed = 0; return; } if (u->level >= user->level) { write_user(user, "You cannot delete a user of an equal or higher level than yourself.\n"); destruct_user(u); destructed = 0; return; } clean_files(u->name); rem_user_node(u->name); vwrite_user(user, "\07~FR~OL~LIUser %s deleted!\n", u->name); write_syslog(SYSLOG, 1, "%s DELETED %s.\n", user->name, u->name); destruct_user(u); destructed = 0; }
/* * Read and process commands * Return: -1 for quit command * 0 otherwise */ int process_args(int cmd_argc, char **cmd_argv, User **user_list_ptr) { User *user_list = *user_list_ptr; if (cmd_argc <= 0) { return 0; } else if (strcmp(cmd_argv[0], "quit") == 0 && cmd_argc == 1) { return -1; } else if (strcmp(cmd_argv[0], "add_user") == 0 && cmd_argc == 2) { switch (create_user(cmd_argv[1], user_list_ptr)) { case 1: error("user by this name already exists"); break; case 2: error("username is too long"); break; } } else if (strcmp(cmd_argv[0], "list_users") == 0 && cmd_argc == 1) { list_users(user_list); } else if (strcmp(cmd_argv[0], "update_pic") == 0 && cmd_argc == 3) { User *user = find_user(cmd_argv[1], user_list); if (user == NULL) { error("user not found"); } if (update_pic(user, cmd_argv[2]) == 1) { error("file not found"); } } else if (strcmp(cmd_argv[0], "delete_user") == 0 && cmd_argc == 2) { if (delete_user(cmd_argv[1], user_list_ptr) == 1) { error("user by this name does not exist"); } } else if (strcmp(cmd_argv[0], "make_friends") == 0 && cmd_argc == 3) { switch (make_friends(cmd_argv[1], cmd_argv[2], user_list)) { case 1: error("users are already friends"); break; case 2: error("at least one user you entered has the max number of friends"); break; case 3: error("you must enter two different users"); break; case 4: error("at least one user you entered does not exist"); break; } } else if (strcmp(cmd_argv[0], "post") == 0 && cmd_argc >= 4) { // first determine how long a string we need int space_needed = 0; for (int i = 3; i < cmd_argc; i++) { space_needed += strlen(cmd_argv[i]) + 1; } // allocate the space char *contents = malloc(space_needed); // copy in the bits to make a single string strcpy(contents, cmd_argv[3]); for (int i = 4; i < cmd_argc; i++) { strcat(contents, " "); strcat(contents, cmd_argv[i]); } User *author = find_user(cmd_argv[1], user_list); User *target = find_user(cmd_argv[2], user_list); switch (make_post(author, target, contents)) { case 1: error("the users are not friends"); break; case 2: error("at least one user you entered does not exist"); break; } } else if (strcmp(cmd_argv[0], "profile") == 0 && cmd_argc == 2) { User *user = find_user(cmd_argv[1], user_list); if (print_user(user) == 1) { error("user not found"); } } else { error("Incorrect syntax"); } return 0; }
int handle_A_input() { char buf[3] = {0}; // same for all users // handle create user // handle login // handle exit size_t l = 0; while (l < 1) l = receive_until( buf, '\n', 2); if (buf[0] == '1') { // CREATE USER create_user(0); } else if (buf[0] == '2') { // LOGIN list_users(); char name[MAX_NAME_LEN]; char pswd[MAX_PASS_LEN]; printf("Username: \n"); size_t len = receive_until( name, '\n', MAX_NAME_LEN - 1); name[len++] = 0; printf("Password: \n"); len = receive_until( pswd, '\n', MAX_PASS_LEN - 1); pswd[len++] = 0; msg_count_login = 0; if (login(name, pswd) == 1) { // successful login return 2; } else { printf("Bad login.\n"); bad_login_count++; if (bad_login_count >= 3) { create_user(bad_login_count); // this allows a user to be re-created bad_login_count = 0; } } } else if (buf[0] == '3') { // EXIT printf("The end.\n"); _terminate(0); } else printf("unknown input: @c @c\n", buf[0], buf[1]); return 0; }
int main(void) { int retcode; unsigned int count; fileHandleType fh; int useraccount; void *message; int messagetype; newUserMessageType *newuser; loginMessageType *loginuser; newPostMessageType *newPost; addCommentMessageType *newComment; unsigned int postID; int responseCode; unsigned int nextPostID = 100; unsigned int sessionToken; char *postText; int postSize; int endIt; // using a small blocksize of 256 bytes because postings are small and this is more efficient retcode = initFileSystem(512, 512, 512*2000); securityIDFileHandle = -1; if (retcode != 0) { printf("Error making filesystem.\n"); _terminate(-1); } retcode = makeMemoryFile("sticky.posts", 0x4347C000 + 1536, 160*16, 1, ROOT_ID ); if ( retcode != 0 ) { printf("Error making posts.log\n"); _terminate(-1); } retcode = makeMemoryFile("initialPostID.mem", 0x4347C000, 4, 1, ROOT_ID ); if ( retcode != 0 ) { printf("Error making posts.log\n"); _terminate(-1); } retcode = createFile("Users.db", REGULAR, ROOT_ID); if ( retcode != 0 ) { printf("Error making Users.db\n"); _terminate(-1); } retcode = createFile("posts.log", REGULAR, ROOT_ID); if ( retcode != 0 ) { printf("Error making posts.log\n"); _terminate(-1); } // seed the first postID with magic page data. After this they just increase by 1 each time fh = openFile("initialPostID.mem", ROOT_ID); if ( fh < 0 ) { printf("Error opening initialPostID.mem\n"); _terminate(-1); } readFile(fh, (void *)&nextPostID, sizeof(nextPostID), 0, 0, ROOT_ID); nextPostID &= 0x0fffffff; // we'll never re-seed the postID so just delete the file deleteFile(fh, ROOT_ID); // this file will allow us to get semi-random userID's from the magic page. It is kept open and a new ID is // read whenever a new account is created retcode = makeMemoryFile("UserIDs.mem", 0x4347C004, 1532, 1, ROOT_ID ); if ( retcode != 0 ) { printf("Error making UserIDs.mem\n"); _terminate(-1); } retcode = allocate(1024, 0, &message); if (retcode != 0) { _terminate(-1); } endIt = 0; while (!endIt) { messagetype = receiveMessage(message); switch (messagetype) { // add a new user case 0xa0: newuser = (newUserMessageType *)message; if (create_user(newuser->name, newuser->password, newuser->fullname) >= 0 ) { responseCode = 0; } else { responseCode = -1; } sendResponse((void *)&responseCode, sizeof(responseCode)); break; // authenticate a user case 0xb0: loginuser = (loginMessageType *)message; useraccount = authenticate(loginuser->name, loginuser->password); sendResponse((void *)&useraccount, sizeof(useraccount)); break; // retrieve a single post to this user's feed case 0xc0: sessionToken = *(unsigned int *)message; retcode = newFeedPost(sessionToken, &postText, &postSize); if (retcode == 0 ) { sendResponse((void *)postText, postSize); deallocate((void *)postText, postSize); } else { retcode = -1; sendResponse((void *)&retcode, sizeof(retcode)); } break; // record a new post from the user case 0xd0: newPost = (newPostMessageType *)message; retcode = savePost(nextPostID, newPost->sessionToken, newPost->post); if (retcode == 0) { retcode = nextPostID; ++nextPostID; } else { retcode = -1; } sendResponse((void *)&retcode, sizeof(retcode)); break; // comment on a post case 0xe0: newComment = (addCommentMessageType *)message; retcode = saveComment(newComment->postID, newComment->commenterID, newComment->comment); sendResponse((void *)&retcode, sizeof(retcode)); break; // retrieve a specific post by its ID--this will include any comments as well case 0xf0: postID = *(unsigned int *)message; if ( postID < 16 ) { retcode = sendStickPost( postID ); } else { retcode = retrievePost( postID, 1 , &postText, &postSize); if (retcode == 0) { sendResponse((void *)postText, postSize); deallocate((void *)postText, postSize); } } if ( retcode == -1 ) { sendResponse((void *)&retcode, sizeof(retcode)); } // response sent by the retrievePost() function break; case 100: endIt = 1; break; default: endIt = 1; break; } //switch } // while (1) printf("BYE!\n"); } // main
/* * read all the user files to check if a user exists */ void recount_users(UR_OBJECT user, char *inpstr) { char filename[80], *s; DIR *dirp; FILE *fp; struct dirent *dp; UD_OBJECT entry, next; UR_OBJECT u; int incorrect, correct, added, removed; if (!user->misc_op) { user->misc_op = 17; write_user(user, "~OL~FRWARNING:~RS This process may take some time if you have a lot of user accounts.\n"); write_user(user, " This should only be done if there are no, or minimal, users currently\n logged on.\n"); write_user(user, "\nDo you wish to continue (y|n)? "); return; } user->misc_op = 0; if (tolower(*inpstr) != 'y') { return; } write_user(user, "\n+----------------------------------------------------------------------------+\n"); incorrect = correct = added = removed = 0; write_user(user, "~OLRecounting all of the users...\n"); /* First process the files to see if there are any to add to the directory listing */ write_user(user, "Processing users to add..."); u = create_user(); if (!u) { write_user(user, "ERROR: Cannot create user object.\n"); write_syslog(SYSLOG | ERRLOG, 1, "ERROR: Cannot create user object in recount_users().\n"); return; } /* open the directory file up */ dirp = opendir(USERFILES); if (!dirp) { write_user(user, "ERROR: Failed to open userfile directory.\n"); write_syslog(SYSLOG | ERRLOG, 1, "ERROR: Directory open failure in recount_users().\n"); return; } /* count up how many files in the directory - this include . and .. */ for (dp = readdir(dirp); dp; dp = readdir(dirp)) { s = strchr(dp->d_name, '.'); if (!s || strcmp(s, ".D")) { continue; } *u->name = '\0'; strncat(u->name, dp->d_name, (size_t) (s - dp->d_name)); for (entry = first_user_entry; entry; entry = next) { next = entry->next; if (!strcmp(u->name, entry->name)) { break; } } if (!entry) { if (load_user_details(u)) { add_user_node(u->name, u->level); write_syslog(SYSLOG, 0, "Added new user node for existing user \"%s\"\n", u->name); ++added; reset_user(u); } /* FIXME: Probably ought to warn about this case */ } else { ++correct; } } closedir(dirp); destruct_user(u); /* * Now process any nodes to remove the directory listing. This may * not be optimal to do one loop to add and then one to remove, but * it is the best way I can think of doing it right now at 4:27am! */ write_user(user, "\nProcessing users to remove..."); for (entry = first_user_entry; entry; entry = next) { next = entry->next; sprintf(filename, "%s/%s.D", USERFILES, entry->name); fp = fopen(filename, "r"); if (!fp) { ++removed; --correct; write_syslog(SYSLOG, 0, "Removed user node for \"%s\" - user file does not exist.\n", entry->name); rem_user_node(entry->name); } else { fclose(fp); } } write_user(user, "\n+----------------------------------------------------------------------------+\n"); vwrite_user(user, "Checked ~OL%d~RS user%s. ~OL%d~RS node%s %s added, and ~OL%d~RS node%s %s removed.\n", added + removed + correct, PLTEXT_S(added + removed + correct), added, PLTEXT_S(added), PLTEXT_WAS(added), removed, PLTEXT_S(removed), PLTEXT_WAS(removed)); if (incorrect) { write_user(user, "See the system log for further details.\n"); } write_user(user, "+----------------------------------------------------------------------------+\n"); }