[PC-BSD Commits] r18024 - pcbsd/current/src-qt4/qsu/src
svn at pcbsd.org
svn at pcbsd.org
Tue Jul 31 13:13:07 PDT 2012
Author: gamaral
Date: 2012-07-31 20:13:07 +0000 (Tue, 31 Jul 2012)
New Revision: 18024
Modified:
pcbsd/current/src-qt4/qsu/src/database.c
pcbsd/current/src-qt4/qsu/src/main.c
Log:
Merge in pam environment, store environment variables in for saved session.
Modified: pcbsd/current/src-qt4/qsu/src/database.c
===================================================================
--- pcbsd/current/src-qt4/qsu/src/database.c 2012-07-31 19:43:30 UTC (rev 18023)
+++ pcbsd/current/src-qt4/qsu/src/database.c 2012-07-31 20:13:07 UTC (rev 18024)
@@ -43,6 +43,10 @@
#define QSU_DB_MAGIC 4106420479 // great movie
+/********************************************************** global variables */
+
+extern char **environ;
+
/******************************************************** local declarations */
static int prepare_database_directory(const char *path);
@@ -99,9 +103,11 @@
int
qsu_database_authenticate(qsu_session *session)
{
+ char *l_name, *l_value;
+ int l_delta;
+ size_t l_len = 0;
+ time_t l_auth;
unsigned int l_magic;
- time_t l_auth;
- int l_delta;
QSU_UNUSED(session);
@@ -132,6 +138,38 @@
if ( l_delta < 0 || l_delta > QSU_AUTH_TIMEOUT)
return(FAILURE);
+ /*
+ * Environment
+ */
+
+ do {
+ l_len = 0;
+
+ if (read(s_db_file, &l_len, sizeof(l_len)) <= 0)
+ break;
+
+ l_value = malloc(l_len);
+ if (read(s_db_file, l_value, l_len) == -1) {
+ free(l_value);
+ perror("read");
+ return(FAILURE);
+ }
+
+ l_name = strsep(&l_value, "=");
+ if (!l_name || !l_value
+ || strlen(l_name) == 0 || strlen(l_value) == 0)
+ continue;
+
+ if (setenv(l_name, l_value, 1) != 0) {
+ free(l_name);
+ perror("setenv");
+ return(FAILURE);
+ }
+
+ free(l_name);
+ }
+ while(1);
+
return(SUCCESS);
}
@@ -140,6 +178,7 @@
{
const unsigned int l_magic = QSU_DB_MAGIC;
const time_t l_auth = time(0);
+ char **l_env;
QSU_UNUSED(session);
@@ -149,18 +188,38 @@
return(FAILURE);
}
- /* check for magic */
+ /* writemagic */
if (write(s_db_file, &l_magic, sizeof(l_magic)) == -1) {
perror("write");
return(FAILURE);
}
- /* read expiration (dangerously) */
+ /* write expiration */
if (write(s_db_file, &l_auth, sizeof(l_auth)) == -1) {
perror("write");
return(FAILURE);
}
+ /*
+ * Environment
+ */
+
+ l_env = environ;
+ while(*l_env) {
+ size_t l_len = strlen(*l_env) + 1;
+ if (write(s_db_file, &l_len, sizeof(l_len)) == -1) {
+ perror("write");
+ return(FAILURE);
+ }
+
+ if (write(s_db_file, *l_env, l_len) == -1) {
+ perror("write");
+ return(FAILURE);
+ }
+
+ ++l_env;
+ }
+
return(SUCCESS);
}
Modified: pcbsd/current/src-qt4/qsu/src/main.c
===================================================================
--- pcbsd/current/src-qt4/qsu/src/main.c 2012-07-31 19:43:30 UTC (rev 18023)
+++ pcbsd/current/src-qt4/qsu/src/main.c 2012-07-31 20:13:07 UTC (rev 18024)
@@ -56,6 +56,8 @@
static int main_pam_authenticate(qsu_session *session);
static int main_pam_set_items(qsu_session *session);
+static void main_pam_environment(qsu_session *session);
+
/*********************************************************** local variables */
static const char *s_command;
@@ -320,6 +322,8 @@
return(FAILURE);
}
+ main_pam_environment(session);
+
return(SUCCESS);
}
@@ -338,3 +342,24 @@
return(SUCCESS);
}
+void
+main_pam_environment(qsu_session *session)
+{
+ char **l_envlist, **l_env;
+ char *l_name, *l_value;
+
+ if ((l_envlist = pam_getenvlist(session->handle)) != 0) {
+ for (l_env = l_envlist; *l_env != NULL; ++l_env) {
+ l_value = *l_env;
+ l_name = strsep(&l_value, "=");
+
+ if (!l_name || !l_value
+ || strlen(l_name) == 0 || strlen(l_value) == 0)
+ continue;
+
+ setenv(l_name, l_value, 1);
+ free(*l_env);
+ }
+ free(l_envlist);
+ }
+}
More information about the Commits
mailing list