static int names_hook(int argc, char *argv[]) { char **my_argv; int my_argc; size_t i; user_t *u; make_argv(&my_argc, &my_argv, argv[5]); for (i = 0; i < my_argc; i++) { assert(my_argv[i] != NULL); if (my_argv[i][0] != '@' && my_argv[i][0] != '+') { u = find_user(my_argv[i], irc_pick_server()); u->flags |= USER_IS_OP; } else { u = find_user(&my_argv[i][1], irc_pick_server()); } assert(u); u->add_channel(u, argv[4]); } channel_t *ch = find_channel(argv[4], irc_pick_server()); if (!ch) return -1; // wio_colored_out(ch->win, USER_RED, "[%s] ", argv[4]); // wio_colored_out(ch->win, USER_WHITE, "%s\n", argv[5]); return 0; }
int main (int argc, char *argv[]) { char in[10]; int id = 1; User *s; unsigned num_users; while (1) { printf ("1. add user\n"); printf ("2. find user\n"); printf ("3. delete user\n"); printf ("4. delete all users\n"); printf ("5. sort items by name\n"); printf ("6. sort items by id\n"); printf ("7. print users\n"); printf ("8. count users\n"); gets (in); switch (atoi (in)) { case 1: printf ("name?\n"); add_user (id++, gets (in)); break; case 2: printf ("id?\n"); s = find_user (atoi (gets (in))); printf ("user: %s\n", s ? s->name : "unknown"); break; case 3: printf ("id?\n"); s = find_user (atoi (gets (in))); if (s) delete_user (s); else printf ("id unknown\n"); break; case 4: delete_all (); break; case 5: sort_by_name (); break; case 6: sort_by_id (); break; case 7: print_users (); break; case 8: num_users = HASH_COUNT (users); printf ("there are %u users\n", num_users); break; } } }
int main(void) { find_user("root"); find_user("nobody"); find_user("jesus"); exit(0); }
/* * If a user with name username does not exist, create a new * user by this name and insert it at the end of the user list. * Return values: * 0 if successful * -1 if username already exists */ int add_user(User **user_list_ptr, char *username) { if (find_user(*user_list_ptr, username)){ //find if there is a user with the same name already return -1; //return -1 if username already exists } else { User * ptr; //make new user ptr if ((ptr = malloc(sizeof(User))) == NULL) { //allocate memory for user, return a ptr to that new allocated memory perror("malloc"); //neseccary error checks if malloc fails exit(1); } if ((ptr->name = malloc(sizeof(strlen(username) + 1))) == NULL) { //allocates memory for the string perror("malloc"); //error check if malloc fails exit(1); } strncpy(ptr->name, username, strlen(username)); //copy the string onto the new allocated memory ptr->name[strlen(username)] = '\0'; //make last character a null termiator ptr->next = *user_list_ptr; // since user can be in any order, the order is the same as calendar *user_list_ptr = ptr; //new users become the head of the list return 0; //return 0 on success } }
int set_user(users **u,usersCtrl *ctrlU) { int uid,flag = 1; do { printf("\n%s %s\n",SELEC, "un usuario"); show_users(ctrlU); printf(">"); scanf("%i",&uid); getchar(); *u = find_user(uid,ctrlU->front); if(u != NULL) break; else { printf("%s\n",FIND_FAIL); if(cancel("creacion del proceso") == 1) { flag = FAIL; break; } } }while(1); return flag; }
static int huser_hook(int argc, char *argv[]) { user_t *u = find_user(argv[1], irc_pick_server()); switch (argc) { case 2: u->flags &= ~ALL_USER_COLORS; break; case 3: u->flags &= ~ALL_USER_COLORS; if (!strcasecmp(argv[2], "red")) u->flags |= USER_RED; else if (!strcasecmp(argv[2], "blue")) u->flags |= USER_BLUE; else if (!strcasecmp(argv[2], "green")) u->flags |= USER_GREEN; else if (!strcasecmp(argv[2], "white")) u->flags |= USER_WHITE; else cio_out("unknown color [%s]\n", argv[2]); break; default: assert(!"code should never get here"); } return 0; }
static enum user_response get_user_info_from_header(const realm_type type, char **user_name, struct user_info **user_item) { int ret_val = no_user_response; if ((type == ws_realm)) { if (is_basic(user_name) == 0) ret_val = access_denied_user_response; if (is_digest(user_name) == 0) ret_val = ok_user_response; } else { if (is_basic(user_name) < 0 && /* Load of *user_name here, but not after the is_digest call. */ is_digest(user_name) < 0) ; else if ((*user_item = find_user(*user_name)) != ((void *)0)) ret_val = ok_user_response; else ret_val = access_denied_user_response; if (ret_val != ok_user_response) g_free(*user_name); } return ret_val; }
int take_book(struct library *library, char *book_name, char *user_name) { struct book *book = find_book(library, book_name); struct user *user = find_user(library, user_name); void *ret; if (book == 0){ return 1; } if (user == 0){ return 2; } if (book->owner != 0){ return 3; } ret = realloc(user->books, sizeof(struct book*) * user->nbooks + 1); if (ret == 0){ return -1; } user->books = (struct book **)ret; /* Now point to the new book that we own*/ user->books[user->nbooks] = book; book->owner = user; user->nbooks++; return 0; }
int add_user(struct library *library, char *uname) { void *new_ptr; struct user *user = find_user(library, uname); if (user != NULL){ return 1; } user = (struct user*)malloc(sizeof(struct user)); if (!user){ return -1; } user->books = NULL; user->nbooks = 0; strcpy(user->name, uname); new_ptr = realloc(library->users, sizeof(struct user *) * (library->nusers + 1)); if (new_ptr == NULL){ return -1; } library->users = (struct user **)new_ptr; library->users[library->nusers] = user; library->nusers++; return 0; }
/* * 处理数据 */ int handle(int client,void *buf) { int ret = 0; struct online_user *user; struct format *data = (struct format *)buf; if (data->length == 0) return -1; if (data->type > (sizeof(action_list) / 4) || data->type < 0) return -1; data->data[data->length] = '\0'; user = find_user(client); if (user == NULL || user->handler == NULL) ret = action_list[data->type - 1](client,data->data); if (user != NULL && user->handler != NULL) ret = user->handler(client,data->data); if (ret < 0) close_connect(client); return ret; }
static void handle_update_game (DskHttpServerRequest *request) { DskCgiVariable *user_var = dsk_http_server_request_lookup_cgi (request, "user"); DskCgiVariable *dx_var = dsk_http_server_request_lookup_cgi (request, "dx"); DskCgiVariable *dy_var = dsk_http_server_request_lookup_cgi (request, "dy"); DskCgiVariable *bx_var = dsk_http_server_request_lookup_cgi (request, "bx"); DskCgiVariable *by_var = dsk_http_server_request_lookup_cgi (request, "by"); User *user = find_user (user_var->value); char buf[512]; if (user == NULL) { snprintf (buf, sizeof (buf), "user %s not found", user_var->value); dsk_http_server_request_respond_error (request, DSK_HTTP_STATUS_BAD_REQUEST, buf); return; } parse_int_clamp (dx_var, &user->move_x); parse_int_clamp (dy_var, &user->move_y); parse_int_clamp (bx_var, &user->bullet_x); parse_int_clamp (by_var, &user->bullet_y); if (user->last_update == user->base.game->latest_update) { /* wait for next frame */ PendingUpdate *pu = dsk_malloc (sizeof (PendingUpdate)); pu->user = user; pu->request = request; pu->next = user->base.game->pending_updates; user->base.game->pending_updates = pu; } else { DskJsonValue *state_json = create_user_update (user); respond_take_json (request, state_json); } }
int remove_user(dev_info_t *pdev, macadr_t *user) { int i; i = find_user(pdev, user); clean_user(&pdev->users[i]); return 0; }
static int notice_hook(int argc, char *argv[]) { char *nick = grab_nick(argv[0]); size_t i; user_t *u = find_user(nick, irc_pick_server()); assert(u != NULL); if (u->flags & USER_IGNORE || u->flags & USER_IGNORE_NOTICES) return 0; for (i = 0; i < strlen(argv[3]); i++) if (argv[3][i] == 2) remove_char_from_str(argv[3], i); if (argv[3][0] == 1) plugin_ctcp_in_hook(nick, argv[2], argv[3], irc_pick_server()); else if (argv[2][0] == '#') { channel_t *ch = find_channel(argv[2], irc_pick_server()); if (!ch) return -1; wio_colored_out(ch->win, USER_GREEN, "*** NOTICE from %s: %s\n", nick, argv[3]); } else io_colored_out(USER_GREEN, "*** NOTICE from %s: %s\n", nick, argv[3]); free(nick); return 0; }
void privmsg_command(int connfd,char *target_list,char* msg){ user *u = user_table[connfd]; char buf[MAX_MSG_LEN]; channel *c; char *target; int tar_fd; while((target = strsep(&target_list,","))){ snprintf(buf,MAX_MSG_LEN,":%s PRIVMSG %s:%s\n",u->nick_name, target, msg); /* ignore PRIVMSG to self */ if(!strcasecmp(target,u->nick_name)) continue; /* if target is a valid channal, send the message to its memembers*/ if(channel_valid(target) && (c = find_channel(target))) invoke_channel(connfd,buf,c); /* if target is a valid user, send the message to it */ else if(nick_valid(target) && (tar_fd = find_user(target,connfd)) >= 0) send_msg_back(tar_fd,buf); /* illegal target should be returned */ else{ snprintf(buf,MAX_MSG_LEN,"%s:No such nick/channel\n",target); send_msg_back(connfd,buf); } } }
void sendClientMessage(qrClientMsg *cmsg) { boost::shared_ptr<Client> c = find_user(cmsg->toip,cmsg->toport); if(c) { c->sendMsg(cmsg->data,cmsg->len); c->unlockKeys(); } }
static int nick_hook(int argc, char *argv[]) { char *nick = grab_nick(argv[0]); user_t *u = find_user(nick, irc_pick_server()); u->recv_nick(u, argv[2]); free(nick); return 0; }
//removes user static int sh_rmdir(const char *path) { struct user* user = find_user(root, path+1); if(user == NULL) return -ENOENT; return sf_tree_delete_user(root, path+1); }
int main() { char *line1 = "this is bad\n"; printf("testing strstr: %s\n", strstr(line1, "\n")); char user[USER_LEN]; char pswd[PSWD_LEN]; char underscore[1] = "_"; char *username; char yes_no; printf("=======WELCOME TO MARY'S PROM DATE SERVER=======\nYou want to take Mary out to PROM because she is an awesome person and if you don't want to then you have bad taste in women.\n\nPlease type in 1 if you have an account or 2 if you'd like to make one.\n"); fgets(&yes_no, 3, stdin); printf("yes_no value:%c\n", yes_no); if (yes_no == '1') { find_user(); /*FILE* fd1 = fopen("username.txt", "r"); printf("Please type in your username:\n"); fgets(user, USER_LEN, stdin); printf("Please type in your password:\n"); fgets(pswd, PSWD_LEN, stdin); char *buffer = (char *)malloc(100*sizeof(char)); //printf("sizeof(buffer) = %lu\n", sizeof(buffer)); fread(buffer, sizeof(char), 100, fd1); printf("buffer: %s\n", buffer); buffer = ""; printf("buffer after fread/fwrite: %s\n", buffer); */ } else if (yes_no == '2'){ FILE* fd1 = fopen("username.txt", "a+"); printf("Please create a username:\n"); fgets(user, USER_LEN, stdin); printf("Please create a password:\n"); fgets(pswd, PSWD_LEN, stdin); printf("username array: %s\n", user); printf("pswd array: %s\n", pswd); username = calloc(strlen(user) + strlen(pswd) + 1 + 1, sizeof(char));//1 is for the underscore and the other is for the null char strcat(username, user); char *line = (char *)calloc(strlen(user) + strlen(pswd) + 1 + 1, sizeof(char)); line = strsep(&username, "\n"); //printf("sizeof(username) = %lu\n", strlen(username)); strcat(line, underscore); //printf("username: %s\n", username); //strcat(password, pswd); strcat(line, pswd); printf("line: %s\n", line); if (find_user_match(user) == 0) { fwrite(line, sizeof(char), strlen(line), fd1); } else if (find_user_match(user) == 1) printf("Please try again\n"); fclose(fd1); } else printf("STOP SABOTAGING THIS PROGRAM AND GIVE US EITHER 1 OR 2 AS YOUR ANSWER. SMH PEOPLE THESE DAYS\n"); return 0; }
void findMatchingServers_GetRules(qrServerRules *rulesData, char *sendmodule) { boost::shared_ptr<Client> user; user = find_user(rulesData->ipaddr,rulesData->port); if(user) { //getRules allocates data which must be freed rulesData->server_rules = user->getRules(); user->unlockKeys(); } }
bool set_pool(PgSocket *client, const char *dbname, const char *username, const char *password, bool takeover) { /* find database */ client->db = find_database(dbname); if (!client->db) { client->db = register_auto_database(dbname); if (!client->db) { disconnect_client(client, true, "No such database: %s", dbname); if (cf_log_connections) slog_info(client, "login failed: db=%s user=%s", dbname, username); return false; } else { slog_info(client, "registered new auto-database: db = %s", dbname ); } } /* are new connections allowed? */ if (client->db->db_disabled) { disconnect_client(client, true, "database does not allow connections: %s", dbname); return false; } if (client->db->admin) { if (admin_pre_login(client, username)) return finish_set_pool(client, takeover); } /* find user */ if (cf_auth_type == AUTH_ANY) { /* ignore requested user */ if (client->db->forced_user == NULL) { slog_error(client, "auth_type=any requires forced user"); disconnect_client(client, true, "bouncer config error"); return false; } client->auth_user = client->db->forced_user; } else { /* the user clients wants to log in as */ client->auth_user = find_user(username); if (!client->auth_user && client->db->auth_user) { if (takeover) { client->auth_user = add_db_user(client->db, username, password); return finish_set_pool(client, takeover); } start_auth_request(client, username); return false; } if (!client->auth_user) { disconnect_client(client, true, "No such user: %s", username); if (cf_log_connections) slog_info(client, "login failed: db=%s user=%s", dbname, username); return false; } } return finish_set_pool(client, takeover); }
int file_passwd(char *uname, char *locn) { char *ne, *oc, *nc; int fd; FILE *fp; uid_t uid; char *fname; struct passwd *pw; struct passwd newpw; fname = _PASSWD_FILE; if (locn != NULL) fname = locn; fd = open(fname, O_RDONLY | O_EXLOCK); if (fd == -1) { err(EXIT_FAILURE, "%s", fname); } fp = fdopen(fd, "r"); if (fp == NULL) { err(EXIT_FAILURE, "%s", fname); } pw = find_user(fp, uname); if (pw == NULL) { errx(EXIT_FAILURE, "user %s not found in %s", uname, fname); } uid = getuid(); if (uid != 0 && uid != pw->pw_uid) { errno = EACCES; err(EXIT_FAILURE, "%s", uname); } // Get the password getpasswd(uname, (uid == 0), 5, 0, 0, pw->pw_passwd, &ne, &oc, &nc); newpw.pw_name = strdup(pw->pw_name); newpw.pw_passwd = strdup(ne); newpw.pw_uid = pw->pw_uid; newpw.pw_gid = pw->pw_gid; newpw.pw_class = strdup(pw->pw_class); newpw.pw_change = pw->pw_change; newpw.pw_expire = pw->pw_expire; newpw.pw_gecos = strdup(pw->pw_gecos); newpw.pw_dir = strdup(pw->pw_dir); newpw.pw_shell = strdup(pw->pw_shell); // Rewrite the file rewind(fp); rewrite_file(fname, fp, &newpw); fclose(fp); return 0; }
//only edits reserved attribute for user static int sh_mknod(const char *path, mode_t mode, dev_t rdev) { struct user* user = find_user(root, path+1); char uname[9]; printf("mknod\n"); if(user != NULL || strcmp(path, "/") == 0) return -ENOENT; int i = user_from_path(path, uname); user = find_user(root, uname); i+=2; if(user != NULL) { user->reserved = malloc(50); strcpy(user->reserved, path+i); } else return -EACCES; return 0; }
static int sh_write(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { struct user* user = find_user(root, path+1); char uname[9]; printf("write\n"); if(user != NULL || strcmp(path, "/") == 0) return -ENOENT; int i = user_from_path(path, uname); user = find_user(root, uname); i+=2; if(user == NULL) return -ENOENT; if(strcmp(path+i, "password-hash") == 0) { char *hashed; hashed = hashword(buf); update_hash(root, uname, hashed); update_daysSinceChanged(root, uname, shadow_time()); } else if(strcmp(path+i, "days_since_changed") == 0) { update_daysSinceChanged(root, uname, atoi(buf)); } else if(strcmp(path+i, "days_until_can_change") == 0) { update_daysUntilCanChange(root, uname, atoi(buf)); } else if(strcmp(path+i, "days_until_must_change") == 0) { update_daysUntilMustChange(root, uname, atoi(buf)); } else if(strcmp(path+i, "days_before_warning") == 0) { update_daysBeforeWarning(root, uname, atoi(buf)); } else if(strcmp(path+i, "days_until_expiration") == 0) { update_daysUntilExpiration(root, uname, atoi(buf)); } else if(strcmp(path+i, "days_since_account_deactivated") == 0) { update_daysSinceDeactivation(root, uname, atoi(buf)); } else if(strcmp(path+i, "reserved") == 0) { update_reserved(root, uname, buf); } return size; }
bool set_pool(PgSocket *client, const char *dbname, const char *username) { PgDatabase *db; PgUser *user; /* find database */ db = find_database(dbname); if (!db) { db = register_auto_database(dbname); if (!db) { disconnect_client(client, true, "No such database: %s", dbname); return false; } else { slog_info(client, "registered new auto-database: db = %s", dbname ); } } /* are new connections allowed? */ if (db->db_disabled) { disconnect_client(client, true, "database does not allow connections: %s", dbname); return false; } /* find user */ if (cf_auth_type == AUTH_ANY) { /* ignore requested user */ user = NULL; if (db->forced_user == NULL) { slog_error(client, "auth_type=any requires forced user"); disconnect_client(client, true, "bouncer config error"); return false; } client->auth_user = db->forced_user; } else { /* the user clients wants to log in as */ user = find_user(username); if (!user) { disconnect_client(client, true, "No such user: %s", username); return false; } client->auth_user = user; } /* pool user may be forced */ if (db->forced_user) user = db->forced_user; client->pool = get_pool(db, user); if (!client->pool) { disconnect_client(client, true, "no memory for pool"); return false; } return check_fast_fail(client); }
void obj_P_init(obj *o,evt *e,lnk *l) { double dr; dr=(GTIME-o->s.ct)*o->s.v; o->s.cx+=o->s.tx*dr; o->s.cy+=o->s.ty*dr; o->s.tx=0; o->s.ty=0; o->s.ct=GTIME; o->dev.cm=0.0; o->dev.pwr[0]=o->dev.pwr[1]=o->dev.pwr[2]=0; if(o->port!=NULL) o->port=find_user((char *)&o->port); obj_FF_init(o,e,l); loc_col_bmv(o); // добавлено для отказа от прежнего режима движения через команду mv }
/* returns true if (user, passwd) pair is in list */ int authenticate_user(char *username, char *passwd) { UserEntry *user = find_user(username); if ((user == NULL) || (strcmp(user->passwd, passwd) != 0)) return 0; else return 1; }
//renames user static int sh_rename(const char *from, const char *to) { struct user* user = find_user(root, from+1); if(user == NULL) return -EACCES; strcpy(user->username, to+1); return 0; }
void loaduserdb() { char accname[50]; int acclevel; int seen,options,timeout; char md5_pass[35]; User *uptr; MYSQL_RES *result; MYSQL_ROW row; if (!reconnect_to_db()) { fprintf(stderr,"Cannot connect to db\n"); operlog("Cannot connect to db"); return; } mysql_query(&mysql,"SELECT * FROM child_users"); if ((result = mysql_use_result(&mysql)) == NULL) { printf("CRITICAL: Cannot load user table: mysql_use_result returned NULL\n"); return; } while ((row = mysql_fetch_row(result))) { strncpy(accname,row[0],50); acclevel = strtol(row[1],NULL,10); seen = strtol(row[2],NULL,10); strncpy(md5_pass,row[4],35); options = strtol(row[5],NULL,10); timeout = strtol(row[6],NULL,10); if (!timeout) timeout = TIMEOUT_DFLT; if (vv) printf("Adding user %s with level %d and pass %s and vhost %s\n",accname,acclevel,md5_pass,row[3]); if (find_user(accname)) continue; uptr = AddUser(accname,acclevel); if (seen) uptr->lastseen = seen; else uptr->lastseen = time(NULL); uptr->options = options; uptr->timeout = timeout; if (vv) printf("User %s added (%p)\n",accname,uptr); strncpy(uptr->vhost,row[3],HOSTLEN); strncpy(uptr->email,row[7],EMAILLEN); uptr->regtime = strtol(row[8], NULL, 10); memset(uptr->md5_pass,'\0',34); strncpy(uptr->md5_pass,md5_pass,32); } mysql_close(&mysql); }
void update_user_timestamp(u_queue_t *u, uint32_t uid, uint32_t now) { user_t *p = find_user(u, uid); if(p == NULL) { fprintf(stderr, "update_user_timestamp error: invalid user id\n"); return; } p->timestamp = now; }
/* * Ugh. To avoid negative return values, "getpriority()" will * not return the normal nice-value, but a negated value that * has been offset by 20 (ie it returns 40..1 instead of -20..19) * to stay compatible. */ asmlinkage long sys_getpriority(int which, int who) { struct task_struct *g, *p; struct user_struct *user; long niceval, retval = -ESRCH; struct pid *pgrp; if (which > PRIO_USER || which < PRIO_PROCESS) return -EINVAL; read_lock(&tasklist_lock); switch (which) { case PRIO_PROCESS: if (who) p = find_task_by_vpid(who); else p = current; if (p) { niceval = 20 - task_nice(p); if (niceval > retval) retval = niceval; } break; case PRIO_PGRP: if (who) pgrp = find_vpid(who); else pgrp = task_pgrp(current); do_each_pid_task(pgrp, PIDTYPE_PGID, p) { niceval = 20 - task_nice(p); if (niceval > retval) retval = niceval; } while_each_pid_task(pgrp, PIDTYPE_PGID, p); break; case PRIO_USER: user = current->user; if (!who) who = current->uid; else if ((who != current->uid) && !(user = find_user(who))) goto out_unlock; /* No processes for this user */ do_each_thread(g, p) if (p->uid == who) { niceval = 20 - task_nice(p); if (niceval > retval) retval = niceval; } while_each_thread(g, p); if (who != current->uid) free_uid(user); /* for find_user() */ break; }