int cmd_pass(t_info *info, char *str) { char *arg; int ret; char buffer[256]; if ((arg = get_cmd_arg(str)) == NULL) { send_answer(info, "Missing password.", 501); return (0); } ret = check_pass(info, arg); if (ret == 0) { snprintf(buffer, 255, "Bad password."); send_answer(info, buffer, 530); info->keep_connected = 0; return (0); } if (ret == 1) { snprintf(buffer, 255, "User %s logged in.", info->user_selected); return (log_user(info, buffer, 230)); } return (1); }
int cmd_mkdir(t_info *info, char *str) { char *arg; char buffer[512]; char buf[256]; if ((arg = get_cmd_arg(str)) == NULL) { send_answer(info, "Missing Argument.", 501); return (0); } snprintf(buffer, sizeof(buffer), "%s/%s/%s%s", info->server_path, ACCOUNT_PATH, info->user_selected, arg); if (mkdir(arg, 0755) == -1) { send_answer(info, "Connot create directory", 550); return (0); } snprintf(buf, sizeof(buf), "\"/%s\" - Directory successfully created", arg); send_answer(info, buf, 257); return (1); }
apr_status_t send_result(socket_thread_data_t *td, int code) { switch(code) { case 220: return send_answer(td, "220 Service ready\n"); break; case 221: return send_answer(td, "221 Closing connection\n"); break; case 250: return send_answer(td, "250 OK\n"); break; case 401: return send_answer(td, "401 Unauthorized\n"); break; case 500: return send_answer(td, "500 Error\n"); break; default: return APR_EINVAL; } }
int main(void){ TEEC_Result res; TEEC_Context ctx; TEEC_Session sess; TEEC_Operation op,init_vals; TEEC_UUID uuid = TA_QUIZ_UUID; char question[DEF_QUES_SIZE] = {0}; uint32_t err_origin; //strt file read FILE *infile; infile = fopen("/bin/test.txt","r"); int num = 0; int i; ssize_t read; size_t len =0; char *line; line = (char *)malloc(sizeof(char) * 120); while((read = getline(&line,&len,infile)) != -1){ // printf("%s\n",line ); num++; } printf("%d\n",num); struct question ques[num/2]; fseek(infile,0,SEEK_SET); for(i =0 ; i < num;++i){ read = getline(&line,&len,infile); // printf("%s\n",line ); line[strlen(line)] = '\0'; if(i%2 == 0){ strcpy(ques[i/2].q,line); }else{ strcpy(ques[i/2].answer,line); } } free(line); num = num/2; /* FILE *infile; infile = fopen("/bin/test.txt","r"); int num = 0; struct question temp; int i; while(fread(&temp,sizeof(struct question),1,infile) != 0){ // printf("%s \n %s \n",temp.q,temp.answer); num++; } fseek(infile,0,SEEK_SET); struct question ques[num]; for(i =0 ; i < num;++i){ fread(&ques[i],sizeof(struct question),1,infile); } */ //end of read from file memset(&init_vals,0,sizeof(init_vals)); init_vals.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,TEEC_MEMREF_TEMP_INPUT,TEEC_NONE,TEEC_NONE); init_vals.params[0].value.a = num; init_vals.params[1].tmpref.buffer = ques; init_vals.params[1].tmpref.size = sizeof(ques[0])*num; res = TEEC_InitializeContext(NULL, &ctx); // This basically checks if a TEE is present in the system if (res != TEEC_SUCCESS) errx(1, "TEEC_InitializeContext failed with code 0x%x", res); /* * Open a session to the TA */ res = TEEC_OpenSession(&ctx, &sess, &uuid,TEEC_LOGIN_PUBLIC, NULL, &init_vals, &err_origin); if (res != TEEC_SUCCESS) errx(1, "TEEC_Opensession failed with code 0x%x origin 0x%x",res, err_origin); /* * Prepare the argument. Pass a value in the first parameter, * the remaining three parameters are unused. */ memset(&op, 0, sizeof(op)); op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, TEEC_NONE); op.params[1].tmpref.buffer = question; op.params[1].tmpref.size = sizeof(question); printf("********************** QUIZ **************************\n"); while(1){ res = TEEC_InvokeCommand(&sess, TA_QUIZ_CMD_START_QUIZ, &op,&err_origin); if (res != TEEC_SUCCESS) errx(1, "TEEC_Get_Question failed with code 0x%x origin 0x%x",res, err_origin); if(op.params[0].value.a == 0){ break; }else{ printf("\n----------------------- \n Question:\n %s \n",question ); printf(" Enter your anwer:\n"); char answer[DEF_QUES_SIZE]; fgets(answer,DEF_QUES_SIZE,stdin); if ((strlen(answer)>0) && (answer[strlen (answer) - 1] == '\n')) answer[strlen (answer) - 1] = '\0'; send_answer(sess,answer,err_origin); } } printf("Quiz ended\n"); /* * Close the session */ TEEC_CloseSession(&sess); TEEC_FinalizeContext(&ctx); return 0; }
static void read_commands(struct client *client) { char buf[1024]; int pos = 0; if (!client->authenticated) client->authenticated = addr.sa.sa_family == AF_UNIX; while (1) { int rc, s, i; rc = read(client->fd, buf + pos, sizeof(buf) - pos); if (rc == -1) { if (errno == EINTR) continue; if (errno == EAGAIN) return; goto close; } if (rc == 0) goto close; pos += rc; s = 0; for (i = 0; i < pos; i++) { const char *line, *msg; char *cmd, *arg; int ret; if (buf[i] != '\n') continue; buf[i] = 0; line = buf + s; s = i + 1; if (!client->authenticated) { if (!server_password) { msg = "password is unset, tcp/ip disabled"; d_print("%s\n", msg); ret = send_answer(client->fd, "%s\n\n", msg); goto close; } if (strncmp(line, "passwd ", 7) == 0) line += 7; client->authenticated = !strcmp(line, server_password); if (!client->authenticated) { msg = "authentication failed"; d_print("%s\n", msg); ret = send_answer(client->fd, "%s\n\n", msg); goto close; } ret = write_all(client->fd, "\n", 1); continue; } while (isspace((unsigned char)*line)) line++; if (*line == '/') { int restricted = 0; line++; search_direction = SEARCH_FORWARD; if (*line == '/') { line++; restricted = 1; } search_text(line, restricted, 1); ret = write_all(client->fd, "\n", 1); } else if (*line == '?') { int restricted = 0; line++; search_direction = SEARCH_BACKWARD; if (*line == '?') { line++; restricted = 1; } search_text(line, restricted, 1); ret = write_all(client->fd, "\n", 1); } else if (parse_command(line, &cmd, &arg)) { if (!strcmp(cmd, "status")) { ret = cmd_status(client); } else { if (strcmp(cmd, "passwd") != 0) { set_client_fd(client->fd); run_parsed_command(cmd, arg); set_client_fd(-1); } ret = write_all(client->fd, "\n", 1); } free(cmd); free(arg); } else { // don't hang cmus-remote ret = write_all(client->fd, "\n", 1); } if (ret < 0) { d_print("write: %s\n", strerror(errno)); goto close; } } memmove(buf, buf + s, pos - s); pos -= s; } return; close: close(client->fd); list_del(&client->node); free(client); }