Certificate_Store_MacOS_Impl() : m_policy(SecPolicyCreateBasicX509()), m_system_roots(nullptr), m_system_chain(nullptr), m_keychains(nullptr) { check_success(SecKeychainOpen(system_roots, &m_system_roots.get()), "open system root certificates"); check_success(SecKeychainOpen(system_keychain, &m_system_chain.get()), "open system keychain"); check_notnull(m_system_roots, "open system root certificate chain"); check_notnull(m_system_chain, "open system certificate chain"); // m_keychains is merely a convenience list view into all open keychain // objects. This list is required in prepareQuery(). std::array<const void*, 2> keychains{{ m_system_roots.get(), m_system_chain.get() }}; m_keychains.assign( CFArrayCreate(kCFAllocatorDefault, keychains.data(), keychains.size(), &kCFTypeArrayCallBacks)); check_notnull(m_keychains, "initialize keychain array"); }
static void launch_tests(void) { char buf[1024]; int len, local, global, i; for (local = 0; local < 2; local++) { for (global = 0; global < 2; global++) { if (!local && !global) continue; launch_instruction_breakpoints(buf, local, global); } } for (len = 1; len <= sizeof(long); len <<= 1) { for (local = 0; local < 2; local++) { for (global = 0; global < 2; global++) { if (!local && !global) continue; launch_watchpoints(buf, BP_W, len, local, global); } } } for (len = 1; len <= sizeof(long); len <<= 1) { for (local = 0; local < 2; local++) { for (global = 0; global < 2; global++) { if (!local && !global) continue; launch_watchpoints(buf, BP_RW, len, local, global); } } } ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success("Test icebp"); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success("Test int 3 trap"); ptrace(PTRACE_CONT, child_pid, NULL, 0); }
char *read_mom_reply( int *local_errno, /* O */ struct tcp_chan *chan) { int rc; char *value = NULL; if (check_success(chan)) return(NULL); value = disrst(chan,&rc); if (rc != DIS_SUCCESS) { if (value != NULL) free(value); *local_errno = rc; return(NULL); } return(value); } /* END read_mom_reply() */
int check_nb(t_var *f, int *line, int choice, int *i) { int total; total = f->line[0] + f->line[1] + f->line[2] + f->line[3]; if ((total - choice) < 1 || (*line - choice) < 0 || choice == 0) { tputs(tgetstr("cl", NULL), 1, my_putchar); my_putstr("\033[01;31m"); my_putstr("You can't withdraw so many matches !\n"); my_putstr("\033[0m"); } else { *line -= choice; (*i)++; if (f->choice[1] == 1) { check_success(f); if (f->choice[2] == 1) easy_marienbad(f, total); else marienbad(f, total); } } total = f->line[0] + f->line[1] + f->line[2] + f->line[3]; return (total); }
Pos *run() { int done_flag = 0; Pos *current_pos; while(done_flag == 0) { if(isEmpty(queue) == 0) { free(current_pos); current_pos = dequeue(queue); if(check_success(current_pos) == 0) { enqueue(queue, addPos(current_pos->x, current_pos->y + 8, current_pos->nr_moves + 1)); //North enqueue(queue, addPos(current_pos->x, current_pos->y - 3, current_pos->nr_moves + 1)); //South enqueue(queue, addPos(current_pos->x - 6, current_pos->y, current_pos->nr_moves + 1)); //West enqueue(queue, addPos(current_pos->x + 5, current_pos->y, current_pos->nr_moves + 1)); //East } else { done_flag = 1; } }else { done_flag = 1; } //Prints when the search traverses into the next level of the tree if(nr_moves_changed != current_pos->nr_moves) { printf("nr_moves: %d\n", current_pos->nr_moves); nr_moves_changed = current_pos->nr_moves; } //No solution found, break. if(current_pos->nr_moves > 30) return current_pos; } return current_pos; }
int main() { nr_moves_changed = 0; init(); if(check_success(queue->front->pos) == 0) { Pos *pos = run(); printf("Det kravs minst %d promenader\n", pos->nr_moves); } else { printf("Du var ju redan framme..."); } return 0; }
static void launch_instruction_breakpoints(char *buf, int local, int global) { int i; for (i = 0; i < 4; i++) { set_breakpoint_addr(dummy_funcs[i], i); toggle_breakpoint(i, BP_X, 1, local, global, 1); ptrace(PTRACE_CONT, child_pid, NULL, 0); sprintf(buf, "Test breakpoint %d with local: %d global: %d", i, local, global); check_success(buf); toggle_breakpoint(i, BP_X, 1, local, global, 0); } }
/** * Searches certificates in all opened system keychains. Takes an optional * \p query that defines filter attributes to be searched for. That query * is amended by generic attributes for "certificate filtering". * * \param query a list of key-value pairs used for filtering * \returns an array with the resulting certificates or nullptr if * no matching certificate was found */ scoped_CFType<CFArrayRef> search(Query query = Query()) const { scoped_CFType<CFDictionaryRef> fullQuery( prepareQuery(std::move(query))); check_notnull(fullQuery, "create search query"); scoped_CFType<CFArrayRef> result(nullptr); auto status = SecItemCopyMatching(fullQuery.get(), (CFTypeRef*)&result.get()); if(errSecItemNotFound == status) { return scoped_CFType<CFArrayRef>(nullptr); // no matches } check_success(status, "look up certificate"); check_notnull(result, "look up certificate (invalid result value)"); return result; }
static void launch_watchpoints(char *buf, int mode, int len, int local, int global) { const char *mode_str; int i; if (mode == BP_W) mode_str = "write"; else mode_str = "read"; for (i = 0; i < 4; i++) { set_breakpoint_addr(&dummy_var[i], i); toggle_breakpoint(i, mode, len, local, global, 1); ptrace(PTRACE_CONT, child_pid, NULL, 0); sprintf(buf, "Test %s watchpoint %d with len: %d local: " "%d global: %d", mode_str, i, len, local, global); check_success(buf); toggle_breakpoint(i, mode, len, local, global, 0); } }
int do_mom( char *HPtr, int MOMPort, int CmdIndex) { int socket; int local_errno = 0; struct tcp_chan *chan = NULL; int rc; if ((socket = openrm(HPtr, MOMPort)) < 0) { /* FAILURE */ extern char TRMEMsg[]; fprintf(stderr, "cannot connect to MOM on node '%s', errno=%d (%s)\n", HPtr, errno, strerror(errno)); if (TRMEMsg[0] != '\0') { fprintf(stderr, " %s\n", TRMEMsg); } return(socket); } else if ((chan = DIS_tcp_setup(socket)) == NULL) { fprintf(stderr, "%s: can not allocate memory of socket buffers\n", __func__); return -1; } /* send protocol and version, plus how many queries we're sending */ if (QueryI == 0) QueryI = 1; if (start_dialogue(chan) != DIS_SUCCESS) { fprintf(stderr,"ERROR: Unable to write the number of queries to %s (errno=%d-%s)\n", HPtr, errno, strerror(errno)); send_command(chan,RM_CMD_CLOSE); DIS_tcp_cleanup(chan); return(-1); } if (IsVerbose == TRUE) { fprintf(stderr, "INFO: successfully connected to %s\n", HPtr); } switch (CmdIndex) { case momClear: { char tmpLine[1024]; char *Value; snprintf(tmpLine, 1024, "clearjob=%s", (JPtr != NULL) ? JPtr : "all"); if (send_command_str(chan, RM_CMD_REQUEST, tmpLine) != 0) { /* FAILURE */ fprintf(stderr,"ERROR: cannot request job clear on %s (errno=%d-%s)\n", HPtr, errno, strerror(errno)); send_command(chan,RM_CMD_CLOSE); return(-1); } if ((Value = (char *)read_mom_reply(&local_errno, chan)) == NULL) { /* FAILURE */ fprintf(stderr,"ERROR: job clear failed on %s (errno=%d - %s: %d - %s)\n", HPtr, errno, pbs_strerror(errno), local_errno, pbs_strerror(local_errno)); send_command(chan,RM_CMD_CLOSE); return(-1); } /* job cleared */ fprintf(stdout,"job clear request successful on %s\n", HPtr); free(Value); } /* END BLOCK (case momClear) */ break; case momShutdown: { if ((send_command(chan,RM_CMD_SHUTDOWN) != PBSE_NONE) || (check_success(chan) != PBSE_NONE)) { /* FAILURE */ fprintf(stderr,"ERROR: cannot shutdown mom daemon on %s (errno=%d-%s)\n", HPtr, errno, pbs_strerror(errno)); send_command(chan,RM_CMD_CLOSE); exit(EXIT_FAILURE); } fprintf(stdout, "shutdown request successful on %s\n", HPtr); } /* END BLOCK */ break; case momReconfig: { if ((send_command(chan,RM_CMD_CONFIG) != PBSE_NONE) || (check_success(chan) != PBSE_NONE)) { /* FAILURE */ fprintf(stderr,"ERROR: cannot reconfigure mom on %s (errno=%d-%s)\n", HPtr, errno, pbs_strerror(errno)); send_command(chan,RM_CMD_CLOSE); return(-1); } fprintf(stdout, "reconfig successful on %s\n", HPtr); } /* END BLOCK (case momReconfig) */ break; case momLayout: char *value; if (send_command(chan, RM_CMD_LAYOUT) != PBSE_NONE) { fprintf(stdout, "Layout command failed to send to mom\n"); return(-1); } if ((value = read_mom_reply(&local_errno, chan)) == NULL) { fprintf(stdout, "Could not read a layout reply from the mom\n"); return(-1); } else { fprintf(stdout, "%s", value); free(value); } break; case momQuery: default: { char *ptr; int rindex; char *Value; for (rindex = 0; rindex < QueryI; rindex++) { if (send_command_str(chan, RM_CMD_REQUEST, Query[rindex]) != 0) { fprintf(stderr,"ERROR: cannot add query for '%s' on %s (errno=%d-%s)\n", Query[rindex], HPtr, errno, pbs_strerror(errno)); } } for (rindex = 0;rindex < QueryI;rindex++) { if ((ptr = strchr(Query[rindex],'=')) != NULL) { *ptr = '\0'; } if ((Value = (char *)read_mom_reply(&local_errno, chan)) == NULL) { fprintf(stderr, "ERROR: query[%d] '%s' failed on %s (errno=%d - %s : %d - %s)\n", rindex, Query[rindex], HPtr, errno, pbs_strerror(errno), local_errno, pbs_strerror(local_errno)); return(-1); } else { if (!strncmp(Query[rindex], "diag", strlen("diag"))) { fprintf(stdout, "%s\n", Value); } else if (!strncmp(Query[rindex], "cycle", strlen("cycle"))) { fprintf(stdout, "mom %s successfully cycled %s\n", HPtr, Value); } else { fprintf(stdout, "%12s: %12s = '%s'\n", HPtr, Query[rindex], Value); } } free(Value); if (ptr != NULL) { *ptr = '='; } } /* END for (rindex) */ } /* END BLOCK (case momQuery) */ break; } /* END switch(CmdIndex) */ rc = diswsi(chan, RM_PROTOCOL); if (rc != DIS_SUCCESS) goto do_mom_fail; rc = diswsi(chan, RM_PROTOCOL_VER); if (rc != DIS_SUCCESS) goto do_mom_fail; rc = diswsi(chan, 1); if (rc != DIS_SUCCESS) goto do_mom_fail; /* send_command will free chan */ send_command(chan,RM_CMD_CLOSE); return(0); do_mom_fail: DIS_tcp_close(chan); return(rc); } /* END do_mom() */