--- ../gksu/gksu.c 2006-09-14 22:45:04.000000000 -0400 +++ gksu.c 2008-05-15 16:37:30.000000000 -0400 @@ -22,6 +22,7 @@ #include "../config.h" #define BASE_PATH "/apps/gksu/" +#define HTTP_PROXY_DIR "/system/http_proxy" /* GLOBALS */ gboolean print_pass = FALSE; @@ -450,6 +451,93 @@ } /* gksuexec */ +void +set_http_proxy_env(GConfClient *conf) +{ + gchar *host; + gint port; + GSList *ignore; + gboolean use_auth; + + host = gconf_client_get_string (conf, HTTP_PROXY_DIR "/host", NULL); + port = gconf_client_get_int (conf, HTTP_PROXY_DIR "/port", NULL); + ignore = gconf_client_get_list (conf, HTTP_PROXY_DIR "/ignore_hosts", + GCONF_VALUE_STRING, NULL); + + if ( port == 0 ) + port = 80; + + if ( host && host[0] != '\0' ) + { + use_auth = gconf_client_get_bool(conf, HTTP_PROXY_DIR "/use_authentication", NULL); + + if ( use_auth ) + { + gchar *auth_user = gconf_client_get_string (conf, HTTP_PROXY_DIR "/authentication_user", NULL); + gchar *auth_pass = gconf_client_get_string (conf, HTTP_PROXY_DIR "/authentication_password", NULL); + + if ( auth_user && auth_user[0] != '\0' && auth_pass && auth_pass[0] != '\0' ) + { + putenv(g_strdup_printf ("http_proxy=http://%s:%s@%s:%d/", + auth_user, auth_pass, host, port)); + g_free(auth_user); + g_free(auth_pass); + } + else if (auth_user && strlen(auth_user)) + { + putenv(g_strdup_printf ("http_proxy=http://%s@%s:%d/", + auth_user, host, port)); + g_free(auth_user); + } + } + else + { + putenv(g_strdup_printf ("http_proxy=http://%s:%d/", host, port)); + } + + g_free (host); + } + + if (ignore) + { + /* code distantly based on gconf's */ + gchar *buf = NULL; + guint bufsize = 64; + guint cur = 0; + + buf = g_malloc (bufsize + 3); + while (ignore != NULL) + { + guint len = strlen (ignore->data); + + if ((cur + len + 2) >= bufsize) /* +2 for '\0' and comma */ + { + bufsize = MAX(bufsize * 2, bufsize + len + 4); + buf = g_realloc (buf, bufsize + 3); + } + + g_assert (cur < bufsize); + + strcpy (&buf[cur], ignore->data); + cur += len; + + g_assert(cur < bufsize); + + buf[cur] = ','; + ++cur; + + g_assert(cur < bufsize); + + ignore = g_slist_next (ignore); + } + + buf[cur-1] = '\0'; /* overwrites last comma */ + + putenv(g_strdup_printf ("no_proxy=%s", buf)); + g_free (buf); + } +} + int main (int argc, char **argv) { @@ -714,6 +802,13 @@ g_error_free (error); error = NULL; } + + // export the http proxy env + GConfClient* gconf_client = gconf_client_get_default(); + if(gconf_client_get_bool (gconf_client, "/system/http_proxy/use_http_proxy", NULL) && !getenv("http_proxy") ) + { + set_http_proxy_env(gconf_client); + } if (run_mode == SUDO_MODE) gksu_sudo_full (context,