static void getfovimg(void) /* load foveal sampled image */ { char combuf[PATH_MAX]; FILE *fp; int x, y; /* compute image size */ fvxr = sqrt(ourview.hn2)/FOVDIA + 0.5; if (fvxr < 2) fvxr = 2; fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5; if (fvyr < 2) fvyr = 2; if (!(inpres.rt & YMAJOR)) { /* picture is rotated? */ y = fvyr; fvyr = fvxr; fvxr = y; } if ((fovimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR))) == NULL) syserror("malloc"); sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d \"%s\"", fvxr, fvyr, infn); if ((fp = popen(combuf, "r")) == NULL) syserror("popen"); getheader(fp, NULL, NULL); /* skip header */ if (fgetresolu(&x, &y, fp) < 0 || (x != fvxr) | (y != fvyr)) goto readerr; for (y = 0; y < fvyr; y++) if (freadscan(fovscan(y), fvxr, fp) < 0) goto readerr; pclose(fp); return; readerr: fprintf(stderr, "%s: error reading from pfilt process in fovimage\n", progname); exit(1); }
int sys_get_robust_list(struct tcb *tcp) { if (entering(tcp)) { tprintf("%ld, ", (long) (pid_t) tcp->u_arg[0]); } else { void *addr; size_t len; if (syserror(tcp) || !tcp->u_arg[1] || umove(tcp, tcp->u_arg[1], &addr) < 0) { tprintf("%#lx, ", tcp->u_arg[1]); } else { tprintf("[%p], ", addr); } if (syserror(tcp) || !tcp->u_arg[2] || umove(tcp, tcp->u_arg[2], &len) < 0) { tprintf("%#lx", tcp->u_arg[2]); } else { tprintf("[%lu]", (unsigned long) len); } } return 0; }
/* Check if filename is a valid FIFO pipe. If not create it. * Returns 0 on success, -1 on error. */ int checkfifo(const char* filename) { struct stat fstat; /* Check if file exists: if not, create the FIFO. */ if (access(filename, F_OK) < 0) { if (mkfifo(filename, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) < 0) { syserror("Cannot create FIFO pipe."); return -1; } return 0; } /* We must be able to read and write the file. (only one direction is * necessary in croutonwebsocket, but croutonclip needs the other direction) */ if (access(filename, R_OK|W_OK) < 0) { error("%s exists, but not readable and writable.", filename); return -1; } if (stat(filename, &fstat) < 0) { syserror("Cannot stat FIFO pipe."); return -1; } if (!S_ISFIFO(fstat.st_mode)) { error("%s exists, but is not a FIFO pipe.", filename); return -1; } return 0; }
int find_nacl(int conn) { char argbuf[70], outbuf[256]; char* cut; int idx = 0, c; if ((c = read(conn, argbuf, sizeof(argbuf)-1)) < 0) { syserror("Failed to read arguments"); return -1; } argbuf[c] = 0; cut = strchr(argbuf, ' '); if (!cut) { error("No ' ' in findnacl arguments: %s.", argbuf); return -1; } *cut = 0; char *cmd = "croutonfindnacl"; char* args[] = {cmd, argbuf, cut + 1, NULL}; c = popen2(cmd, args, NULL, 0, outbuf, sizeof(outbuf)-1); if (c <= 0) { error("Error running helper"); return -1; } outbuf[c] = 0; /* Parse PID:file output */ cut = strchr(outbuf, ':'); if (!cut) { error("No ':' in helper reply: %s.", outbuf); return -1; } *cut = 0; char* endptr; long pid = strtol(outbuf, &endptr, 10); if(outbuf == endptr || *endptr != '\0') { error("Invalid pid: %s", outbuf); return -1; } char* file = cut+1; int ret = 0; int fd = -1; if (pid > 0) { if ((fd = open(file, O_RDWR)) < 0) syserror("Cannot open file %s", file); } if (send_pid_fd(conn, pid, fd) < 0) { syserror("FD-passing failed."); ret = -1; } close(fd); return ret; }
void TEXT_init(TEXT_t *l, char *filename, char *mode) { struct stat buf; if ((l->filename = strdup(filename))==NULL) syserror(errno,"strdup"); if ((l->file=fopen(l->filename, mode))==NULL) syserror(errno,l->filename); if (SETVBUF(l->file,NULL,_IOFBF,BUFSIZ>TEXT_BUFFER?BUFSIZ:TEXT_BUFFER)!=0) syserror(errno,"setvbuf"); if (stat(l->filename,&buf)==-1) syserror(errno,l->filename); l->filesize=buf.st_size; }
int proc_ioctl(struct tcb *tcp, int code, int arg) { int val; struct procfs_status status; if (entering(tcp)) return 0; switch (code) { case PIOCSTATUS: case PIOCWAIT: if (arg == 0) tprintf(", NULL"); else if (syserror(tcp)) tprintf(", %x", arg); else if (umove(tcp, arg, &status) < 0) tprintf(", {...}"); else { tprintf(", {state=%d, flags=", status.state); printflags(proc_status_flags, status.flags, "PF_???"); tprintf(", events="); printflags(proc_status_why, status.events, "S_???"); tprintf(", why="); printxval(proc_status_why, status.why, "S_???"); tprintf(", val=%lu}", status.val); } return 1; case PIOCBIS: tprintf(", "); printflags(proc_status_why, arg, "S_???"); return 1; return 1; case PIOCSFL: tprintf(", "); printflags(proc_status_flags, arg, "PF_???"); return 1; case PIOCGFL: if (syserror(tcp)) tprintf(", %#x", arg); else if (umove(tcp, arg, &val) < 0) tprintf(", {...}"); else { tprintf(", ["); printflags(proc_status_flags, val, "PF_???"); tprintf("]"); } return 1; default: /* ad naseum */ return 0; } }
void LMP_init(LMP_t *l, char *filename, char *mode) { struct stat buf; struct tm *ft; if ((l->filename = strdup(filename))==NULL) syserror(errno,"strdup"); if ((l->file=fopen(l->filename, mode))==NULL) syserror(errno,l->filename); if (SETVBUF(l->file,NULL,_IOFBF,BUFSIZ>MYBUFSIZE?BUFSIZ:MYBUFSIZE)!=0) syserror(errno,"setvbuf"); if (stat(l->filename,&buf)==-1) syserror(errno,l->filename); l->filesize=buf.st_size; ft=localtime(&buf.st_mtime); l->year=ft->tm_year; }
int NotifyCream(char *buffer, creamConnection_t *connection) { int retcod; struct pollfd fds[2]; if (connection->creamfilter == NULL) return -1; fds[0].fd = connection->socket_fd; fds[0].events = ( POLLOUT | POLLPRI | POLLERR | POLLHUP | POLLNVAL ) ; if(!connection->creamisconn){ return -1; } retcod = poll(fds, 1, bfunctions_poll_timeout); if (retcod < 0) { free_cream_connection(connection); do_log(debuglogfile, debug, 1, "Fatal Error:Poll error in NotifyCream errno:%d\n",errno); sysfatal("Poll error in NotifyCream: %r"); } else if ( retcod == 0 ) { do_log(debuglogfile, debug, 1, "Error:poll() timeout in NotifyCream\n"); syserror("poll() timeout in NotifyCream: %r"); return -1; } else if ( retcod > 0 ) { if (( fds[0].revents & ( POLLERR | POLLNVAL | POLLHUP) )){ switch (fds[0].revents){ case POLLNVAL: do_log(debuglogfile, debug, 1, "Error:poll() file descriptor error in NotifyCream\n"); syserror("poll() file descriptor error in NotifyCream: %r"); return -1; case POLLHUP: do_log(debuglogfile, debug, 1, "Connection closed in NotifyCream\n"); syserror("Connection closed in NotifyCream: %r"); return -1; case POLLERR: do_log(debuglogfile, debug, 1, "Error:poll() POLLERR in NotifyCream\n"); syserror("poll() POLLERR in NotifyCream: %r"); return -1; } } else { Writeline(connection->socket_fd, buffer, strlen(buffer)); do_log(debuglogfile, debug, 1, "Sent for Cream:%s",buffer); } } return 0; }
int scsi_ioctl(struct tcb *tcp, const unsigned int code, const long arg) { uint32_t iid; if (SG_IO != code) return RVAL_DECODED; if (entering(tcp)) { tprints(", "); if (!arg || umove(tcp, arg, &iid) < 0) { printaddr(arg); return RVAL_DECODED | 1; } else { return print_sg_io_req(tcp, iid, arg); } } else { if (!syserror(tcp)) { if (umove(tcp, arg, &iid) < 0) tprints(", ???"); else print_sg_io_res(tcp, iid, arg); } tprintf("}"); return RVAL_DECODED | 1; } }
static int do_adjtimex(struct tcb *tcp, long addr) { if (addr == 0) tprints("NULL"); else if (syserror(tcp) || !verbose(tcp)) tprintf("%#lx", addr); else if (tprint_timex(tcp, addr) < 0) tprints("{...}"); if (syserror(tcp)) return 0; tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval); if (tcp->auxstr) return RVAL_STR; return 0; }
/** * Sends an HB_RESP in response to an HB_REQ */ void send_hb_response(const struct sockaddr_in *src, int response) { unsigned char *packet; struct uftp_h *header; struct hb_resp_h *hbresp; int meslen; packet = calloc(sizeof(struct uftp_h) + sizeof(struct hb_resp_h), 1); if (packet == NULL) { syserror(0, 0, "calloc failed!"); exit(1); } header = (struct uftp_h *)packet; hbresp = (struct hb_resp_h *)(packet + sizeof(struct uftp_h)); header->uftp_id = UFTP_VER_NUM; header->func = HB_RESP; header->blsize = ntohs(sizeof(struct hb_resp_h)); hbresp->func = HB_RESP; hbresp->authenticated = response; if (response == HB_AUTH_CHALLENGE) { hbresp->nonce = htonl(down_nonce); } meslen = sizeof(struct uftp_h) + sizeof(struct hb_resp_h); if (nb_sendto(listener, packet, meslen, 0, (struct sockaddr *)src, sizeof(struct sockaddr_in)) == SOCKET_ERROR) { sockerror(0, 0, "Error sending HB_RESP"); } else { log(0, 0, "Sent HB_RESP to %s:%d", inet_ntoa(src->sin_addr), ntohs(src->sin_port)); } free(packet); }
int sys_shmat(struct tcb *tcp) { if (exiting(tcp)) { tprintf("%lu", tcp->u_arg[0]); if (indirect_ipccall(tcp)) { tprintf(", %#lx", tcp->u_arg[3]); tprints(", "); printflags(shm_flags, tcp->u_arg[1], "SHM_???"); } else { tprintf(", %#lx", tcp->u_arg[1]); tprints(", "); printflags(shm_flags, tcp->u_arg[2], "SHM_???"); } if (syserror(tcp)) return 0; if (indirect_ipccall(tcp)) { unsigned long raddr; if (umove(tcp, tcp->u_arg[2], &raddr) < 0) return RVAL_NONE; tcp->u_rval = raddr; } return RVAL_HEX; } return 0; }
static int decode_sockname(struct tcb *tcp) { int ulen, rlen; if (entering(tcp)) { printfd(tcp, tcp->u_arg[0]); tprints(", "); if (fetch_socklen(tcp, &ulen, tcp->u_arg[1], tcp->u_arg[2])) { set_tcb_priv_ulong(tcp, ulen); return 0; } else { printaddr(tcp->u_arg[1]); tprints(", "); printaddr(tcp->u_arg[2]); return RVAL_DECODED; } } ulen = get_tcb_priv_ulong(tcp); if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &rlen) < 0) { printaddr(tcp->u_arg[1]); tprintf(", [%d]", ulen); } else { decode_sockaddr(tcp, tcp->u_arg[1], ulen > rlen ? rlen : ulen); if (ulen != rlen) tprintf(", [%d->%d]", ulen, rlen); else tprintf(", [%d]", rlen); } return RVAL_DECODED; }
void printrusage(struct tcb *tcp, long addr) { struct rusage ru; if (!addr) tprints("NULL"); else if (syserror(tcp) || !verbose(tcp)) tprintf("%#lx", addr); else if (umove(tcp, addr, &ru) < 0) tprints("{...}"); else if (!abbrev(tcp)) { tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ", (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec, (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec); tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ", ru.ru_maxrss, ru.ru_ixrss); tprintf("ru_idrss=%lu, ru_isrss=%lu, ", ru.ru_idrss, ru.ru_isrss); tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ", ru.ru_minflt, ru.ru_majflt, ru.ru_nswap); tprintf("ru_inblock=%lu, ru_oublock=%lu, ", ru.ru_inblock, ru.ru_oublock); tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ", ru.ru_msgsnd, ru.ru_msgrcv); tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}", ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw); } else { tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}", (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec, (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec); } }
/** * Send out DONE messages specifiying active clients that haven't yet responded. * Returns 1 on success, 0 on fail */ int send_done(const struct finfo_t *finfo, int attempt, int pass, int section) { unsigned char *buf; struct uftp_h *header; struct done_h *done; uint32_t *addrlist; int rval; buf = calloc(mtu, 1); if (buf == NULL) { syserror(0, 0, "calloc failed!"); exit(1); } header = (struct uftp_h *)buf; done = (struct done_h *)(buf + sizeof(struct uftp_h)); addrlist = (uint32_t *)((char *)done + sizeof(struct done_h)); set_uftp_header(header, DONE, finfo, &receive_dest); done->func = DONE; done->file_id = htons(finfo->file_id); done->pass = pass; done->section = htons(section); rval = send_multiple(finfo, buf, DONE, attempt, addrlist, DEST_STATUS, &done->destcount, (keytype != KEY_NONE), &receive_dest, 0); free(buf); return rval; }
int sys_rt_sigprocmask(struct tcb *tcp) { sigset_t sigset; /* Note: arg[3] is the length of the sigset. */ if (entering(tcp)) { printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???"); tprints(", "); if (!tcp->u_arg[1]) tprints("NULL, "); else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0) tprintf("%#lx, ", tcp->u_arg[1]); else { printsigmask(&sigset, 1); tprints(", "); } } else { if (!tcp->u_arg[2]) tprints("NULL"); else if (syserror(tcp)) tprintf("%#lx", tcp->u_arg[2]); else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0) tprints("[?]"); else printsigmask(&sigset, 1); tprintf(", %lu", tcp->u_arg[3]); } return 0; }
/** * Send out DONE_CONF messages specifiying all completed clients. * Returns 1 on success, 0 on fail */ int send_doneconf(const struct finfo_t *finfo, int attempt) { unsigned char *buf; struct uftp_h *header; struct doneconf_h *doneconf; uint32_t *addrlist; int rval; if (finfo->file_id != 0) { return 1; } buf = calloc(mtu, 1); if (buf == NULL) { syserror(0, 0, "calloc failed!"); exit(1); } header = (struct uftp_h *)buf; doneconf = (struct doneconf_h *)(buf + sizeof(struct uftp_h)); addrlist = (uint32_t *)((char *)doneconf + sizeof(struct doneconf_h)); set_uftp_header(header, DONE_CONF, finfo, &receive_dest); doneconf->func = DONE_CONF; doneconf->file_id = htons(finfo->file_id); rval = send_multiple(finfo, buf, DONE_CONF, attempt, addrlist, DEST_DONE, &doneconf->destcount, (keytype != KEY_NONE), &receive_dest, 0); free(buf); return rval; }
static int do_pipe(struct tcb *tcp, int flags_arg) { if (exiting(tcp)) { if (syserror(tcp)) { tprintf("%#lx", tcp->u_arg[0]); } else { #if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64) int fds[2]; if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0) tprints("[...]"); else tprintf("[%u, %u]", fds[0], fds[1]); #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64) tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp)); #else tprintf("%#lx", tcp->u_arg[0]); #endif } if (flags_arg >= 0) { tprints(", "); printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); } } return 0; }
static int do_accept(struct tcb *tcp, int flags_arg) { if (entering(tcp)) { printfd(tcp, tcp->u_arg[0]); tprints(", "); return 0; } if (!tcp->u_arg[2]) tprintf("%#lx, NULL", tcp->u_arg[1]); else { int len; if (tcp->u_arg[1] == 0 || syserror(tcp) || umove(tcp, tcp->u_arg[2], &len) < 0) { tprintf("%#lx", tcp->u_arg[1]); } else { printsock(tcp, tcp->u_arg[1], len); } tprints(", "); printnum_int(tcp, tcp->u_arg[2], "%u"); } if (flags_arg >= 0) { tprints(", "); printflags(sock_type_flags, tcp->u_arg[flags_arg], "SOCK_???"); } return 0; }
int sys_sysinfo(struct tcb *tcp) { struct sysinfo si; if (exiting(tcp)) { if (syserror(tcp) || !verbose(tcp)) tprintf("%#lx", tcp->u_arg[0]); else if (umove(tcp, tcp->u_arg[0], &si) < 0) tprints("{...}"); else { tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ", (long) si.uptime, (long) si.loads[0], (long) si.loads[1], (long) si.loads[2]); tprintf("totalram=%lu, freeram=%lu, ", (long) si.totalram, (long) si.freeram); tprintf("sharedram=%lu, bufferram=%lu} ", (long) si.sharedram, (long) si.bufferram); tprintf("totalswap=%lu, freeswap=%lu, procs=%u}", (long) si.totalswap, (long) si.freeswap, (unsigned)si.procs); } } return 0; }
int sys_mincore(struct tcb *tcp) { if (entering(tcp)) { tprintf("%#lx, %lu, ", tcp->u_arg[0], tcp->u_arg[1]); } else { unsigned long i, len; char *vec = NULL; len = tcp->u_arg[1]; if (syserror(tcp) || tcp->u_arg[2] == 0 || (vec = malloc(len)) == NULL || umoven(tcp, tcp->u_arg[2], len, vec) < 0) tprintf("%#lx", tcp->u_arg[2]); else { tprints("["); for (i = 0; i < len; i++) { if (abbrev(tcp) && i >= max_strlen) { tprints("..."); break; } tprints((vec[i] & 1) ? "1" : "0"); } tprints("]"); } free(vec); } return 0; }
static int do_pipe(struct tcb *tcp, int flags_arg) { if (exiting(tcp)) { if (syserror(tcp)) { tprintf("%#lx", tcp->u_arg[0]); } else { #ifdef HAVE_GETRVAL2 if (flags_arg < 0) { tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp)); } else #endif { int fds[2]; if (umove(tcp, tcp->u_arg[0], &fds) < 0) tprintf("%#lx", tcp->u_arg[0]); else tprintf("[%u, %u]", fds[0], fds[1]); } } if (flags_arg >= 0) { tprints(", "); printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); } } return 0; }
int sys_shmat(struct tcb *tcp) { #ifdef LINUX unsigned long raddr; #endif /* LINUX */ if (exiting(tcp)) { tprintf("%lu", tcp->u_arg[0]); if (indirect_ipccall(tcp)) { tprintf(", %#lx", tcp->u_arg[3]); tprintf(", "); printflags(shm_flags, tcp->u_arg[1], "SHM_???"); } else { tprintf(", %#lx", tcp->u_arg[1]); tprintf(", "); printflags(shm_flags, tcp->u_arg[2], "SHM_???"); } if (syserror(tcp)) return 0; /* HPPA does not use an IPC multiplexer on Linux. */ #if defined(LINUX) && !defined(HPPA) if (umove(tcp, tcp->u_arg[2], &raddr) < 0) return RVAL_NONE; tcp->u_rval = raddr; #endif /* LINUX */ return RVAL_HEX; } return 0; }
static int do_sockname(struct tcb *tcp, int flags_arg) { if (entering(tcp)) { printfd(tcp, tcp->u_arg[0]); tprints(", "); return 0; } int len; if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) || umove(tcp, tcp->u_arg[2], &len) < 0) { printaddr(tcp->u_arg[1]); tprints(", "); printaddr(tcp->u_arg[2]); } else { printsock(tcp, tcp->u_arg[1], len); tprintf(", [%d]", len); } if (flags_arg >= 0) { tprints(", "); printflags(sock_type_flags, tcp->u_arg[flags_arg], "SOCK_???"); } return 0; }
/** * Generates an RSA private key with the given exponent and number of bits * and writes it to the given file (if specified). */ RSA_key_t gen_RSA_key(int bits, int exponent, const char *filename) { RSA_key_t rsa; FILE *f; if ((rsa = RSA_generate_key(bits ? bits : DEF_RSA_LEN, exponent, NULL, NULL)) == NULL) { log_ssl_err("couldn't generate rsa key"); return NULL; } if (strcmp(filename, "")) { if ((f = fopen(filename, "rb")) != NULL) { log(0, 0, "Private key file already exists, won't overwrite"); fclose(f); return NULL; } if ((f = fopen(filename, "wb")) == NULL) { syserror(0, 0, "failed to open key file"); return NULL; } if (!PEM_write_RSAPrivateKey(f, rsa, NULL, NULL, 0, NULL, NULL)) { log_ssl_err("couldn't write rsa private key"); fclose(f); return NULL; } fclose(f); } return rsa; }
static void printstatfs64(struct tcb *tcp, long addr) { struct statfs64 statbuf; if (syserror(tcp) || !verbose(tcp)) { tprintf("%#lx", addr); return; } if (umove(tcp, addr, &statbuf) < 0) { tprints("{...}"); return; } tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ", sprintfstype(statbuf.f_type), (unsigned long long)statbuf.f_bsize, (unsigned long long)statbuf.f_blocks, (unsigned long long)statbuf.f_bfree); tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}", (unsigned long long)statbuf.f_bavail, (unsigned long long)statbuf.f_files, (unsigned long long)statbuf.f_ffree, statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]); tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen); #ifdef _STATFS_F_FRSIZE tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize); #endif #ifdef _STATFS_F_FLAGS tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags); #endif tprints("}"); }
int sys_read(struct tcb *tcp) { struct socket_info sockinfo; if (entering(tcp)) { json_object_object_add(tcp->json, "fd", json_object_new_int((int)tcp->u_arg[0])); printfd(tcp, tcp->u_arg[0]); tprintf(", "); if (output_json) { if (get_socket_info(tcp->pid, (int) tcp->u_arg[0], &sockinfo) == 0) { append_to_json(tcp->json, &sockinfo); } else { json_object_object_add(tcp->json, "pid", json_object_new_int(tcp->pid)); } } } else { /* exiting... */ if (syserror(tcp)) { tprintf("%#lx", tcp->u_arg[1]); } else { /* no error */ if (output_json) { json_object_object_add(tcp->json, "content", json_object_new_string(readstr(tcp, tcp->u_arg[1], tcp->u_arg[2]))); json_object_object_add(tcp->json, "length", json_object_new_int(tcp->u_arg[2])); } else { printstr(tcp, tcp->u_arg[1], tcp->u_rval); } } tprintf(", %lu", tcp->u_arg[2]); } return 0; }
/* Read the pid of nacl_helper and get shm from findnacl daemon. * The socket fd is passed in and fd of nacl_helper is returned..*/ int recv_pid_fd(int conn) { int fd = -1; struct msghdr msg = { 0 }; struct iovec iov; struct cmsghdr *cmsg; long pid; char buf[CMSG_SPACE(sizeof(int))]; memset(buf, 0, sizeof(buf)); iov.iov_base = &pid; iov.iov_len = sizeof(pid); msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = buf; msg.msg_controllen = CMSG_SPACE(sizeof(int)); if (recvmsg(conn, &msg, 0) < 0) { syserror("Cannot get response from findnacl daemon."); return -1; } cmsg = CMSG_FIRSTHDR(&msg); if (cmsg) { if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { fd = *((int *)CMSG_DATA(cmsg)); } else { error("No fd is passed from findnacl daemon."); } } else { error("No fd is passed from findnacl daemon."); } return fd; }
/** * Returns the next key container for the current user */ const char *get_next_container() { static int flag = CRYPT_FIRST; static char *item = NULL; static int mlen = 0; int rval, len; if (flag == CRYPT_FIRST) { rval = CryptGetProvParam(base_prov, PP_ENUMCONTAINERS, NULL, &mlen, CRYPT_FIRST); if (!rval) { return NULL; } item = malloc(mlen); if (item == NULL) { syserror(0, 0, "malloc failed!"); exit(1); } } len = mlen; rval = CryptGetProvParam(base_prov, PP_ENUMCONTAINERS, item, &len, flag); if (!rval) { if (GetLastError() != ERROR_NO_MORE_ITEMS) { mserror("CryptGetProvParam failed"); } flag = CRYPT_FIRST; free(item); item = NULL; return NULL; } flag = CRYPT_NEXT; return item; }
/* * A write error has occurred; if the file being written was * the edited file then we consider it to have changed since it is * now likely scrambled. */ static void wrerror(void) { if (eq(file, savedfile) && edited) change(); syserror(); }