Ejemplo n.º 1
0
int keyring_unlock(char *keyring)
{
  GnomeKeyringInfo *info = NULL;
  char *password;

  gnome_keyring_get_info_sync(keyring, &info);

  if (gnome_keyring_info_get_is_locked(info))
  {
    password = try_secure_alloc(sizeof(char) * PASSWORD_MAX_SIZE);

    read_password(&password, "Enter the keyring password");
    GnomeKeyringResult res = gnome_keyring_unlock_sync(keyring, password);

    free_password(password);

    if (res != GNOME_KEYRING_RESULT_OK)
    {
      gnome_keyring_info_free(info);
      return keyring_handle_error(res);
    }
  }

  gnome_keyring_info_free(info);

  return GNOME_KEYRING_RESULT_OK;
}
Ejemplo n.º 2
0
void credential_clear(struct credential *c)
{
	free(c->protocol);
	free(c->host);
	free(c->path);
	free(c->username);
	free_password(c->password);

	credential_init(c);
}
Ejemplo n.º 3
0
int credential_read(struct credential *c)
{
	char    buf[1024];
	ssize_t line_len = 0;
	char   *key      = buf;
	char   *value;

	while (fgets(buf, sizeof(buf), stdin))
	{
		line_len = strlen(buf);

		if(buf[line_len-1]=='\n')
			buf[--line_len]='\0';

		if(!line_len)
			break;

		value = strchr(buf,'=');
		if(!value) {
			warning("invalid credential line: %s", key);
			return -1;
		}
		*value++ = '\0';

		if (!strcmp(key, "protocol")) {
			free(c->protocol);
			c->protocol = xstrdup(value);
		} else if (!strcmp(key, "host")) {
			free(c->host);
			c->host = xstrdup(value);
			value = strrchr(c->host,':');
			if (value) {
				*value++ = '\0';
				c->port = atoi(value);
			}
		} else if (!strcmp(key, "path")) {
			free(c->path);
			c->path = xstrdup(value);
		} else if (!strcmp(key, "username")) {
			free(c->username);
			c->username = xstrdup(value);
		} else if (!strcmp(key, "password")) {
			free_password(c->password);
			c->password = xstrdup(value);
			while (*value) *value++ = '\0';
		}
		/*
		 * Ignore other lines; we don't know what they mean, but
		 * this future-proofs us when later versions of git do
		 * learn new lines, and the helpers are updated to match.
		 */
	}
	return 0;
}
Ejemplo n.º 4
0
void free_passwords(void)
{
    password *pwd;

    pwd = g_pwd_head.next;

    while (pwd != NULL) {
        pwd = free_password(pwd);
    }

    g_pwd_head.next = NULL;
    g_pwd_tail = &g_pwd_head;
}
Ejemplo n.º 5
0
int keyring_get(struct credential *c)
{
	char* object = NULL;
	GList *entries;
	GnomeKeyringNetworkPasswordData *password_data;
	GnomeKeyringResult result;

	if (!c->protocol || !(c->host || c->path))
		return EXIT_FAILURE;

	object = keyring_object(c);

	result = gnome_keyring_find_network_password_sync(
				c->username,
				NULL /* domain */,
				c->host,
				object,
				c->protocol,
				NULL /* authtype */,
				c->port,
				&entries);

	free(object);

	if (result == GNOME_KEYRING_RESULT_NO_MATCH)
		return EXIT_SUCCESS;

	if (result == GNOME_KEYRING_RESULT_CANCELLED)
		return EXIT_SUCCESS;

	if (result != GNOME_KEYRING_RESULT_OK) {
		error("%s",gnome_keyring_result_to_message(result));
		return EXIT_FAILURE;
	}

	/* pick the first one from the list */
	password_data = (GnomeKeyringNetworkPasswordData *) entries->data;

	free_password(c->password);
	c->password = xstrdup(password_data->password);

	if (!c->username)
		c->username = xstrdup(password_data->user);

	gnome_keyring_network_password_list_free(entries);

	return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
static int
prompt_password (pam_handle_t *ph)
{
	const struct pam_conv *conv;
	struct pam_message msg;
	struct pam_response *resp;
	const struct pam_message *msgs[1];
	const void *item;
	char *password;
	int ret;

	/* Get the conversation function */
	ret = pam_get_item (ph, PAM_CONV, &item);
	if (ret != PAM_SUCCESS)
		return ret;

	/* Setup a message */
	memset (&msg, 0, sizeof (msg));
	memset (&resp, 0, sizeof (resp));
	msg.msg_style = PAM_PROMPT_ECHO_OFF;
	msg.msg = gkr_pam_gettext ("Password: ");
	msgs[0] = &msg;
	
	/* Call away */
	conv = (const struct pam_conv*)item;
	ret = (conv->conv) (1, msgs, &resp, conv->appdata_ptr);
	if (ret != PAM_SUCCESS)
		return ret;
	
	password = resp[0].resp;
	free (resp);
	
	if (password == NULL) 
		return PAM_CONV_ERR;
		
	/* Store it away for later use */
	ret = pam_set_item (ph, PAM_AUTHTOK, password);
	free_password (password);

	if (ret == PAM_SUCCESS)
		ret = pam_get_item (ph, PAM_AUTHTOK, &item); 

	return ret;
}
Ejemplo n.º 7
0
static void
cleanup_free_password (pam_handle_t *ph, void *data, int pam_end_status)
{
	free_password (data);
}