Example #1
0
static char *
netsnmp_unix_fmtaddr(netsnmp_transport *t, void *data, int len)
{
    struct sockaddr_un *to = NULL;

    if (data != NULL) {
        to = (struct sockaddr_un *) data;
    } else if (t != NULL && t->data != NULL) {
        to = &(((sockaddr_un_pair *) t->data)->server);
        len = SUN_LEN(to);
    }
    if (to == NULL) {
        /*
         * "Local IPC" is the Posix.1g term for Unix domain protocols,
         * according to W. R. Stevens, ``Unix Network Programming Volume I
         * Second Edition'', p. 374.
         */
        return strdup("Local IPC: unknown");
    } else if (to->sun_path[0] == 0) {
        /*
         * This is an abstract name.  We could render it as hex or something
         * but let's not worry about that for now.
         */
        return strdup("Local IPC: abstract");
    } else {
        char           *tmp = (char *) malloc(16 + len);
        if (tmp != NULL) {
            sprintf(tmp, "Local IPC: %s", to->sun_path);
        }
        return tmp;
    }
}
Example #2
0
static wbcErr wbc_create_error_info(const struct winbindd_response *resp,
                                    struct wbcAuthErrorInfo **_e)
{
    wbcErr wbc_status = WBC_ERR_SUCCESS;
    struct wbcAuthErrorInfo *e;

    e = (struct wbcAuthErrorInfo *)wbcAllocateMemory(
            1, sizeof(struct wbcAuthErrorInfo),
            wbcAuthErrorInfoDestructor);
    BAIL_ON_PTR_ERROR(e, wbc_status);

    e->nt_status = resp->data.auth.nt_status;
    e->pam_error = resp->data.auth.pam_error;
    e->nt_string = strdup(resp->data.auth.nt_status_string);
    BAIL_ON_PTR_ERROR(e->nt_string, wbc_status);

    e->display_string = strdup(resp->data.auth.error_string);
    BAIL_ON_PTR_ERROR(e->display_string, wbc_status);

    *_e = e;
    e = NULL;

done:
    wbcFreeMemory(e);
    return wbc_status;
}
Example #3
0
void parse_variable(char *cfg_filename, char *line, char *space)
{
    char space2[BUFSIZE] = { 0 };
    char *value = NULL;
    char *key = NULL;
    tTokenizer t;

    /* Space2 = space + '.' */
    if (space != NULL)
        snprintf(space2, sizeof(space2), "%s.", space);

    if ((strncmp(line, space2, strlen(space2)) == 0) ||
            ((space == NULL) && (strstr(line, ".") != NULL))) {
        t = tokenize(line, "=");
        if (t.numTokens != 2) {
            DPRINTF("%s: Warning! There are %d tokens instead of 2. Ignoring line: '%s'\n",
                    __FUNCTION__, t.numTokens, line);
            return;
        }
        key   = strdup(trim(t.tokens[0]));
        value = strdup(trim(t.tokens[1]));
        free_tokens(t);

        if (space == NULL) {
            space = strdup(key);
            space[ strlen(space) - strlen(strchr(space, '.')) ] = 0;
            snprintf(space2, sizeof(space2), "%s.", space);
        }

        if (config_variable_add( cfg_filename, space, key + strlen(space2), value, key) != 0)
            fprintf(stderr, "Warning: Cannot add configuration variable '%s'\n", key);
    }
}
Example #4
0
/** Parses an entry of a user in the config
 * @param doc the xml document
 * @param cur the current xml node
 * @return 0 on success, -1 on failure
 */
int parseUser(xmlDoc *doc, xmlNode *cur)
{
    xmlChar *key;
    cur = cur->xmlChildrenNode;
    lp_user *user = g_new0(lp_user, 1);


    while (cur)
    {
        key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
        if ((!xmlStrcmp(cur->name, (const xmlChar *)"login")))
            user->login = strdup((char*)key);
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"pass")))
            user->pass = strdup((char*)key);
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"email")))
            user->email = strdup((char*)key);
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"right_db")))
        {
            if(atoi((char*)key))
                user->rights |= LP_RIGHT_DB;
        }
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"right_op")))
        {
            if(atoi((char*)key))
                user->rights |= LP_RIGHT_OP;
        }
        xmlFree(key);
        cur = cur->next;
    }
    config->users = g_list_append(config->users, user);
    return(0);
}
Example #5
0
static void
openFiles(struct CmdlineInfo const cmdline,
          unsigned int *     const fileCtP,
          struct pam **      const imgPamP,
          const char ***     const namesP) {

    unsigned int fileCt;
    struct pam * imgPam;
    const char ** names;

    fileCt = cmdline.nFiles > 0 ? cmdline.nFiles : 1;

    MALLOCARRAY(imgPam, fileCt);
    MALLOCARRAY(names, fileCt);

    if (!imgPam || !names)
        pm_error("out of memory");

    if (cmdline.nFiles > 0) {
        unsigned int i;

        for (i = 0; i < cmdline.nFiles; ++i) {
            imgPam[i].file = pm_openr(cmdline.inFileName[i]);
            names[i] = strdup(cmdline.inFileName[i]);
        }
    } else {
        imgPam[0].file = stdin;
        names[0] = strdup("stdin");
    }

    *fileCtP = fileCt;
    *imgPamP = imgPam;
    *namesP  = names;
}
Example #6
0
Preferences::Preferences(const char* name, const char* signature, bool doSave)
    : BMessage('Pref'), BLocker("Preferences", true),
      fSavePreferences(doSave)
{
    fNewPreferences = false;
    fSettingsFile = 0;
    BPath prefpath;
    fName = strdup(name);
    if (signature)
        fSignature = strdup(signature);
    else
        fSignature = NULL;

    if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath) == B_OK) {
        BDirectory prefdir(prefpath.Path());
        BEntry entry;
        prefdir.FindEntry(fName, &entry);

        BFile file(&entry, B_READ_ONLY);
        if (file.InitCheck() == B_OK)
            Unflatten(&file);
        else
            fNewPreferences = true;
    }
}
Example #7
0
/*
 * Return a new string node for storing the string [val], or NULL on error.
 * If [key] is specified, it will be used to index the node; otherwise,
 * the string [val] will be used.
 */
zed_strings_node_t *
_zed_strings_node_create(const char *key, const char *val)
{
    zed_strings_node_t *np;

    assert(val != NULL);

    np = calloc(1, sizeof (*np));
    if (!np)
        return (NULL);

    np->val = strdup(val);
    if (!np->val)
        goto nomem;

    if (key) {
        np->key = strdup(key);
        if (!np->key)
            goto nomem;
    } else {
        np->key = np->val;
    }
    return (np);

nomem:
    _zed_strings_node_destroy(np);
    return (NULL);
}
Example #8
0
SDB_API char *sdb_array_get(Sdb *s, const char *key, int idx, ut32 *cas) {
    const char *str = sdb_const_get (s, key, cas);
    const char *p = str;
    char *o, *n;
    int i, len;
    if (!str || !*str) return NULL;
    if (idx<0) {
        int len = sdb_alen (str);
        idx = -idx;
        if (idx>len)
            return NULL;
        idx = (len-idx);
    }
    if (idx==0) {
        n = strchr (str, SDB_RS);
        if (!n) return strdup (str);
        len = n-str;
        o = malloc (len+1);
        memcpy (o, str, len);
        o[len] = 0;
        return o;
    }
    for (i=0; i<idx; i++) {
        n = strchr (p, SDB_RS);
        if (!n) return NULL;
        p = n+1;
    }
    n = strchr (p, SDB_RS);
    if (!n) return strdup (p);
    len = n-p;
    o = malloc (len+1);
    memcpy (o, p, len);
    o[len] = 0;
    return o;
}
Example #9
0
char *
noit_module_options(mtev_console_closure_t ncct,
                    mtev_console_state_stack_t *stack,
                    mtev_console_state_t *state,
                    int argc, char **argv, int idx) {
    if(argc == 1) {
        /* List modules */
        mtev_hash_iter iter = MTEV_HASH_ITER_ZERO;
        const char *name;
        int klen, i = 0;
        void *vhdr;

        while(mtev_hash_next(&modules, &iter, (const char **)&name, &klen,
                             &vhdr)) {
            mtev_image_t *hdr = (mtev_image_t *)vhdr;
            if(!strncmp(hdr->name, argv[0], strlen(argv[0]))) {
                if(idx == i) return strdup(hdr->name);
                i++;
            }
        }
        return NULL;
    }
    if(argc == 2) {
        if(!strncmp("examples", argv[1], strlen(argv[1])))
            if(idx == 0) return strdup("examples");
    }
    return NULL;
}
Example #10
0
int main(int argc, char **argv)
{
    allocated_mem = 0;
    int i;
    init_debugger(argv[1]);
    for (i = 0; i < argc; i++)
        debugf("argv[%d] = \"%s\"\n", i, argv[i]);
    lib_path = strdup("lib/");

    if (argc < 2)
    {
        printf(EVE_CMD_OUTPUT, EVE_VERSION);
        return 0;
    }
    parse_cmds(argc, argv);
    // init
    create_global_types();
    init_imported_files();
    init_inc();
    init_functions_stack();
    LexInfo li;
    li = Lex_Begin(compile_file, readfile(compile_file));
    global_thread = create_thread(_main, NULL, "__main__", "void", NULL, 0, 0, 0, 0);
    start_parse(&li);
    debugf("parsing ended successfully.\nGenerating code.\n");
    free_imported_files();
    string src = strdup(gen_code(compile_file, global_thread));
    debugf("preparing compilation.\n");
    eve_compile(src, argc, argv);
    debugf("\nExecution Ended.\nTotal allocated memory: %d\n", allocated_mem);
    return 0;
}
Example #11
0
//*
//* Parse PROP String
//*
static char * oppo_parsepropstring(char * bf,char *key) {
    char* result = NULL;
    if (bf==NULL) return result;
    char* buffer=strdup(bf);
    char* line = strtok(buffer, "\n");
    do {
        while (*line && isspace(*line)) ++line;
        if (*line == '\0' || *line == '#') continue;
        char* equal = strchr(line, '=');
        if (equal == NULL) goto done;

        char* key_end = equal-1;
        while (key_end > line && isspace(*key_end)) --key_end;
        key_end[1] = '\0';

        if (strcmp(key, line) != 0) continue;

        char* val_start = equal+1;
        while(*val_start && isspace(*val_start)) ++val_start;

        char* val_end = val_start + strlen(val_start)-1;
        while (val_end > val_start && isspace(*val_end)) --val_end;
        val_end[1] = '\0';

        result = strdup(val_start);
        break;
    } while ((line = strtok(NULL, "\n")));
    free(buffer);
done:

    return result;
}
Example #12
0
static void callerid_write(struct cw_channel *chan, int argc, char **argv, const char *value)
{
    if (!value)
        return;

    if (!strncasecmp("all", argv[0], 3)) {
        char name[256];
        char num[256];
        if (!cw_callerid_split(value, name, sizeof(name), num, sizeof(num)))
            cw_set_callerid(chan, num, name, num);
    } else if (!strncasecmp("name", argv[0], 4)) {
        cw_set_callerid(chan, NULL, value, NULL);
    } else if (!strncasecmp("num", argv[0], 3) || !strncasecmp("number", argv[0], 6)) {
        cw_set_callerid(chan, value, NULL, NULL);
    } else if (!strncasecmp("ani", argv[0], 3)) {
        cw_set_callerid(chan, NULL, NULL, value);
    } else if (!strncasecmp("dnid", argv[0], 4)) {
        /* do we need to lock chan here? */
        if (chan->cid.cid_dnid)
            free(chan->cid.cid_dnid);
        chan->cid.cid_dnid = cw_strlen_zero(value) ? NULL : strdup(value);
    } else if (!strncasecmp("rdnis", argv[0], 5)) {
        /* do we need to lock chan here? */
        if (chan->cid.cid_rdnis)
            free(chan->cid.cid_rdnis);
        chan->cid.cid_rdnis = cw_strlen_zero(value) ? NULL : strdup(value);
    } else {
        cw_log(LOG_ERROR, "Unknown callerid data type.\n");
    }
}
Example #13
0
void config_set_string(config_file_t *conf, const char *key, const char *val)
{
    struct config_entry_list *last  = conf->entries;
    struct config_entry_list *entry = config_get_entry(conf, key, &last);

    if (entry && !entry->readonly)
    {
        free(entry->value);
        entry->value = strdup(val);
        return;
    }

    entry = (struct config_entry_list*)calloc(1, sizeof(*entry));

    if (!entry)
        return;

    entry->key   = strdup(key);
    entry->value = strdup(val);

    if (last)
        last->next = entry;
    else
        conf->entries = entry;
}
Example #14
0
static struct xamine_item *
xamine_field_definition(const struct xamine_conversation *conversation,
                        const unsigned char **data, size_t *size, size_t *offset,
                        const struct xamine_field_definition *field,
                        const struct xamine_item *parent)
{
    struct xamine_item *item;

    if (field->length) {
        struct xamine_item **end;
        size_t length;

        item = calloc(1, sizeof(*item));
        item->name = strdup(field->name);
        item->definition = field->definition;
        item->offset = *offset;

        end = &item->child;
        length = xamine_evaluate_expression(field->length, parent);
        for (size_t i = 0; i < length; i++) {
            *end = xamine_definition(conversation, data, size, offset, field->definition, parent);
            (*end)->name = afmt("[%lu]", i);
            end = &(*end)->next;
        }
        *end = NULL;
    }
    else {
        item = xamine_definition(conversation, data, size, offset, field->definition, parent);
        item->name = strdup(field->name);
    }

    return item;
}
Example #15
0
void
kv_replace(struct keyvalueq *head, char *key, char *value)
{
    struct keyvalue *entry;

    TAILQ_FOREACH(entry, head, next) {
        if (strcmp(key, entry->key) == 0)
            break;
    }

    if (entry == NULL) {
        entry = malloc(sizeof(struct keyvalue));
        if (entry == NULL)
            err(1, "%s: malloc", __func__);
    } else {
        free(entry->key);
        free(entry->value);
        TAILQ_REMOVE(head, entry, next);
    }

    entry->key = strdup(key);
    entry->value = strdup(value);

    if (entry->key == NULL || entry->value == NULL)
        err(1, "%s: strdup", __func__);

    TAILQ_INSERT_TAIL(head, entry, next);
}
Example #16
0
/*
 * Executes a program and feeds some shell-proof information data into it
 */
void EventExec (Contact *cont, const char *script, UBYTE type, UDWORD msgtype, const char *text)
{
    static int rc;
    char *mytext, *mynick, *myscript, *tmp, *myagent;
    const char *mytype, *cmd;

    mytext = strdup (text ? text : "");
    mynick = strdup (cont ? cont->nick : "");
    myagent = strdup (cont && cont->version ? cont->version : "");
    mytype = (type == 1 ? "msg" : type == 2 ? "on" : type == 3 ? "off" :
              type == 4 ? "beep" : type == 5 ? "status" : "other");
    myscript = strdup (s_realpath (script));

    for (tmp = mytext; *tmp; tmp++)
        if (*tmp == '\'' || *tmp == '\\')
            *tmp = '"';
    for (tmp = mynick; *tmp; tmp++)
        if (*tmp == '\'' || *tmp == '\\')
            *tmp = '"';
    for (tmp = myagent; *tmp; tmp++)
        if (*tmp == '\'' || *tmp == '\\')
            *tmp = '"';

    cmd = s_sprintf ("%s icq %ld '%s' global %s %ld '%s' '%s'",
                     myscript, cont ? cont->uin : 0, mynick, mytype, msgtype, mytext, myagent);

    rc = system (cmd);
    if (rc)
        rl_printf (i18n (2222, "Script command '%s' failed: %s (%d).\n"),
                   myscript, strerror (rc), rc);
    free (mynick);
    free (mytext);
    free (myscript);
}
Example #17
0
void
send_stonith_update(crm_action_t * action, const char *target, const char *uuid)
{
    int rc = pcmk_ok;
    crm_node_t *peer = NULL;

    /* zero out the node-status & remove all LRM status info */
    xmlNode *node_state = NULL;

    CRM_CHECK(target != NULL, return);
    CRM_CHECK(uuid != NULL, return);

    /* Make sure the membership and join caches are accurate */
    peer = crm_get_peer_full(0, target, CRM_GET_PEER_ANY);

    CRM_CHECK(peer != NULL, return);

    if (peer->uuid == NULL) {
        crm_info("Recording uuid '%s' for node '%s'", uuid, target);
        peer->uuid = strdup(uuid);
    }

    crmd_peer_down(peer, TRUE);

    /* Generate a node state update for the CIB.
     * We rely on the membership layer to do node_update_cluster,
     * and the peer status callback to do node_update_peer,
     * because the node might rejoin before we get the stonith result.
     */
    node_state = do_update_node_cib(peer, node_update_join|node_update_expected,
                                    NULL, __FUNCTION__);

    /* we have to mark whether or not remote nodes have already been fenced */
    if (peer->flags & crm_remote_node) {
        time_t now = time(NULL);
        char *now_s = crm_itoa(now);
        crm_xml_add(node_state, XML_NODE_IS_FENCED, now_s);
        free(now_s);
    }

    /* Force our known ID */
    crm_xml_add(node_state, XML_ATTR_UUID, uuid);

    rc = fsa_cib_conn->cmds->update(fsa_cib_conn, XML_CIB_TAG_STATUS, node_state,
                                    cib_quorum_override | cib_scope_local | cib_can_create);

    /* Delay processing the trigger until the update completes */
    crm_debug("Sending fencing update %d for %s", rc, target);
    fsa_register_cib_callback(rc, FALSE, strdup(target), cib_fencing_updated);

    /* Make sure it sticks */
    /* fsa_cib_conn->cmds->bump_epoch(fsa_cib_conn, cib_quorum_override|cib_scope_local);    */

    erase_status_tag(peer->uname, XML_CIB_TAG_LRM, cib_scope_local);
    erase_status_tag(peer->uname, XML_TAG_TRANSIENT_NODEATTRS, cib_scope_local);

    free_xml(node_state);
    return;
}
Example #18
0
static pmh_realelement *copy_element(parser_data *p_data, pmh_realelement *elem)
{
    pmh_realelement *result = mk_element(p_data, elem->type, elem->pos, elem->end);
    result->label = (elem->label == NULL) ? NULL : strdup(elem->label);
    result->text = (elem->text == NULL) ? NULL : strdup(elem->text);
    result->address = (elem->address == NULL) ? NULL : strdup(elem->address);
    return result;
}
Example #19
0
static void create_mime_mappings(const char *fn) {
    FILE *mimefile = fopen(fn, "r");
    char line[4096];
    char *type, *ext, *cur;
    mime_type *mapping;

    mimetypes = avl_tree_new(_compare_mappings, NULL);

    if (mimefile == NULL)
    {
        WARN1 ("Cannot open mime type file %s", fn);
        return;
    }

    while(fgets(line, 4096, mimefile))
    {
        line[4095] = 0;

        if(*line == 0 || *line == '#')
            continue;

        type = line;

        cur = line;

        while(*cur != ' ' && *cur != '\t' && *cur)
            cur++;
        if(*cur == 0)
            continue;

        *cur++ = 0;

        while(1) {
            while(*cur == ' ' || *cur == '\t')
                cur++;
            if(*cur == 0)
                break;

            ext = cur;
            while(*cur != ' ' && *cur != '\t' && *cur != '\n' && *cur)
                cur++;
            *cur++ = 0;
            if(*ext)
            {
                void *tmp;
                /* Add a new extension->type mapping */
                mapping = malloc(sizeof(mime_type));
                mapping->ext = strdup(ext);
                mapping->type = strdup(type);
                if(!avl_get_by_key(mimetypes, mapping, &tmp))
                    avl_delete(mimetypes, mapping, _delete_mapping);
                avl_insert(mimetypes, mapping);
            }
        }
    }

    fclose(mimefile);
}
Example #20
0
static void parse_commandline(int argc, char **argv, ZBX_TASK_EX *t)
{
    char	ch	= '\0';

    t->task = ZBX_TASK_START;

    /* Parse the command-line. */
    while ((ch = (char)zbx_getopt_long(argc, argv, shortopts, longopts, NULL)) != (char)EOF)
        switch (ch) {
        case 'c':
            CONFIG_FILE = strdup(zbx_optarg);
            break;
        case 'h':
            help();
            exit(-1);
            break;
        case 'V':
            version();
            exit(-1);
            break;
        case 'p':
            if(t->task == ZBX_TASK_START)
                t->task = ZBX_TASK_PRINT_SUPPORTED;
            break;
        case 't':
            if(t->task == ZBX_TASK_START)
            {
                t->task = ZBX_TASK_TEST_METRIC;
                TEST_METRIC = strdup(zbx_optarg);
            }
            break;
#if defined (_WINDOWS)
        case 'i':
            t->task = ZBX_TASK_INSTALL_SERVICE;
            break;
        case 'd':
            t->task = ZBX_TASK_UNINSTALL_SERVICE;
            break;
        case 's':
            t->task = ZBX_TASK_START_SERVICE;
            break;
        case 'x':
            t->task = ZBX_TASK_STOP_SERVICE;
            break;
        case 'm':
            t->flags = ZBX_TASK_FLAG_MULTIPLE_AGENTS;
            break;
#endif /* _WINDOWS */
        default:
            t->task = ZBX_TASK_SHOW_USAGE;
            break;
        }

    if(CONFIG_FILE == NULL)
    {
        CONFIG_FILE = DEFAULT_CONFIG_FILE;
    }
}
Example #21
0
void
webpopup_finalize_result(webpopup_result_t *wr)
{
    if(wr->wr_trapped.url != NULL) {
        char hn[256];
        char path[4096];

        TRACE(TRACE_DEBUG, "webpopup", "Trapped URL: %s", wr->wr_trapped.url);

        url_split(NULL, 0, NULL, 0, hn, sizeof(hn),
                  &wr->wr_trapped.port, path, sizeof(path),
                  wr->wr_trapped.url);

        wr->wr_trapped.hostname = strdup(hn);
        wr->wr_trapped.path     = strdup(path);


        char *k = strchr(wr->wr_trapped.path, '?');
        while(k) {
            *k++ = 0;

            char *v = strchr(k, '=');
            int kl, vl = 0;

            char *n = strchr(k, '&');

            if(v == NULL) {
                if(n == NULL) {
                    kl = strlen(k);
                } else {
                    kl = n - k;
                }
            } else {
                kl = v - k;
                v++;
                if(n == NULL) {
                    vl = strlen(v);
                } else {
                    vl = n - v;
                }
            }

            http_header_t *hh = malloc(sizeof(http_header_t));
            hh->hh_key = malloc(kl+1);
            memcpy(hh->hh_key, k, kl);
            hh->hh_key[kl] = 0;

            if(v != NULL) {
                hh->hh_value = malloc(vl+1);
                memcpy(hh->hh_value, v, vl);
                hh->hh_value[vl] = 0;
            }
            k = n;
            LIST_INSERT_HEAD(&wr->wr_trapped.qargs, hh, hh_link);
        }
    }
}
Example #22
0
static void
firmcvt(char *firmfile)
{
    char			*basefile, *outfile, *ptr;
    char			sysbuf[1024];

    outfile = strdup(basename(firmfile));
    basefile = strdup(outfile);

    snprintf(sysbuf, sizeof(sysbuf),
#ifdef __i386__
             "objcopy -I binary -O elf32-i386-freebsd -B i386 %s %s.o\n",
#endif
#ifdef __amd64__
             "objcopy -I binary -O elf64-x86-64-freebsd -B i386 %s %s.o\n",
#endif
             firmfile, outfile);
    printf("%s", sysbuf);
    system(sysbuf);

    ptr = firmfile;
    while (*ptr) {
        if (*ptr == '/' || *ptr == '.')
            *ptr = '_';
        ptr++;
    }
    ptr = basefile;
    while (*ptr) {
        if (*ptr == '/' || *ptr == '.')
            *ptr = '_';
        else
            *ptr = tolower(*ptr);
        ptr++;
    }

    snprintf(sysbuf, sizeof(sysbuf),
             "objcopy --redefine-sym _binary_%s_start=%s_start "
             "--strip-symbol _binary_%s_size "
             "--redefine-sym _binary_%s_end=%s_end %s.o %s.o\n",
             firmfile, basefile, firmfile, firmfile,
             basefile, outfile, outfile);
    ptr = sysbuf;
    printf("%s", sysbuf);
    system(sysbuf);

    snprintf(sysbuf, sizeof(sysbuf),
             "ld -Bshareable -d -warn-common -o %s.ko %s.o\n",
             outfile, outfile);
    printf("%s", sysbuf);
    system(sysbuf);

    free(basefile);

    exit(0);
}
Example #23
0
static int PAM_conv(int num_msg,
                    const struct pam_message **msg,
                    struct pam_response **resp, void *appdata_ptr)
{
    int count = 0;
    unsigned int replies = 0U;
    struct pam_response *reply = NULL;
    size_t size = (size_t) 0U;

    (void) appdata_ptr;
    *resp = NULL;
    for (count = 0; count < num_msg; count++) {
        switch (msg[count]->msg_style) {
        case PAM_PROMPT_ECHO_ON:
            GET_MEM;
            memset(&reply[replies], 0, sizeof reply[replies]);
            if ((reply[replies].resp = strdup(PAM_username)) == NULL) {
#ifdef PAM_BUF_ERR
                reply[replies].resp_retcode = PAM_BUF_ERR;
#endif
                PAM_error = 1;
                return PAM_CONV_ERR;
            }
            reply[replies++].resp_retcode = PAM_SUCCESS;
            /* PAM frees resp */
            break;
        case PAM_PROMPT_ECHO_OFF:
            GET_MEM;
            memset(&reply[replies], 0, sizeof reply[replies]);
            if ((reply[replies].resp = strdup(PAM_password)) == NULL) {
#ifdef PAM_BUF_ERR
                reply[replies].resp_retcode = PAM_BUF_ERR;
#endif
                PAM_error = 1;
                return PAM_CONV_ERR;
            }
            reply[replies++].resp_retcode = PAM_SUCCESS;
            /* PAM frees resp */
            break;
        case PAM_TEXT_INFO:
            /* ignore it... */
            break;
        case PAM_ERROR_MSG:
        default:
            /* Must be an error of some sort... */
            free(reply);
            PAM_error = 1;
            return PAM_CONV_ERR;
        }
    }
    *resp = reply;

    return PAM_SUCCESS;
}
Example #24
0
static char *
fndSource(char *varname)
{
    int i;

    if(debug)
        fprintf(stderr,"fndSource %s\n",varname);
    for( i=0; i< srctop; i++)
        if( strcmp(varname, sources[i].varname)==0)
            return strdup(sources[i].source);
    return strdup(varname);
}
Example #25
0
Professor* Professor_new(const char* name, char gender, const char* office) {
    Professor* professor = (Professor*) malloc(sizeof(Professor));
    professor->person.name = strdup(name);
    professor->person.gender = gender;
    professor->person.delet = &Professor_delete;
    professor->office = strdup(office);
    professor->person.work = &work_professor;
    professor->person.type_check = &type_check_professor;
    professor->research = &research;

    return professor;
}
Example #26
0
char *expand_string(char *str, int argc, char **argv)
{
    char buf[1024];
    char *p, *src, *dst;
    int len, buflen;

    if (strcspn(str, "%\\\'") == strlen(str))
        return strdup(str);

    src    = str;
    dst    = buf;
    len    = 0;
    buflen = sizeof(buf) - 8;	/* Slightly on the safe side... */

    while (*src && (len < buflen)) {
        switch (*src) {
        case '\'':
            *dst++ = *src++;
            len++;
            while (*src && (*src != '\'') && (len < buflen)) {
                *dst++ = *src++;
                len++;
            }
            if (*src) {
                *dst++ = '\'';
                len++;
            }
            break;

        case '\\':
            src++;
            *dst++ = parsechr(src, &src);
            len++;
            break;

        case '%':
            src++;
            p = parsestr(src, &src, argc, argv);
            strncpy(dst, p, min(strlen(p), buflen - len));
            dst += min(strlen(p), buflen - len);
            len += min(strlen(p), buflen - len);
            break;

        default:
            *dst++ = *src++;
            len++;
            break;
        }
    }

    *dst = 0;
    return strdup(buf);
}
Item *item_create_switch(    char *name, char *hint, int  *val_int, char *str_off, char *str_on )
{
    char **names = calloc( 2, sizeof( char* ) );
    Item *item = item_create_basic( ITEM_SWITCH, name, hint );
    names[0] = strdup( str_off );
    names[1] = strdup( str_on );
    item->value = value_create_range_str( val_int, names, 2 );
    free( names[0] );
    free( names[1] );
    free( names );
    return item;
}
Example #28
0
void
chat_log_chat(const gchar * const login, gchar *other,
              const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp)
{
    struct dated_chat_log *dated_log = g_hash_table_lookup(logs, other);

    // no log for user
    if (dated_log == NULL) {
        dated_log = _create_log(other, login);
        g_hash_table_insert(logs, strdup(other), dated_log);

        // log exists but needs rolling
    } else if (_log_roll_needed(dated_log)) {
        dated_log = _create_log(other, login);
        g_hash_table_replace(logs, strdup(other), dated_log);
    }

    gchar *date_fmt = NULL;
    GDateTime *dt = NULL;
    if (tv_stamp == NULL) {
        dt = g_date_time_new_now_local();
    } else {
        dt = g_date_time_new_from_timeval_utc(tv_stamp);
    }

    date_fmt = g_date_time_format(dt, "%H:%M:%S");

    FILE *logp = fopen(dated_log->filename, "a");
    if (logp != NULL) {
        if (direction == PROF_IN_LOG) {
            if (strncmp(msg, "/me ", 4) == 0) {
                fprintf(logp, "%s - *%s %s\n", date_fmt, other, msg + 4);
            } else {
                fprintf(logp, "%s - %s: %s\n", date_fmt, other, msg);
            }
        } else {
            if (strncmp(msg, "/me ", 4) == 0) {
                fprintf(logp, "%s - *me %s\n", date_fmt, msg + 4);
            } else {
                fprintf(logp, "%s - me: %s\n", date_fmt, msg);
            }
        }
        fflush(logp);
        int result = fclose(logp);
        if (result == EOF) {
            log_error("Error closing file %s, errno = %d", dated_log->filename, errno);
        }
    }

    g_free(date_fmt);
    g_date_time_unref(dt);
}
Example #29
0
Under* Under_new(const char* name, char gender, const char* major, int year) {
    Under* under = (Under*) malloc(sizeof(Under));
    under->student.person.name = strdup(name);
    under->student.person.gender = gender;
    under->student.person.delet = &Under_delete;
    under->student.major = strdup(major);
    under->year = year;
    under->student.person.work = &work_student;
    under->student.person.type_check = &type_check_under;
    under->student.graduate = &graduate_under;

    return under;
}
Example #30
0
/*
  convert username:password to char*:char*
  if password is not specified it defaults to ""
*/
static int parse_auth(char *auth, char **username, char **password) {
    char *ptr;
    *username = strdup(auth);
    ptr = strchr(*username, ':');
    if (ptr != NULL) {
        *ptr = '\0';
        *password = strdup(ptr + 1);
    } else {
        *password = strdup("");
    }

    return 0;
}