/** * generic acl checking for different methods (basic set of methods supported) * returns null if no err */ static dav_error *check_methods(request_rec *r, const dav_resource *resource, davacl_dir_cfg *conf) { const dav_hooks_repository *repos = REPOS(conf); if (repos == NULL || resource == NULL) return dav_acl_privilege_error(r, "unknown", NULL); switch (r->method_number) { default: if (r->method_number == iM_ACL) { return check_acl(r, resource, conf, repos); } else if (r->method_number == iM_HEAD) { return check_get(r, resource, conf, repos); } else { TRACE(r, "Unknown methdod:%d", r->method_number); return NULL; } break; case M_PUT: return check_put(r, resource, conf, repos); case M_PROPPATCH: return check_proppatch(r, resource, conf, repos); case M_MKCOL: return check_mkcol(r, resource, conf, repos); case M_PROPFIND: /* done with individual properties within dav_get_props() and * dav_get_allprops */ return NULL; case M_DELETE: return check_delete(r, resource, conf, repos); case M_OPTIONS: case M_GET: return check_get(r, resource, conf, repos); case M_COPY: return check_copy(r, resource, conf, repos); case M_MOVE: return check_move(r, resource, conf, repos); case M_LOCK: return check_lock(r, resource, conf, repos); case M_UNLOCK: return check_unlock(r, resource, conf, repos); } }
void send(char line_data[], void *p){ Socket *s = p; Socket connect_socket = *s; int i, rc; for(i = 0; i < strlen(line_data); i++){ rc = Socket_putc(line_data[i], connect_socket); check_put(rc, &connect_socket); } }
void do_put(char recv_buf[], char send_buf[], char file_buf[], char current_dir[], char processed_path[], int client_sockfd, int file_sockfd) { printf("## PUT cmd ##\n"); int ret; struct cmd_type_header* cmd_hdr = (struct cmd_type_header*)recv_buf; ret = check_put(cmd_hdr->cmd_argv, send_buf, current_dir, processed_path); send(client_sockfd, send_buf, BUF_SIZE, 0); if (ret == 0) { recv_file(processed_path, file_sockfd, file_buf); } }
void shell_service(void){ int i = 0, c, character, rc, no_error; //MAX_LINE is the longest the stdin buffer can be, so we won't overflow it char line_data[MAX_LINE]; pid_t cpid, term_pid; /* pid_t is typedef for Linux process ID */ int chld_status; unsigned char new_line[MAX_LINE]; unsigned char tmp_name[MAX_TMP]; unsigned char id_str[MAX_TMP]; char response[MAX_LINE]; char temp[MAX_LINE]; int id; /* variable names for file "handles" */ FILE *tmpFP; FILE *fp; /* get the parent process ID and use it to create a file name for the * temporary file with the format "tmpxxxxx" where xxxxx is the ID */ id = (int) getpid(); sprintf(id_str, "%d", id); strcpy(tmp_name,"tmp"); strcat(tmp_name, id_str); /* will not use the server socket */ Socket_close(welcome_socket); while((c = Socket_getc(connect_socket)) != EOF){ if(c != NEWLINE){ line_data[i] = c; i ++; } else{ line_data[i] = STRING_END; i++; //make sure the string is terminated if(i == MAX_LINE){ line_data[MAX_LINE - 1] = STRING_END; } cpid = fork(); /* create child == service process */ if (cpid == ERROR){ perror("fork"); exit (ERROR); } if (cpid == NORMAL) {/* code for the service process */ /* dynamically redirect stdout to the named temporary * file open for writing */ fp = freopen(tmp_name, "w", stdout); parse_input(line_data, &connect_socket); } /* end service process */ else{ i = 0; term_pid = waitpid(cpid, &chld_status, 0); if (term_pid == ERROR) perror("waitpid"); else{ if (WIFEXITED(chld_status)) sprintf(response, "End of input: PID %d exited, status = %d\n", cpid, WEXITSTATUS(chld_status)); else sprintf(response, "End of Input: PID %d did not exit normally\n", cpid); } if ((tmpFP = fopen (tmp_name, "r")) == NULL) { fprintf (stderr, "error opening tmp file\n"); exit (ERROR); } no_error = 0; while (!feof (tmpFP)) { no_error = 1; /* Get line from file */ if (fgets (new_line, sizeof(new_line), tmpFP) == NULL) break; send(new_line, &connect_socket); } rc = Socket_putc(NEWLINE, connect_socket); check_put(rc, &connect_socket); if(no_error) send(response, &connect_socket); rc = Socket_putc(STRING_END, connect_socket); check_put(rc, &connect_socket); /* delete the temporary file */ remove(tmp_name); // } } } } }