コード例 #1
0
ファイル: window-util.c プロジェクト: GNOME/tasks
static void
on_unmap (GtkWidget *widget, gpointer user_data)
{
  GError *error = NULL;
  GKeyFile *keys;
  const char *filename, *group;
  char *dirname, *data;
  int x, y, w, h;

  keys = get_key_file ();

  group = g_object_get_data (G_OBJECT (widget), GROUP_PROP);

  gtk_window_get_position (GTK_WINDOW (widget), &x, &y);
  g_key_file_set_integer (keys, group, WINDOW_X, x);
  g_key_file_set_integer (keys, group, WINDOW_Y, y);

  gtk_window_get_size (GTK_WINDOW (widget), &w, &h);
  g_key_file_set_integer (keys, group, WINDOW_WIDTH, w);
  g_key_file_set_integer (keys, group, WINDOW_HEIGHT, h);

  filename = get_filename ();
  dirname = g_path_get_dirname (filename);
  g_mkdir_with_parents (dirname, 0755);
  g_free (dirname);

  data = g_key_file_to_data (keys, NULL, NULL);
  if (!g_file_set_contents (filename, data, -1, &error)) {
    g_warning ("Cannot write key file: %s", error->message);
    g_error_free (error);
  }

  g_free (data);
  g_key_file_free (keys);
}
コード例 #2
0
void  ConfigFmThs :: SetRxSearchAfThs
(
    const char *file, UINT fd
)
{
    int index;
    struct NAME_MAP *found;
    char **grps = NULL;
    char **grps_cpy = NULL;

    keyfile = get_key_file();

    ALOGD("%s: file name is: %s\n", __func__, file);
    if(!parse_load_file(keyfile, file)) {
       ALOGE("Error in loading threshold file\n");
    }else {
       grps_cpy = grps = get_grps(keyfile);
       if(grps != NULL) {
          while(*grps != NULL) {
              ALOGE("Search grp: %s\n", *grps);
              found = (NAME_MAP *)bsearch(*grps, GRPS_MAP, MAX_GRPS,
                             sizeof(NAME_MAP), compare_name);
              if(found != NULL) {
                 ALOGE("Found group: %s\n", found->name);
                 switch(found->num) {
                 case AF_THS:
                      set_af_ths(fd);
                      break;
                 case SRCH_THS:
                      set_srch_ths(fd);
                      break;
                 case HYBRD_SRCH_LIST:
                      set_hybrd_list(fd);
                      break;
                 case BAND_CFG:
                      set_band_cfgs(fd);
                      break;
                 }
              }
              grps++;
          }
       }else {
          ALOGE("No of groups found is zero\n");
       }
       free_strs(grps_cpy);
    }
    free_key_file(keyfile);
    keyfile = NULL;
}
コード例 #3
0
ファイル: window-util.c プロジェクト: GNOME/tasks
void
window_bind_state (GtkWindow *window, const char *name)
{
  GKeyFile *keys;
  char *group;
  gboolean got_pos, got_size;
  int x, y, w, h, screen_w, screen_h;

  g_return_if_fail (GTK_IS_WINDOW (window));

  g_signal_connect (window, "unmap", G_CALLBACK (on_unmap), NULL);

  keys = get_key_file ();

  group = g_strconcat ("Window-", name, NULL);
  g_object_set_data_full (G_OBJECT (window), GROUP_PROP, group, g_free);

  got_pos = get (keys, group, WINDOW_X, &x);
  if (got_pos)
    got_pos &= get (keys, group, WINDOW_Y, &y);

  if (got_pos) {
    gtk_window_move (window, x, y);
  }

  got_size = get (keys, group, WINDOW_WIDTH, &w);
  if (got_size)
    got_size &= get (keys, group, WINDOW_HEIGHT, &h);

  if (got_size) {
    screen_w = gdk_screen_get_width (gtk_window_get_screen (window));
    screen_h = gdk_screen_get_width (gtk_window_get_screen (window));

    if (w > screen_w)
        w = screen_w;

    if (h > screen_h)
        h = screen_h;

    gtk_window_set_default_size (window, w, h);
  }

  g_key_file_free (keys);
}
コード例 #4
0
ファイル: fwknop.c プロジェクト: rafavg77/fwknop
/* Prompt for and receive a user password.
*/
static int
get_keys(fko_ctx_t ctx, fko_cli_options_t *options,
    char *key, int *key_len, char *hmac_key, int *hmac_key_len)
{
#if !AFL_FUZZING
    char   *key_tmp = NULL, *hmac_key_tmp = NULL;
#endif
    int     use_hmac = 0, res = 0;

    memset(key, 0x0, MAX_KEY_LEN+1);
    memset(hmac_key, 0x0, MAX_KEY_LEN+1);

    if(options->have_key)
    {
        strlcpy(key, options->key, MAX_KEY_LEN+1);
        *key_len = strlen(key);
    }
    else if(options->have_base64_key)
    {
        *key_len = fko_base64_decode(options->key_base64,
                (unsigned char *) options->key);
        if(*key_len > 0 && *key_len < MAX_KEY_LEN)
        {
            memcpy(key, options->key, *key_len);
        }
        else
        {
            log_msg(LOG_VERBOSITY_ERROR, "[*] Invalid key length: '%d', must be in [1,%d]",
                    *key_len, MAX_KEY_LEN);
            return 0;
        }
    }
    else
    {
        /* If --get-key file was specified grab the key/password from it.
        */
        if(options->get_key_file[0] != 0x0)
        {
            if(get_key_file(key, key_len, options->get_key_file, ctx, options) != 1)
            {
                return 0;
            }
        }
        else if(options->use_gpg)
        {
            if(options->use_gpg_agent)
                log_msg(LOG_VERBOSITY_NORMAL,
                    "[+] GPG mode set, signing passphrase acquired via gpg-agent");
            else if(options->gpg_no_signing_pw)
                log_msg(LOG_VERBOSITY_NORMAL,
                    "[+] GPG mode set, signing passphrase not required");
            else if(strlen(options->gpg_signer_key))
            {
#if AFL_FUZZING
                strlcpy(key, AFL_ENC_KEY, MAX_KEY_LEN+1);
#else
                key_tmp = getpasswd("Enter passphrase for signing: ", options->input_fd);
                if(key_tmp == NULL)
                {
                    log_msg(LOG_VERBOSITY_ERROR, "[*] getpasswd() key error.");
                    return 0;
                }
                strlcpy(key, key_tmp, MAX_KEY_LEN+1);
#endif
                *key_len = strlen(key);
            }
        }
        else
        {
#if AFL_FUZZING
            strlcpy(key, AFL_ENC_KEY, MAX_KEY_LEN+1);
#else
            key_tmp = getpasswd("Enter encryption key: ", options->input_fd);
            if(key_tmp == NULL)
            {
                log_msg(LOG_VERBOSITY_ERROR, "[*] getpasswd() key error.");
                return 0;
            }
            strlcpy(key, key_tmp, MAX_KEY_LEN+1);
#endif
            *key_len = strlen(key);
        }
    }

    if(options->have_hmac_key)
    {
        strlcpy(hmac_key, options->hmac_key, MAX_KEY_LEN+1);
        *hmac_key_len = strlen(hmac_key);
        use_hmac = 1;
    }
    else if(options->have_hmac_base64_key)
    {
        *hmac_key_len = fko_base64_decode(options->hmac_key_base64,
            (unsigned char *) options->hmac_key);
        if(*hmac_key_len > MAX_KEY_LEN || *hmac_key_len < 0)
        {
            log_msg(LOG_VERBOSITY_ERROR,
                    "[*] Invalid decoded key length: '%d', must be in [0,%d]",
                    *hmac_key_len, MAX_KEY_LEN);
            return 0;
        }
        memcpy(hmac_key, options->hmac_key, *hmac_key_len);
        use_hmac = 1;
    }
    else if (options->use_hmac)
    {
        /* If --get-key file was specified grab the key/password from it.
        */
        if(options->get_hmac_key_file[0] != 0x0)
        {
            if(get_key_file(hmac_key, hmac_key_len,
                options->get_hmac_key_file, ctx, options) != 1)
            {
                return 0;
            }
            use_hmac = 1;
        }
        else
        {
#if AFL_FUZZING
            strlcpy(hmac_key, AFL_HMAC_KEY, MAX_KEY_LEN+1);
#else
            hmac_key_tmp = getpasswd("Enter HMAC key: ", options->input_fd);
            if(hmac_key_tmp == NULL)
            {
                log_msg(LOG_VERBOSITY_ERROR, "[*] getpasswd() key error.");
                return 0;
            }
            strlcpy(hmac_key, hmac_key_tmp, MAX_KEY_LEN+1);
#endif
            *hmac_key_len = strlen(hmac_key);
            use_hmac = 1;
        }
    }

    if (use_hmac)
    {
        if(*hmac_key_len < 0 || *hmac_key_len > MAX_KEY_LEN)
        {
            log_msg(LOG_VERBOSITY_ERROR, "[*] Invalid HMAC key length: '%d', must be in [0,%d]",
                    *hmac_key_len, MAX_KEY_LEN);
            return 0;
        }

        /* Make sure the same key is not used for both encryption and the HMAC
        */
        if(*hmac_key_len == *key_len)
        {
            if(memcmp(hmac_key, key, *key_len) == 0)
            {
                log_msg(LOG_VERBOSITY_ERROR,
                    "[*] The encryption passphrase and HMAC key should not be identical, no SPA packet sent. Exiting.");
                return 0;
            }
        }

        res = fko_set_spa_hmac_type(ctx, options->hmac_type);
        if(res != FKO_SUCCESS)
        {
            errmsg("fko_set_spa_hmac_type", res);
            return 0;
        }
    }

    return 1;
}