static void buddy_idle_changed_cb(PurpleBuddy *buddy, gboolean old_idle, gboolean idle, void *data) { if (idle) { write_status(buddy, _("%s has become idle: %s (%s)")); } else { write_status(buddy, _("%s is no longer idle: %s (%s)")); } }
static void buddy_idle_changed_cb(PurpleBuddy *buddy, gboolean old_idle, gboolean idle, void *data) { if (purple_prefs_get_bool("/plugins/core/statenotify/notify_idle")) { if (idle) { write_status(buddy, _("%s has become idle.")); } else { write_status(buddy, _("%s is no longer idle.")); } } }
static int restore_sbuf(struct sbuf *sb, struct bu *arr, int a, int i, const char *tmppath1, const char *tmppath2, enum action act, const char *client, char status, struct cntr *p1cntr, struct cntr *cntr, struct config *cconf) { //logp("%s: %s\n", act==ACTION_RESTORE?"restore":"verify", sb->path); write_status(client, status, sb->path, p1cntr, cntr); if((sb->datapth && async_write(CMD_DATAPTH, sb->datapth, strlen(sb->datapth))) || async_write(CMD_STAT, sb->statbuf, sb->slen)) return -1; else if(sb->cmd==CMD_FILE || sb->cmd==CMD_ENC_FILE || sb->cmd==CMD_METADATA || sb->cmd==CMD_ENC_METADATA || sb->cmd==CMD_EFS_FILE) { return restore_file(arr, a, i, sb->datapth, sb->path, tmppath1, tmppath2, act, sb->endfile, sb->cmd, sb->winattr, cntr, cconf); } else { if(async_write(sb->cmd, sb->path, sb->plen)) return -1; // If it is a link, send what // it points to. else if(sbuf_is_link(sb)) { if(async_write(sb->cmd, sb->linkto, sb->llen)) return -1; } do_filecounter(cntr, sb->cmd, 0); } return 0; }
/* Print the BEGIN_SIGNING status message. If MD is not NULL it is used to retrieve the hash algorithms used for the message. */ void write_status_begin_signing (gcry_md_hd_t md) { if (md) { char buf[100]; size_t buflen; int i; /* We use a hard coded list of possible algorithms. Using other algorithms than specified by OpenPGP does not make sense anyway. We do this out of performance reasons: Walking all the 110 allowed Ids is not a good idea given the way the check is implemented in libgcrypt. Recall that the only use of this status code is to create the micalg algorithm for PGP/MIME. */ buflen = 0; for (i=1; i <= 11; i++) if (i < 4 || i > 7) if ( gcry_md_is_enabled (md, i) && buflen < DIM(buf) ) { snprintf (buf+buflen, DIM(buf) - buflen - 1, "%sH%d", buflen? " ":"",i); buflen += strlen (buf+buflen); } write_status_text ( STATUS_BEGIN_SIGNING, buf ); } else write_status ( STATUS_BEGIN_SIGNING ); }
static int print_err(int iErr) { write_status(_T("")); if (iErr == DWNL_E_LASTERROR) { if (GetLastError() == ERROR_SUCCESS) { /* File not found */ _ftprintf(stderr, _T("\nERROR: Download failed.\n")); } else { /* Display last error code */ _ftprintf(stderr, _T("\nERROR: %u\n"), GetLastError()); } } else { switch (iErr) { case DWNL_E_NEEDTARGETFILENAME: _ftprintf(stderr, _T("\nERROR: Cannot determine filename, please specify a destination file name.\n")); break; case DWNL_E_UNSUPPORTEDSCHEME: _ftprintf(stderr, _T("\nERROR: Unsupported protocol.\n")); break; } } return 1; }
int write_error(http_status status) { time_t curtime; char html_error[HTML_ERROR_LENGTH]; char last_modified[HEADER_LINE_LENGTH]; char content_length[HEADER_LINE_LENGTH]; /* maybe the error occured after some data was already written, so reset the buffer */ response_buffer_size = 0; /* send current time as lastmodified */ time(&curtime); strftime(last_modified, HEADER_LINE_LENGTH, DATE_TIME_FORMAT, gmtime(&curtime)); /* content body */ snprintf(html_error, HTML_ERROR_LENGTH, HTML_ERROR, VERSION, LISTEN_PORT); snprintf(content_length, HEADER_LINE_LENGTH, "%d", strlen(html_error)); return (write_status(status) && write_general_headers() && write_header(HEADER_CONTENT_TYPE, "text/html") && write_header(HEADER_CONTENT_LENGTH, content_length) && write_header(HEADER_LAST_MODIFIED, last_modified) && write_data("\r\n", 2) && write_data(html_error, strlen(html_error))); }
static int reap_and_check (void) { W_DEBUG ("waiting for a children to reap...\n"); int status; pid_t pid = waitpid (-1, &status, WNOHANG); if (pid == cmd_task.pid) { W_DEBUGC (" reaped cmd process $I\n", (unsigned) pid); write_status ("cmd exit $L $i\n", (unsigned long) pid, status); cmd_task.pid = NO_PID; /* * If exit-on-success was request AND the process exited ok, * then we do not want to respawn, but to gracefully shutdown. */ if (success_exit && WIFEXITED (status) && WEXITSTATUS (status) == 0) { W_DEBUGC (" cmd process ended successfully, will exit\n"); running = 0; } else { task_action_queue (&cmd_task, A_START); } return status; } else if (log_enabled && pid == log_task.pid) { W_DEBUGC (" reaped log process $I\n", (unsigned) pid); write_status ("log exit $L $i\n", (unsigned long) pid, status); log_task.pid = NO_PID; task_action_queue (&log_task, A_START); } else { W_DEBUGC (" reaped unknown process $I", (unsigned) pid); } /* * For cases where a return status is not meaningful (PIDs other than * that of the command being run) just return some invalid return code * value. */ return -1; }
static void set_capability(void) { static char buffer[1024]; memset(buffer, 0, sizeof(buffer)); snprintf(buffer, sizeof(buffer) - 1, "MAC_FOR_CAPABILITY::%s=enforcing\n", capability); write_status(buffer); }
void fifo_tick(struct bot *bot) { status_fifo = open("status", O_WRONLY | O_NDELAY); if (status_fifo != -1) { write_status(bot); close(status_fifo); } status_fifo = 0; }
void encode_crypt_files(int nfiles, char **files, STRLIST remusr) { int rc = 0; if (opt.outfile) { log_error(_("--output doesn't work for this command\n")); return; } if (!nfiles) { char line[2048]; unsigned int lno = 0; while ( fgets(line, DIM(line), stdin) ) { lno++; if (!*line || line[strlen(line)-1] != '\n') { log_error("input line %u too long or missing LF\n", lno); return; } line[strlen(line)-1] = '\0'; print_file_status(STATUS_FILE_START, line, 2); if ( (rc = encode_crypt(line, remusr, 0)) ) log_error("encryption of `%s' failed: %s\n", print_fname_stdin(line), g10_errstr(rc) ); write_status( STATUS_FILE_DONE ); iobuf_ioctl( NULL, 2, 0, NULL); /* Invalidate entire cache. */ } } else { while (nfiles--) { print_file_status(STATUS_FILE_START, *files, 2); if ( (rc = encode_crypt(*files, remusr, 0)) ) log_error("encryption of `%s' failed: %s\n", print_fname_stdin(*files), g10_errstr(rc) ); write_status( STATUS_FILE_DONE ); iobuf_ioctl( NULL, 2, 0, NULL); /* Invalidate entire cache. */ files++; } } }
static void buddy_status_changed_cb(PurpleBuddy *buddy, PurpleStatus *old_status, PurpleStatus *status, void *data) { g_return_if_fail(buddy != NULL); g_return_if_fail(status != NULL); write_status(buddy, NULL); }
void encrypt_crypt_files (ctrl_t ctrl, int nfiles, char **files, strlist_t remusr) { int rc = 0; if (opt.outfile) { log_error(_("--output doesn't work for this command\n")); return; } if (!nfiles) { char line[2048]; unsigned int lno = 0; while ( fgets(line, DIM(line), stdin) ) { lno++; if (!*line || line[strlen(line)-1] != '\n') { log_error("input line %u too long or missing LF\n", lno); return; } line[strlen(line)-1] = '\0'; print_file_status(STATUS_FILE_START, line, 2); rc = encrypt_crypt (ctrl, -1, line, remusr, 0, NULL, -1); if (rc) log_error ("encryption of '%s' failed: %s\n", print_fname_stdin(line), gpg_strerror (rc) ); write_status( STATUS_FILE_DONE ); } } else { while (nfiles--) { print_file_status(STATUS_FILE_START, *files, 2); if ( (rc = encrypt_crypt (ctrl, -1, *files, remusr, 0, NULL, -1)) ) log_error("encryption of '%s' failed: %s\n", print_fname_stdin(*files), gpg_strerror (rc) ); write_status( STATUS_FILE_DONE ); files++; } } }
static void update_status_bits(struct kcs_bmc *kcs_bmc, u8 mask, u8 val) { u8 tmp = read_status(kcs_bmc); tmp &= ~mask; tmp |= val & mask; write_status(kcs_bmc, tmp); }
static void buddy_status_changed_cb(PurpleBuddy *buddy, PurpleStatus *old_status, PurpleStatus *status, void *data) { gboolean available, old_available; if (!purple_status_is_exclusive(status) || !purple_status_is_exclusive(old_status)) return; available = purple_status_is_available(status); old_available = purple_status_is_available(old_status); if (purple_prefs_get_bool("/plugins/core/statenotify/notify_away")) { if (available && !old_available) write_status(buddy, _("%s is no longer away.")); else if (!available && old_available) write_status(buddy, _("%s has gone away.")); } }
static void CBindStatusCallback_UpdateProgress(CBindStatusCallback *This) { /* FIXME: better output */ if (This->Size != 0) { UINT Percentage; Percentage = (UINT)((This->Progress * 100) / This->Size); if (Percentage > 99) Percentage = 99; write_status(_T("%2d%% (%I64u bytes downloaded)"), Percentage, This->Progress); } else { /* Unknown size */ write_status(_T("%I64u bytes downloaded"), This->Progress); } }
int do_delete_server(struct asfd *asfd, struct sdirs *sdirs, struct cntr *cntr, const char *cname, const char *backup, const char *manual_delete) { int ret=-1; int found=0; unsigned long bno=0; struct bu *bu=NULL; struct bu *bu_list=NULL; logp("in do_delete\n"); if(bu_get_list(sdirs, &bu_list) || write_status(CNTR_STATUS_DELETING, NULL, cntr)) goto end; if(backup && *backup) bno=strtoul(backup, NULL, 10); for(bu=bu_list; bu; bu=bu->next) { if(!backup || !*backup) continue; if(!found && (!strcmp(bu->timestamp, backup) || bu->bno==bno)) { if(bu->flags & BU_DELETABLE) { found=1; if(asfd->write_str(asfd, CMD_GEN, "ok") || delete_backup(sdirs, cname, bu, manual_delete)) goto end; } else { asfd->write_str(asfd, CMD_ERROR, "backup not deletable"); goto end; } break; } } if(backup && *backup && !found) { asfd->write_str(asfd, CMD_ERROR, "backup not found"); goto end; } ret=0; end: bu_list_free(&bu_list); return ret; }
/** * Display inventory items. */ void inventory () { int old_fg, old_bg; int n; /* screen is white with black text */ old_fg = game.color_fg; old_bg = game.color_bg; game.color_fg = 0; game.color_bg = 15; clear_screen (game.color_bg); print_text (YOUHAVE_MSG, 0, YOUHAVE_X, YOUHAVE_Y, 40, STATUS_FG, STATUS_BG); /* FIXME: doesn't check if objects overflow off screen... */ intobj = malloc (4 + game.num_objects); memset(intobj, 0, (4 + game.num_objects)); n = show_items (); if (getflag (F_status_selects_items)) { print_text (SELECT_MSG, 0, SELECT_X, SELECT_Y, 40, STATUS_FG, STATUS_BG); } else { print_text (ANY_KEY_MSG, 0, ANY_KEY_X, ANY_KEY_Y, 40, STATUS_FG, STATUS_BG); } flush_screen (); /* If flag 13 is set, we want to highlight & select an item. * opon selection, put objnum in var 25. Then on esc put in * var 25 = 0xff. */ if (getflag (F_status_selects_items)) select_items (n); free (intobj); if (!getflag (F_status_selects_items)) wait_any_key(); clear_screen (0); write_status (); show_pic (); game.color_fg = old_fg; game.color_bg = old_bg; game.has_prompt = 0; flush_lines (game.line_user_input, 24); }
static void handle_signal (int signum) { W_DEBUG ("handle signal $i ($s)\n", signum, signal_to_name (signum)); /* Receiving INT/TERM signal will stop gracefully */ if (signum == SIGINT || signum == SIGTERM) { running = 0; return; } /* Handle CHLD: check children */ if (signum == SIGCHLD) { check_child = 1; return; } /* * If we have a maximum time to run the process, and we receive SIGALRM, * then the timeout was reached. As per signal(7) it is safe to kill(2) * the process from a signal handler, so we do that and then mark it for * respawning. */ if (cmd_timeout && signum == SIGALRM) { write_status ("cmd timeout $L\n", (unsigned long) cmd_task.pid); task_action (&cmd_task, A_STOP); task_action_queue (&cmd_task, A_START); alarm (cmd_timeout); return; } unsigned i = 0; while (forward_signals[i].code != NO_SIGNAL) { if (signum == forward_signals[i++].code) break; } if (signum != NO_SIGNAL) { /* Try to forward signals */ if (cmd_signals) { W_DEBUGC (" delayed signal $i for cmd process\n", signum); task_action_queue (&cmd_task, A_SIGNAL); task_signal_queue (&cmd_task, signum); } if (log_signals && log_enabled) { W_DEBUGC (" delayed signal $i for log process\n", signum); task_action_queue (&log_task, A_SIGNAL); task_signal_queue (&log_task, signum); } } }
static #endif int do_list_server_work( int list_server_callback(const char *fullpath)) { int ret=-1; int found=0; //logp("in do_list_server\n"); if(write_status(CNTR_STATUS_LISTING, NULL, cntr)) goto end; switch(list_mode) { case LIST_MODE_BACKUPS: if((found=list_all_backups())<0) goto end; break; case LIST_MODE_CONTENTS_ONE: if((found=list_contents_one(list_server_callback))<0) goto end; break; case LIST_MODE_CONTENTS_MANY: if((found=list_contents_many(list_server_callback))<0) goto end; break; } if(!found) { if(list_mode==LIST_MODE_BACKUPS) { asfd_write_wrapper_str(asfd, CMD_MESSAGE, "no backups"); // Success. } else { asfd_write_wrapper_str(asfd, CMD_MESSAGE, "backup not found"); goto end; } } ret=0; end: bu_list_free(&bu_list); return ret; }
/**************** * Check the secret key * Ask up to 3 (or n) times for a correct passphrase * If n is negative, disable the key info prompt and make n=abs(n) */ int check_secret_key( PKT_secret_key *sk, int n ) { int rc = gpg_error (GPG_ERR_BAD_PASSPHRASE); int i,mode; if (sk && sk->is_protected && sk->protect.s2k.mode == 1002) return 0; /* Let the scdaemon handle this. */ if(n<0) { n=abs(n); mode=1; } else mode=0; if( n < 1 ) n = 3; /* Use the default value */ for(i=0; i < n && gpg_err_code (rc) == GPG_ERR_BAD_PASSPHRASE; i++ ) { int canceled = 0; const char *tryagain = NULL; if (i) { tryagain = N_("Invalid passphrase; please try again"); log_info (_("%s ...\n"), _(tryagain)); } rc = do_check( sk, tryagain, mode, &canceled ); if ( gpg_err_code (rc) == GPG_ERR_BAD_PASSPHRASE && is_status_enabled () ) { u32 kid[2]; char buf[50]; keyid_from_sk( sk, kid ); sprintf(buf, "%08lX%08lX", (ulong)kid[0], (ulong)kid[1]); write_status_text( STATUS_BAD_PASSPHRASE, buf ); } if( have_static_passphrase() || canceled) break; } if( !rc ) write_status( STATUS_GOOD_PASSPHRASE ); return rc; }
static int verify_one_file (ctrl_t ctrl, const char *name ) { IOBUF fp; armor_filter_context_t *afx = NULL; progress_filter_context_t *pfx = new_progress_context (); int rc; print_file_status( STATUS_FILE_START, name, 1 ); fp = iobuf_open(name); if (fp) iobuf_ioctl (fp, IOBUF_IOCTL_NO_CACHE, 1, NULL); if (fp && is_secured_file (iobuf_get_fd (fp))) { iobuf_close (fp); fp = NULL; gpg_err_set_errno (EPERM); } if( !fp ) { rc = gpg_error_from_syserror (); log_error(_("can't open '%s': %s\n"), print_fname_stdin(name), strerror (errno)); print_file_status( STATUS_FILE_ERROR, name, 1 ); goto leave; } handle_progress (pfx, fp, name); if( !opt.no_armor ) { if( use_armor_filter( fp ) ) { afx = new_armor_context (); push_armor_filter (afx, fp); } } rc = proc_signature_packets (ctrl, NULL, fp, NULL, name ); iobuf_close(fp); write_status( STATUS_FILE_DONE ); reset_literals_seen(); leave: release_armor_context (afx); release_progress_context (pfx); return rc; }
static int restore_sbuf(struct asfd *asfd, struct sbuf *sb, enum action act, enum cstat_status status, struct conf *conf, int *need_data) { //logp("%s: %s\n", act==ACTION_RESTORE?"restore":"verify", sb->path.buf); if(write_status(status, sb->path.buf, conf)) return -1; if(asfd->write(asfd, &sb->attr) || asfd->write(asfd, &sb->path)) return -1; if(sbuf_is_link(sb) && asfd->write(asfd, &sb->link)) return -1; if(sb->burp2->bstart) { // This will restore directory data on Windows. struct blk *b=NULL; struct blk *n=NULL; b=sb->burp2->bstart; while(b) { struct iobuf wbuf; iobuf_set(&wbuf, CMD_DATA, b->data, b->length); if(asfd->write(asfd, &wbuf)) return -1; n=b->next; blk_free(&b); b=n; } sb->burp2->bstart=sb->burp2->bend=NULL; } switch(sb->path.cmd) { case CMD_FILE: case CMD_ENC_FILE: case CMD_METADATA: case CMD_ENC_METADATA: case CMD_EFS_FILE: *need_data=1; return 0; default: cntr_add(conf->cntr, sb->path.cmd, 0); return 0; } }
/* If RC is not 0, write an appropriate status message. */ static void status_sc_op_failure (int rc) { switch (gpg_err_code (rc)) { case 0: break; case GPG_ERR_CANCELED: write_status_text (STATUS_SC_OP_FAILURE, "1"); break; case GPG_ERR_BAD_PIN: write_status_text (STATUS_SC_OP_FAILURE, "2"); break; default: write_status (STATUS_SC_OP_FAILURE); break; } }
/* Request a string from the client over the command-fd. If GETBOOL is set the function returns a static string (do not free) if the netered value was true or NULL if the entered value was false. */ static char * do_get_from_fd ( const char *keyword, int hidden, int getbool ) { int i, len; char *string; if (statusfp != stdout) fflush (stdout); write_status_text (getbool? STATUS_GET_BOOL : hidden? STATUS_GET_HIDDEN : STATUS_GET_LINE, keyword); for (string = NULL, i = len = 200; ; i++ ) { if (i >= len-1 ) { char *save = string; len += 100; string = hidden? xmalloc_secure ( len ) : xmalloc ( len ); if (save) memcpy (string, save, i ); else i = 0; } /* Fixme: why not use our read_line function here? */ if ( myread( opt.command_fd, string+i, 1) != 1 || string[i] == '\n' ) break; else if ( string[i] == CONTROL_D ) { /* Found ETX - Cancel the line and return a sole ETX. */ string[0] = CONTROL_D; i = 1; break; } } string[i] = 0; write_status (STATUS_GOT_IT); if (getbool) /* Fixme: is this correct??? */ return (string[0] == 'Y' || string[0] == 'y') ? "" : NULL; return string; }
/* * Function: write_debug * Description: * Print a standardly formatted debug output line. * There is a standard 'header' line format that can be generated * that will look something like: * Debug LIBSPMITTY -- "util.c", line 80 * Debug LIBSPMITTY -- "util.c", line 95 * And you can print just data lines like: * x = 32 * Scope: PUBLIC * Parameters: * dest - [RO] * [LOG - write only to the log file * SCR - write only to the display * LOGSCR - write to both the file and display] * debug_flag - Is debug actually turned on? If not - nothing is * printed. * who_called - A caller can use this to identify where this * debug output is coming from (e.g. each library and app * can have its own tag to easily distinguish where output * is coming from). * If who_called is NULL, then the header line of * output is not printed, and only the data line from the * format/var args is printed. * file_name - name of file the debug output request was called from. * Use macro __FILE__. * line_number - line number the debug output request was called from. * Use macro __LINE__. * format - [RO] * [LEVEL0 - base level message * LEVEL1 - first level message * LEVEL2 - second level message * LEVEL3 - third level message * CONTINUE - message continuation from preceding message * LISTITEM - item type message * FMTPARTIAL - part of a message (more to come)] * format of the message (used by the formatting routine) * fmtstr - format string to print any message you want. * Used to pass to vfprintf. * ... - var args to be used with format above to pass to vfprintf. * Return: none * Globals: none * Notes: * The defines, DEBUG_LOC and DEBUG_LOC_NOHD may be useful * to use as parameters when calling this routine. */ void write_debug(u_char dest, int debug_flag, char *who_called, char *file_name, int line_number, u_int format, char *fmtstr, ...) { va_list ap; char buf[MAXPATHLEN + 1] = ""; int old_trace_level; if (!debug_flag) return; old_trace_level = get_trace_level(); (void) set_trace_level(1); /* * if they specified a 'who_called', then * print first debug info line with who_called, function name, * file name, line number, etc... * * if no 'who_called', then * don't print first line with debug info. * i.e. so we can end up with debug output like: * Debug LIBSPMITTY -- "util.c", line 80: main() * x = 32 * y = 32 */ if (who_called) { (void) write_status(dest, LEVEL0, "Debug %s -- \"%s\", line %d", who_called, file_name ? file_name : "", line_number); } if (fmtstr) { va_start(ap, fmtstr); (void) vsprintf(buf, fmtstr, ap); _write_message(dest, STATMSG, format, buf); va_end(ap); } (void) set_trace_level(old_trace_level); }
static int restore_sbuf(struct asfd *asfd, struct sbuf *sb, struct bu *bu, enum action act, struct sdirs *sdirs, enum cntr_status cntr_status, struct conf **cconfs, struct sbuf *need_data, const char *manifest, struct slist *slist) { //printf("%s: %s\n", act==ACTION_RESTORE?"restore":"verify", sb->path.buf); if(write_status(cntr_status, sb->path.buf, get_cntr(cconfs))) return -1; if(sb->path.cmd==CMD_HARD_LINK) { struct f_link *lp=NULL; struct f_link **bucket=NULL; if((lp=linkhash_search(&sb->statp, &bucket))) { // It is in the list of stuff that is in the manifest, // but was skipped on this restore. // Need to go through the manifest from the beginning, // and substitute in the data to restore to this // location. return hard_link_substitution(asfd, sb, lp, bu, act, sdirs, cntr_status, cconfs, manifest, slist); // FIX THIS: Would be nice to remember the new link // location so that further hard links would link to // it instead of doing the hard_link_substitution // business over again. } } if(get_protocol(cconfs)==PROTO_1) { return restore_sbuf_protocol1(asfd, sb, bu, act, sdirs, cntr_status, cconfs); } else { return restore_sbuf_protocol2(asfd, sb, act, cntr_status, get_cntr(cconfs), need_data); } }
static void bind_key_callback(void *k) { int key = (int)k; int b; bound_to_1 = key; if (key == 2) { bound_to_1 = 0; input_mode = s9_input_switch_input_mode(); input_mode_show_counter = 60; // counted in cibyl_timer ticks } if (key == 3) { b = getflag(F_sound_on); setflag (F_sound_on, !b); write_status(); } }
static void flush_headers(slash_context_t* ctx) { #ifdef SL_TEST /* don't write the headers in testing mode */ return; #endif int status; sl_response_key_value_t* headers; size_t header_count, i; if(!ctx->headers_sent) { int content_type_sent = 0; ctx->headers_sent = 1; status = sl_response_get_status(ctx->vm); write_status(ctx, status); headers = sl_response_get_headers(ctx->vm, &header_count); for(i = 0; i < header_count; i++) { if(!content_type_sent && strcasecmp("Content-Type", headers[i].name) == 0) { content_type_sent = 1; } write_header(ctx, headers[i].name, headers[i].value); } if(!content_type_sent) { write_header(ctx, "Content-Type", "text/html; charset=utf-8"); } /* terminate headers */ ctx->api->write_out(ctx->api, SAPI_CGI_HEADER_SEPARATOR, SAPI_CGI_HEADER_SEPARATOR_LENGTH); } }
static int get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid ) { int rc; gcry_mpi_t plain_dek = NULL; byte *frame = NULL; unsigned int n; size_t nframe; u16 csum, csum2; int card = 0; if (sk->is_protected && sk->protect.s2k.mode == 1002) { /* Note, that we only support RSA for now. */ #ifdef ENABLE_CARD_SUPPORT unsigned char *rbuf; size_t rbuflen; char *snbuf; unsigned char *indata = NULL; size_t indatalen; snbuf = serialno_and_fpr_from_sk (sk->protect.iv, sk->protect.ivlen, sk); if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &indata, &indatalen, enc->data[0])) BUG (); rc = agent_scd_pkdecrypt (snbuf, indata, indatalen, &rbuf, &rbuflen); xfree (snbuf); xfree (indata); if (rc) goto leave; frame = rbuf; nframe = rbuflen; card = 1; #else rc = gpg_error (GPG_ERR_NOT_SUPPORTED); goto leave; #endif /*!ENABLE_CARD_SUPPORT*/ } else { rc = pk_decrypt (sk->pubkey_algo, &plain_dek, enc->data, sk->skey ); if( rc ) goto leave; if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &frame, &nframe, plain_dek)) BUG(); gcry_mpi_release (plain_dek); plain_dek = NULL; } /* Now get the DEK (data encryption key) from the frame * * Old versions encode the DEK in in this format (msb is left): * * 0 1 DEK(16 bytes) CSUM(2 bytes) 0 RND(n bytes) 2 * * Later versions encode the DEK like this: * * 0 2 RND(n bytes) 0 A DEK(k bytes) CSUM(2 bytes) * * (mpi_get_buffer already removed the leading zero). * * RND are non-zero randow bytes. * A is the cipher algorithm * DEK is the encryption key (session key) with length k * CSUM */ if (DBG_CIPHER) log_printhex ("DEK frame:", frame, nframe ); n=0; if (!card) { if( n + 7 > nframe ) { rc = G10ERR_WRONG_SECKEY; goto leave; } if( frame[n] == 1 && frame[nframe-1] == 2 ) { log_info(_("old encoding of the DEK is not supported\n")); rc = G10ERR_CIPHER_ALGO; goto leave; } if( frame[n] != 2 ) /* somethink is wrong */ { rc = G10ERR_WRONG_SECKEY; goto leave; } for(n++; n < nframe && frame[n]; n++ ) /* skip the random bytes */ ; n++; /* and the zero byte */ } if( n + 4 > nframe ) { rc = G10ERR_WRONG_SECKEY; goto leave; } dek->keylen = nframe - (n+1) - 2; dek->algo = frame[n++]; if( dek->algo == CIPHER_ALGO_IDEA ) write_status(STATUS_RSA_OR_IDEA); rc = openpgp_cipher_test_algo (dek->algo); if( rc ) { if( !opt.quiet && gpg_err_code (rc) == GPG_ERR_CIPHER_ALGO ) { log_info(_("cipher algorithm %d%s is unknown or disabled\n"), dek->algo, dek->algo == CIPHER_ALGO_IDEA? " (IDEA)":""); if(dek->algo==CIPHER_ALGO_IDEA) idea_cipher_warn (0); } dek->algo = 0; goto leave; } if ( dek->keylen != openpgp_cipher_get_algo_keylen (dek->algo) ) { rc = GPG_ERR_WRONG_SECKEY; goto leave; } /* copy the key to DEK and compare the checksum */ csum = frame[nframe-2] << 8; csum |= frame[nframe-1]; memcpy( dek->key, frame+n, dek->keylen ); for( csum2=0, n=0; n < dek->keylen; n++ ) csum2 += dek->key[n]; if( csum != csum2 ) { rc = G10ERR_WRONG_SECKEY; goto leave; } if( DBG_CIPHER ) log_printhex ("DEK is:", dek->key, dek->keylen ); /* check that the algo is in the preferences and whether it has expired */ { PKT_public_key *pk = NULL; KBNODE pkb = get_pubkeyblock (keyid); if( !pkb ) { rc = -1; log_error("oops: public key not found for preference check\n"); } else if(pkb->pkt->pkt.public_key->selfsigversion > 3 && dek->algo != CIPHER_ALGO_3DES && !opt.quiet && !is_algo_in_prefs( pkb, PREFTYPE_SYM, dek->algo )) log_info (_("WARNING: cipher algorithm %s not found in recipient" " preferences\n"), openpgp_cipher_algo_name (dek->algo)); if (!rc) { KBNODE k; for (k=pkb; k; k = k->next) { if (k->pkt->pkttype == PKT_PUBLIC_KEY || k->pkt->pkttype == PKT_PUBLIC_SUBKEY){ u32 aki[2]; keyid_from_pk(k->pkt->pkt.public_key, aki); if (aki[0]==keyid[0] && aki[1]==keyid[1]) { pk = k->pkt->pkt.public_key; break; } } } if (!pk) BUG (); if ( pk->expiredate && pk->expiredate <= make_timestamp() ) { log_info(_("NOTE: secret key %s expired at %s\n"), keystr(keyid), asctimestamp( pk->expiredate) ); } } if ( pk && pk->is_revoked ) { log_info( _("NOTE: key has been revoked") ); log_printf ("\n"); show_revocation_reason( pk, 1 ); } release_kbnode (pkb); rc = 0; } leave: gcry_mpi_release (plain_dek); xfree (frame); return rc; }
int action_osdp_RAW (OSDP_CONTEXT *ctx, OSDP_MSG *msg) { /* action_osdp_RAW */ int bits; int processed; unsigned char *raw_data; long int sample_1 [4]; int status; status = ST_OK; osdp_conformance.rep_raw.test_status = OCONFORM_EXERCISED; processed = 0; raw_data = msg->data_payload + 4; /* this processes an osdp_RAW. byte 0=rdr, b1=format, 2-3 are length (2=lsb) */ bits = *(msg->data_payload+2) + ((*(msg->data_payload+3))<<8); ctx->last_raw_read_bits = bits; { int octets; octets = (bits+7)/8; if (octets > sizeof (ctx->last_raw_read_data)) octets = sizeof (ctx->last_raw_read_data); memcpy (ctx->last_raw_read_data, raw_data, octets); }; status = write_status (ctx); if (bits EQUALS 26) { fprintf (ctx->log, "CARD DATA (%d bits):", bits); fprintf (ctx->log, " %02x-%02x-%02x-%02x\n", *(raw_data+0), *(raw_data+1), *(raw_data+2), *(raw_data+3)); processed = 1; }; if (bits EQUALS 75) { int i; unsigned char *p; long int tmp1_l; p = (unsigned char *)&(sample_1 [0]); for (i=0; i<10; i++) *(p+i) = *(raw_data+i); tmp1_l = *(long int *)(raw_data); sample_1 [0] = tmp1_l; status = fasc_n_75_to_string (tlogmsg, sample_1); fprintf (ctx->log, "CARD DATA (%d bits):\n%s\n", bits, tlogmsg); processed = 1; }; if (!processed) { unsigned d; int i; char hstr [1024]; int octet_count; char tstr [32]; hstr [0] = 0; fprintf (stderr, "Raw Unknown:"); octet_count = (bits+7)/8; for (i=0; i<octet_count; i++) { d = *(unsigned char *)(msg->data_payload+4+i); fprintf (stderr, " %02x", d); sprintf (tstr, " %02x", d); strcat (hstr, tstr); }; fprintf (stderr, "\n"); fprintf (ctx->log, "Unknown RAW CARD DATA (%d. bits) first byte %02x\n %s\n", bits, *(msg->data_payload+4), hstr); processed = 1; }; return (status); } /* action_osdp_RAW */