void mowgli_mutex_destroy(mowgli_mutex_t *mutex) { return_if_fail(mutex != NULL); mowgli_mutex_uninit(mutex); mowgli_free(mutex); }
int irc_prefix_destroy(irc_prefix_t *pfx) { if (pfx == NULL) return -1; mowgli_free(pfx); return 0; }
void mowgli_ioevent_destroy(mowgli_ioevent_handle_t *self) { return_if_fail(self != NULL); #if defined(HAVE_EPOLL_CTL) || defined(HAVE_PORT_CREATE) close(self->impldata); #endif mowgli_free(self); }
void mowgli_helper_destroy(mowgli_eventloop_t *eventloop, mowgli_eventloop_helper_proc_t *helper) { return_if_fail(eventloop != NULL); return_if_fail(helper != NULL); mowgli_process_kill(helper->child); mowgli_pollable_destroy(eventloop, helper->pfd); close(helper->fd); mowgli_free(helper); }
static void mowgli_config_file_entry_free(mowgli_config_file_entry_t *ceptr) { mowgli_config_file_entry_t *nptr; for (; ceptr; ceptr = nptr) { nptr = ceptr->next; if (ceptr->entries) mowgli_config_file_entry_free(ceptr->entries); /* ce_varname and ce_vardata are inside cf_mem */ mowgli_free(ceptr); } }
void mowgli_program_opts_parse(const mowgli_program_opts_t *opts, size_t opts_size, int *argc, char ***argv) { mowgli_getopt_option_t *g_opts; const char *shortops; int c; size_t i; int opt_index; return_if_fail(opts != NULL); return_if_fail(opts_size > 0); return_if_fail(argc != NULL); return_if_fail(argv != NULL); g_opts = mowgli_program_opts_convert(opts, opts_size); shortops = mowgli_program_opts_compute_optstr(opts, opts_size); for (;;) { const mowgli_program_opts_t *opt = NULL; c = mowgli_getopt_long(*argc, *argv, shortops, g_opts, &opt_index); if (c == -1) break; switch (c) { case 0: /* long-option was provided, resolve it. */ opt = &opts[g_opts[opt_index].iflag]; break; default: for (i = 0; i < opts_size; i++) if (opts[i].smallopt == c) { opt = &opts[i]; break; } break; } mowgli_program_opts_dispatch(opt, mowgli_optarg); } mowgli_free(g_opts); }
int main(int argc, const char **argv) { BIO *in; EC_KEY *eckey; char challenge[BUFSIZE]; const unsigned char *workbuf_p; unsigned char *sig_buf, *sig_buf_p; size_t len; unsigned int buf_len, i; if (argv[1] == NULL || argv[2] == NULL) { fprintf(stderr, "usage: %s [keyfile] [base64challenge]\n", argv[0]); return EXIT_FAILURE; } in = BIO_new(BIO_s_file()); BIO_read_filename(in, argv[1]); eckey = PEM_read_bio_ECPrivateKey(in, NULL, NULL, NULL); BIO_free(in); if (!EC_KEY_check_key(eckey)) { fprintf(stderr, "Key data for %s is inconsistent.\n", argv[1]); return EXIT_FAILURE; } memset(challenge, '\0', sizeof challenge); len = base64_decode(argv[2], challenge, BUFSIZE); workbuf_p = (unsigned char *) challenge; buf_len = ECDSA_size(eckey); sig_buf = mowgli_alloc(buf_len); sig_buf_p = sig_buf; if (!ECDSA_sign(0, challenge, len, sig_buf_p, &buf_len, eckey)) { fprintf(stderr, "Failed to sign challenge!\n"); return EXIT_FAILURE; } base64_encode(sig_buf, buf_len, challenge, BUFSIZE); printf("%s\n", challenge); mowgli_free(sig_buf); return EXIT_SUCCESS; }
static int mech_step_accname(sasl_session_t *p, char *message, int len, char **out, int *out_len) { ecdsa_session_t *s = p->mechdata; myuser_t *mu; char *username; unsigned char pubkey_raw[BUFSIZE]; const unsigned char *pubkey_raw_p; metadata_t *md; int ret; memset(pubkey_raw, '\0', sizeof pubkey_raw); username = mowgli_alloc(len + 5); memcpy(username, message, len); username[len] = '\0'; p->username = sstrdup(username); mowgli_free(username); mu = myuser_find_by_nick(p->username); if (mu == NULL) return ASASL_FAIL; md = metadata_find(mu, "pubkey"); if (md == NULL) return ASASL_FAIL; ret = base64_decode(md->value, (char *)pubkey_raw, BUFSIZE); if (ret == -1) return ASASL_FAIL; pubkey_raw_p = pubkey_raw; o2i_ECPublicKey(&s->pubkey, &pubkey_raw_p, ret); #ifndef DEBUG_STATIC_CHALLENGE_VECTOR RAND_pseudo_bytes(s->challenge, CHALLENGE_LENGTH); #else memset(s->challenge, 'A', CHALLENGE_LENGTH); #endif *out = malloc(400); memcpy(*out, s->challenge, CHALLENGE_LENGTH); *out_len = CHALLENGE_LENGTH; s->step = ECDSA_ST_RESPONSE; return ASASL_MORE; }
mowgli_eventloop_helper_proc_t * mowgli_helper_spawn(mowgli_eventloop_t *eventloop, const char *path, char *const argv[]) { mowgli_eventloop_helper_proc_t *helper; int io_fd[2]; char buf[64]; return_val_if_fail(eventloop != NULL, NULL); return_val_if_fail(path != NULL, NULL); helper = mowgli_alloc(sizeof(mowgli_eventloop_helper_proc_t)); helper->type.type = MOWGLI_EVENTLOOP_TYPE_HELPER; helper->eventloop = eventloop; socketpair(AF_UNIX, SOCK_STREAM, 0, io_fd); /* set up helper/child fd mapping */ helper->fd = io_fd[0]; /* make pollables and make them non-blocking */ helper->pfd = mowgli_pollable_create(eventloop, helper->fd, helper); snprintf(buf, sizeof buf, "%d", io_fd[1]); setenv("IO_FD", buf, 1); /* Spawn helper process using mowgli_process_spawn(), helper will get * IO_FD mapping from getenv(). Ugly hack, but it works... * --nenolod */ helper->child = mowgli_process_spawn(path, argv); if (helper->child == NULL) { mowgli_pollable_destroy(eventloop, helper->pfd); close(io_fd[0]); close(io_fd[1]); mowgli_free(helper); return NULL; } close(io_fd[1]); return helper; }
mowgli_mutex_t * mowgli_mutex_create(void) { mowgli_mutex_t *mutex = mowgli_alloc(sizeof(mowgli_mutex_t)); return_val_if_fail(mutex != NULL, NULL); if (mowgli_mutex_init(mutex)) { return mutex; } else { mowgli_free(mutex); return NULL; } }
mowgli_eventloop_helper_proc_t * mowgli_helper_create(mowgli_eventloop_t *eventloop, mowgli_eventloop_helper_start_fn_t *start_fn, const char *helpername, void *userdata) { mowgli_eventloop_helper_proc_t *helper; mowgli_helper_create_req_t child; int io_fd[2]; return_val_if_fail(eventloop != NULL, NULL); return_val_if_fail(start_fn != NULL, NULL); child.start_fn = start_fn; child.userdata = userdata; helper = mowgli_alloc(sizeof(mowgli_eventloop_helper_proc_t)); helper->type.type = MOWGLI_EVENTLOOP_TYPE_HELPER; helper->eventloop = eventloop; socketpair(AF_UNIX, SOCK_STREAM, 0, io_fd); /* set up helper/child fd mapping */ helper->fd = io_fd[0]; child.fd = io_fd[1]; /* make pollables and make them non-blocking */ helper->pfd = mowgli_pollable_create(eventloop, helper->fd, helper); mowgli_pollable_set_nonblocking(helper->pfd, true); /* spawn helper process using mowgli_process_clone() */ helper->child = mowgli_process_clone((mowgli_process_start_fn_t) mowgli_helper_trampoline, helpername, &child); if (helper->child == NULL) { mowgli_pollable_destroy(eventloop, helper->pfd); close(io_fd[0]); close(io_fd[1]); mowgli_free(helper); return NULL; } close(child.fd); return helper; }
static mowgli_config_file_t *mowgli_config_file_load_internal(mowgli_config_file_t *parent, const char *filename) { struct stat sb; FILE *fp; size_t ret; char *buf = NULL; mowgli_config_file_t *cfptr; static int nestcnt; if (nestcnt > MAX_INCLUDE_NESTING) { mowgli_config_file_error(parent, "Includes nested too deep \"%s\"\n", filename); return NULL; } fp = fopen(filename, "rb"); if (!fp) { mowgli_config_file_error(parent, "Couldn't open \"%s\": %s\n", filename, strerror(errno)); return NULL; } if (stat(filename, &sb) == -1) { mowgli_config_file_error(parent, "Couldn't fstat \"%s\": %s\n", filename, strerror(errno)); fclose(fp); return NULL; } if (!S_ISREG(sb.st_mode)) { mowgli_config_file_error(parent, "Not a regular file: \"%s\"\n", filename); fclose(fp); return NULL; } if (sb.st_size > SSIZE_MAX - 1) { mowgli_config_file_error(parent, "File too large: \"%s\"\n", filename); fclose(fp); return NULL; } buf = (char *) mowgli_alloc(sb.st_size + 1); if (sb.st_size) { errno = 0; ret = fread(buf, 1, sb.st_size, fp); if (ret != (size_t)sb.st_size) { mowgli_config_file_error(parent, "Error reading \"%s\": %s\n", filename, strerror(errno ? errno : EFAULT)); mowgli_free(buf); fclose(fp); return NULL; } } else ret = 0; buf[ret] = '\0'; fclose(fp); nestcnt++; cfptr = mowgli_config_file_parse(filename, buf); nestcnt--; /* buf is owned by cfptr or freed now */ return cfptr; }
static void on_RPL_NAMREPLY_cb(const char *key, void *data, void *priv) { struct a_net_chanuser *cu = data; a_net_user_vanish(cu->u); mowgli_free(cu); }
static void mowgli_strput(char **p, const char *s) { if (*p) mowgli_free(*p); *p = mowgli_strdup(s); }