Exemple #1
0
// General initialization. Takes care of all the other stuff.
const backend_kwallet_context_t* dt_pwstorage_kwallet_new()
{
  backend_kwallet_context_t *context = g_malloc(sizeof(backend_kwallet_context_t));
  memset(context, 0, sizeof(backend_kwallet_context_t));

  GError* error = NULL;
  context->connection = g_bus_get_sync(G_BUS_TYPE_SESSION,NULL, &error);
  if(check_error(error))
  {
    g_free(context);
    return NULL;
  }

  if(!init_kwallet(context))
  {
    // kwalletd may not be running. Try to start it and try again.
    if (!start_kwallet(context) || !init_kwallet(context))
    {
      g_object_unref(context->connection);
      g_free(context);
      return NULL;
    }
  }

  return context;
}
Exemple #2
0
// General initialization. Takes care of all the other stuff.
const backend_kwallet_context_t* dt_pwstorage_kwallet_new()
{
  _context = g_malloc(sizeof(backend_kwallet_context_t));

  // NULL the context
  memset(_context, 0, sizeof(backend_kwallet_context_t));

#if GLIB_MAJOR_VERSION <= 2
#if GLIB_MINOR_VERSION < 31
  // Initialize threading in dbus-glib - it should be fine for
  // dbus_g_thread_init to be called multiple times.
  if (!g_thread_supported())
    g_thread_init(NULL);
#endif
#endif
  dbus_g_thread_init();

  GError* error = NULL;
  // Get a connection to the session bus.
  _context->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);

  if (CheckError(error))
    return NULL;

  if (!init_kwallet())
  {
    // kwalletd may not be running. Try to start it and try again.
    if (!start_kwallet() || !init_kwallet())
      return NULL;
  }

  return _context;
}
PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
    pam_syslog(pamh, LOG_INFO, "pam_sm_open_session\n");

    if (get_env(pamh, "PAM_KWALLET_LOGIN") != NULL) {
        pam_syslog(pamh, LOG_INFO, "pam_kwallet: we were already executed");
        return PAM_SUCCESS;
    }

    parseArguments(argc, argv);

    int result;
    result = pam_set_data(pamh, "sm_open_session", "1", NULL);
    if (result != PAM_SUCCESS) {
        pam_syslog(pamh, LOG_ERR, "pam_kwallet: Impossible to store sm_open_session: %s"
            , pam_strerror(pamh, result));
        return PAM_IGNORE;
    }

     //Fetch the user, needed to get user information
    const char *username;
    result = pam_get_user(pamh, &username, NULL);
    if (result != PAM_SUCCESS) {
        pam_syslog(pamh, LOG_ERR, "pam_kwallet: Couldn't get username %s",
                   pam_strerror(pamh, result));
        return PAM_IGNORE;//Since we are not an essential module, just make pam ignore us
    }

    struct passwd *userInfo;
    userInfo = getpwnam(username);
    if (!userInfo) {
        pam_syslog(pamh, LOG_ERR, "pam_kwallet: Couldn't get user info (passwd) info");
        return PAM_IGNORE;
    }

    const char *kwalletKey;
    result = pam_get_data(pamh, "kwallet_key", (const void **)&kwalletKey);

    if (result != PAM_SUCCESS) {
        pam_syslog(pamh, LOG_INFO, "pam_kwallet: open_session called without kwallet_key");
        return PAM_SUCCESS;//We will wait for pam_sm_authenticate
    }

    start_kwallet(pamh, userInfo, kwalletKey);

    return PAM_SUCCESS;
}