Esempio n. 1
0
static gboolean
handle_set_icon_data_url (CockpitAccount *object,
                          GDBusMethodInvocation *invocation,
                          const gchar *arg_data)
{
  GError *error = NULL;
  Account *acc = ACCOUNT (object);

  if (!account_auth_check (object, invocation, acc))
    return TRUE;

  if (acc->u)
    {
      const gchar *base64_data = strstr (arg_data, "base64,");
      if (base64_data == NULL)
        goto out;

      base64_data += strlen ("base64,");

      gsize raw_size;
      gs_free gchar *raw_data = (gchar *)g_base64_decode (base64_data, &raw_size);

      gs_unref_object GFileIOStream *tmp_stream = NULL;
      gs_unref_object GFile *tmp_file = g_file_new_tmp ("cockpit-user-icon-XXXXXX", &tmp_stream, &error);

      if (tmp_file == NULL)
        goto out;

      GOutputStream *out = g_io_stream_get_output_stream (G_IO_STREAM (tmp_stream));
      if (!g_output_stream_write_all (out, raw_data, raw_size, NULL, NULL, &error))
        goto out;

      if (!g_io_stream_close (G_IO_STREAM (tmp_stream), NULL, &error))
        goto out;

      gs_free gchar *tmp_path = g_file_get_path (tmp_file);
      act_user_set_icon_file (acc->u, tmp_path);
      g_file_delete (tmp_file, NULL, NULL);
    }

out:
  if (error)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR, COCKPIT_ERROR_FAILED,
                                             "%s", error->message);
      g_clear_error (&error);
    }
  else
    cockpit_account_complete_set_icon_data_url (object, invocation);
  return TRUE;
}
Esempio n. 2
0
static gboolean
handle_set_real_name (CockpitAccount *object,
                      GDBusMethodInvocation *invocation,
                      const gchar *arg_value)
{
  Account *acc = ACCOUNT (object);

  if (!account_auth_check (object, invocation, acc))
    return TRUE;

  if (acc->u)
    act_user_set_real_name (acc->u, arg_value);

  cockpit_account_complete_set_real_name (object, invocation);
  return TRUE;
}
Esempio n. 3
0
static gboolean
handle_set_password_hash (CockpitAccount *object,
                          GDBusMethodInvocation *invocation,
                          const gchar *arg_hash)
{
    GError *error;
    Account *acc = ACCOUNT (object);
    const gchar *argv[6];
    gint status;

    if (!account_auth_check (object, invocation, acc))
        return TRUE;

    if (acc->u == NULL)
    {
        cockpit_account_complete_set_password_hash (object, invocation);
        return TRUE;
    }

    argv[0] = "/usr/sbin/usermod";
    argv[1] = "-p";
    argv[2] = arg_hash;
    argv[3] = "--";
    argv[4] = act_user_get_user_name (acc->u);
    argv[5] = NULL;

    error = NULL;
    if (g_spawn_sync (NULL, (gchar**)argv, NULL, 0, NULL, NULL, NULL, NULL, &status, &error))
        g_spawn_check_exit_status (status, &error);

    if (error)
    {
        g_dbus_method_invocation_return_error (invocation,
                                               COCKPIT_ERROR, COCKPIT_ERROR_FAILED,
                                               "Failed to change password hash via %s: %s", argv[0], error->message);
        g_error_free (error);
    }
    else
    {
        cockpit_account_complete_set_password_hash (object, invocation);
    }

    return TRUE;
}
Esempio n. 4
0
static gboolean
handle_set_password (CockpitAccount *object,
                     GDBusMethodInvocation *invocation,
                     const gchar *arg_password)
{
  Account *acc = ACCOUNT (object);

  if (!account_auth_check (object, invocation, acc))
    return TRUE;

  if (acc->u)
    {
      act_user_set_password_mode (acc->u, ACT_USER_PASSWORD_MODE_REGULAR);
      act_user_set_password (acc->u, arg_password, "");
    }

  cockpit_account_complete_set_password (object, invocation);
  return TRUE;
}
Esempio n. 5
0
static gboolean
handle_get_password_hash (CockpitAccount *object,
                          GDBusMethodInvocation *invocation)
{
    Account *acc = ACCOUNT (object);
    const gchar *hash = "";

    if (!account_auth_check (object, invocation, acc))
        return TRUE;

    if (acc->u)
    {
        struct spwd *sp = getspnam (act_user_get_user_name (acc->u));
        if (sp && sp->sp_pwdp)
            hash = sp->sp_pwdp;
    }

    cockpit_account_complete_get_password_hash (object, invocation, hash);
    return TRUE;
}