Ejemplo n.º 1
0
/**
 * bastile_gpg_options_change_vals
 * 
 * @option: null-terminated array of option names to change
 * @value: The values to change respective option to
 * @err: Returns an error value when errors
 * 
 * Changes the given option in the gpg config file.
 * If a value is NULL, the option will be deleted. If you want
 * an empty value, set value to an empty string. 
 * 
 * Returns: TRUE if success, FALSE if not
 **/
gboolean
bastile_gpg_options_change_vals (const gchar *options[], gchar *values[],
                                  GError **err)
{
    GError *e = NULL;
    GArray *lines;

    g_assert (!err || !*err);
    if (!err)
        err = &e;

    if (!gpg_options_init (err))
        return FALSE;

    lines = read_config_file (err);
    if (!lines)
        return FALSE;

    process_conf_edits (lines, options, values);
    
    write_config_file (lines, err);
    free_string_array (lines);
    
    return *err ? FALSE : TRUE;
}
Ejemplo n.º 2
0
/**
 * bastile_gpg_options_find_vals
 * 
 * @option: null terminated array of option names
 * @value: An array of pointers for return values 
 * @err: Returns an error value when errors
 * 
 * Find the value for a given options in the gpg config file.
 * Values without a value are returned as an empty string.
 * On success be sure to free all *value after you're done 
 * with them. values should be at least as big as options
 * 
 * Returns: TRUE if success, FALSE if not
 **/
gboolean
bastile_gpg_options_find_vals (const gchar *options[], gchar *values[],
                                GError **err)
{
    GError *e = NULL;
    GArray *lines;
    const gchar **opt;
    gchar *line;
    gchar *t;
    guint i, j;
    
    g_assert (!err || !*err);
    if (!err)
        err = &e;

    if (!gpg_options_init (err))
        return FALSE;
    
    lines = read_config_file (err);
    if (!lines)
        return FALSE;

    /* Clear out all values */
    for (i = 0, opt = options; *opt != NULL; opt++, i++)
        values[i] = NULL;

    for (j = 0; j < lines->len; j++) {
        line = g_array_index (lines, gchar*, j);
        g_assert (line != NULL);        

        g_strstrip (line);

        /* Ignore comments and blank lines */
        if (line[0] != '#' && line[0] != 0) {
            for (i = 0, opt = options; *opt != NULL; opt++, i++) {
                if (g_str_has_prefix (line, *opt)) {
                    t = line + strlen (*opt);
                    if (t[0] == 0 || g_ascii_isspace (t[0])) {
                        /* 
                         * We found a value. Fill it in. The caller
                         * frees this stuff. Note that we don't short 
                         * circuit the search because for gpg options 
                         * can be specified multiple times, and the 
                         * last one wins.
                         */

                        g_free (values[i]);
                        values[i] = g_strdup (t);
                        g_strstrip (values[i]);
                        break;  /* Done with this line */
                    }
                }
            }
        }
    }

    free_string_array (lines);

    return *err ? FALSE : TRUE;
}
Ejemplo n.º 3
0
/**
 * seahorse_gpg_homedir
 *
 * Returns: The home dir that GPG uses for it's keys and configuration
 **/
const gchar *
seahorse_gpg_homedir (void)
{
    if (!gpg_options_init (NULL))
        return NULL;
    return gpg_homedir;
}
Ejemplo n.º 4
0
/**
 * bastile_gpg_homedir
 * 
 * Returns: The home dir that GPG uses for it's keys and configuration
 **/
const gchar*
bastile_gpg_homedir ()
{
    /* THis shouldn't normally fail, and as such we return an invalid 
     * directory to avoid NULL memory access */
    g_return_val_if_fail (gpg_options_init (NULL), "/invalid/gpg/dir");
    return gpg_homedir;
}