void recv_file(int conn_fd) { /* Client sends encoded file path and permissions */ char *perm_ptr, *filepath = buf; if((perm_ptr = strstr(buf, SEPARATOR)) != NULL) { *(perm_ptr) = '\0'; /* Stick in a NULL and advance a pointer, effectively making two * strings. One for file path, one for permissions */ perm_ptr += strlen(SEPARATOR); FILE* f = fopen(filepath, "w"); if(f == NULL) err_handler("Failed to open file"); build_dirs(filepath, 0); memset(buf, '\0', sizeof(buf)); while(recv(conn_fd, buf, BUF_SIZE, NO_FLAGS) > 0) { if(strncmp(buf, OP_EOF, strlen(OP_EOF)) == 0) { fflush(f); break; } fputs(buf, f); send(conn_fd, ACK, strlen(ACK), NO_FLAGS); /* Clear the buffer for accurate comparisons */ memset(buf, '\0', sizeof(buf)); } if(strcmp(buf, OP_EOF) == 0) printf("File transfer successful\n"); fflush(NULL); fclose(f); } }
void fs_var_log(void) { build_list("/var/log"); // create /var/log if it doesn't exit if (is_dir("/var/log")) { // extract group id for /var/log/wtmp struct stat s; gid_t wtmp_group = 0; if (stat("/var/log/wtmp", &s) == 0) wtmp_group = s.st_gid; // mount a tmpfs on top of /var/log if (arg_debug) printf("Mounting tmpfs on /var/log\n"); if (mount("tmpfs", "/var/log", "tmpfs", MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0) errExit("mounting /var/log"); fs_logger("tmpfs /var/log"); build_dirs(); release_all(); // create an empty /var/log/wtmp file /* coverity[toctou] */ FILE *fp = fopen("/var/log/wtmp", "w"); if (fp) fclose(fp); if (chown("/var/log/wtmp", 0, wtmp_group) < 0) errExit("chown"); if (chmod("/var/log/wtmp", S_IRUSR | S_IWRITE | S_IRGRP | S_IWGRP | S_IROTH ) < 0) errExit("chmod"); fs_logger("touch /var/log/wtmp"); // create an empty /var/log/btmp file fp = fopen("/var/log/btmp", "w"); if (fp) fclose(fp); if (chown("/var/log/btmp", 0, wtmp_group) < 0) errExit("chown"); if (chmod("/var/log/btmp", S_IRUSR | S_IWRITE | S_IRGRP | S_IWGRP) < 0) errExit("chmod"); fs_logger("touch /var/log/btmp"); } else fprintf(stderr, "Warning: cannot mount tmpfs on top of /var/log\n"); }
void fs_var_log(void) { build_list("/var/log"); // create /var/log if it does't exit struct stat s; if (is_dir("/var/log")) { // mount a tmpfs on top of /var/log if (arg_debug) printf("Mounting tmpfs on /var/log\n"); if (mount("tmpfs", "/var/log", "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0) errExit("mounting /var/log"); build_dirs(); release_all(); } else fprintf(stderr, "Warning: cannot mount tmpfs in top of /var/log\n"); }
void init_filelist(struct benchfiles *b, char *basedir, char *basename, uint32_t numsubdirs, int builddirs) { memset(b, 0, sizeof(struct benchfiles)); b->basedir = ffsb_strdup(basedir); b->basename = ffsb_strdup(basename); b->numsubdirs = numsubdirs; init_rwlock(&b->fileslock); b->files = rbtree_construct(); b->dirs = rbtree_construct(); b->holes = ffsb_malloc(sizeof(struct cirlist)); b->dholes = ffsb_malloc(sizeof(struct cirlist)); init_cirlist(b->holes); init_cirlist(b->dholes); if (builddirs) build_dirs(b); }
void fs_var_log(void) { build_list("/var/log"); // note: /var/log is not created here, if it does not exist, this section fails. // create /var/log if it doesn't exit if (is_dir("/var/log")) { // extract group id for /var/log/wtmp struct stat s; gid_t wtmp_group = 0; if (stat("/var/log/wtmp", &s) == 0) wtmp_group = s.st_gid; // mount a tmpfs on top of /var/log if (arg_debug) printf("Mounting tmpfs on /var/log\n"); if (mount("tmpfs", "/var/log", "tmpfs", MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0) errExit("mounting /var/log"); fs_logger("tmpfs /var/log"); build_dirs(); release_all(); // create an empty /var/log/wtmp file /* coverity[toctou] */ FILE *fp = fopen("/var/log/wtmp", "w"); if (fp) { SET_PERMS_STREAM(fp, 0, wtmp_group, S_IRUSR | S_IWRITE | S_IRGRP | S_IWGRP | S_IROTH); fclose(fp); } fs_logger("touch /var/log/wtmp"); // create an empty /var/log/btmp file fp = fopen("/var/log/btmp", "w"); if (fp) { SET_PERMS_STREAM(fp, 0, wtmp_group, S_IRUSR | S_IWRITE | S_IRGRP | S_IWGRP); fclose(fp); } fs_logger("touch /var/log/btmp"); } else fwarning("cannot hide /var/log directory\n"); }