int prompt(int connfd) { int r = 0; memset(read_buff, 0, SIZE_READ_BUFF); // r = read(connfd, read_buff, SIZE_READ_BUFF); r = read_helper(connfd, read_buff); if(r == 1) return COMMAND_HANDLED; strcpy(original_read_buff, read_buff); argv = command_decode(read_buff); if(strcmp(argv[0], "exit") == 0) return 0; // same as end if(strcmp(argv[0], "setenv") == 0) { setenv_helper(connfd); return COMMAND_HANDLED; } if(strcmp(argv[0], "printenv") == 0) { printenv_helper(connfd); return COMMAND_HANDLED; } if(strcmp(argv[0], "who") == 0) { cmd_who(connfd); return COMMAND_HANDLED; } if(strcmp(argv[0], "name") == 0) { cmd_name(connfd, argv[1]); return COMMAND_HANDLED; } if(strcmp(argv[0], "yell") == 0) { cmd_yell(connfd, original_read_buff); return COMMAND_HANDLED; } if(strcmp(argv[0], "tell") == 0) { cmd_tell(connfd, atoi(argv[1])-1, original_read_buff); return COMMAND_HANDLED; } return r; }
static void co_debug_parse(int fd) { xml_start(); for (;;) { co_debug_tlv_t tlv; int nread; nread = read(fd, &tlv, sizeof(tlv)); if (nread != sizeof(tlv) || tlv.length == 0) break; char block[tlv.length]; nread = read_helper(fd, (void*)&block, tlv.length); if (nread != tlv.length) break; parse_tlv(&tlv, block); /* Flush every block, if stdout not redirected */ if (output_file != stdout) fflush (output_file); } xml_end(); }
void read_it(void) { read_helper( Test_fd, "This is test PPP input." ); }
int sepol_module_package_read(sepol_module_package_t *mod, struct sepol_policy_file *spf, int verbose) { struct policy_file *file= &spf->pf; uint32_t *buf, nsec; size_t *offsets, len; int retval = -1; unsigned i, seen = 0; if (module_package_read_offsets(mod, file, &offsets, &nsec)) return -1; /* we know the section offsets, seek to them and read in the data */ for (i = 0; i < nsec; i++ ) { if (policy_file_seek(file, offsets[i])) { ERR(file->handle, "error seeking to offset %zu for " "module package section %u", offsets[i], i); goto cleanup; } len = offsets[i + 1] - offsets[i]; if (len < sizeof(uint32_t)) { ERR(file->handle, "module package section %u " "has too small length %zu", i, len); goto cleanup; } /* read the magic number, so that we know which function to call */ buf = next_entry(file, sizeof(uint32_t)); if (!buf) { ERR(file->handle, "module package section %u truncated, lacks magic number", i); goto cleanup; } switch(le32_to_cpu(buf[0])) { case SEPOL_PACKAGE_SECTION_FC: if (seen & SEEN_FC) { ERR(file->handle, "found multiple file contexts sections in module package (at section %u)", i); goto cleanup; } mod->file_contexts_len = len - sizeof(uint32_t); mod->file_contexts = (char *)malloc(mod->file_contexts_len); if (!mod->file_contexts) { ERR(file->handle, "out of memory"); goto cleanup; } if (read_helper(mod->file_contexts, file, mod->file_contexts_len)) { ERR(file->handle, "invalid file contexts section at section %u", i); free(mod->file_contexts); mod->file_contexts = NULL; goto cleanup; } seen |= SEEN_FC; break; case SEPOL_PACKAGE_SECTION_SEUSER: if (seen & SEEN_SEUSER) { ERR(file->handle, "found multiple seuser sections in module package (at section %u)", i); goto cleanup; } mod->seusers_len = len - sizeof(uint32_t); mod->seusers = (char *)malloc(mod->seusers_len); if (!mod->seusers) { ERR(file->handle, "out of memory"); goto cleanup; } if (read_helper(mod->seusers, file, mod->seusers_len)) { ERR(file->handle, "invalid seuser section at section %u", i); free(mod->seusers); mod->seusers = NULL; goto cleanup; } seen |= SEEN_SEUSER; break; case SEPOL_PACKAGE_SECTION_USER_EXTRA: if (seen & SEEN_USER_EXTRA) { ERR(file->handle, "found multiple user_extra sections in module package (at section %u)", i); goto cleanup; } mod->user_extra_len = len - sizeof(uint32_t); mod->user_extra = (char *)malloc(mod->user_extra_len); if (!mod->user_extra) { ERR(file->handle, "out of memory"); goto cleanup; } if (read_helper(mod->user_extra, file, mod->user_extra_len)) { ERR(file->handle, "invalid user_extra section at section %u", i); free(mod->user_extra); mod->user_extra= NULL; goto cleanup; } seen |= SEEN_USER_EXTRA; break; case POLICYDB_MOD_MAGIC: if (seen & SEEN_MOD) { ERR(file->handle, "found multiple module sections in module package (at section %u)", i); goto cleanup; } /* seek back to where the magic number was */ if (policy_file_seek(file, offsets[i])) goto cleanup; retval = policydb_read(&mod->policy->p, file, verbose); if (retval < 0) { ERR(file->handle, "invalid module in module package (at section %u)", i); goto cleanup; } seen |= SEEN_MOD; break; default: /* unknown section, ignore */ ERR(file->handle, "unknown magic number at section %u, offset: %zx, number: %ux ", i, offsets[i],le32_to_cpu(buf[0])); break; } } if ((seen & SEEN_MOD) == 0) { ERR(file->handle, "missing module in module package"); goto cleanup; } free(offsets); return 0; cleanup: free(offsets); return retval; }
bool acut::read_file(const std::wstring& path, std::vector<wchar_t>& buffer) { return read_helper(path, buffer); }
bool acut::read_file(const std::wstring& path, std::wstring& buffer) { return read_helper(path, buffer); }