summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2016-09-02 16:51:46 +0200
committerSimon Rettberg2016-09-02 16:51:46 +0200
commitda462fef7173682429cdcc20802cdda1f90d77a8 (patch)
tree486bc8283bf13212345b3b17e4819dee8899aaa6 /src
parent[pwgui] Fix formatting, introduce constants for argv index (diff)
downloadprintergui-da462fef7173682429cdcc20802cdda1f90d77a8.tar.gz
printergui-da462fef7173682429cdcc20802cdda1f90d77a8.tar.xz
printergui-da462fef7173682429cdcc20802cdda1f90d77a8.zip
[pwgui] Steal env var for user prefix from printergui
Diffstat (limited to 'src')
-rw-r--r--src/pwgui/main.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp
index 34c677b..2c8123b 100644
--- a/src/pwgui/main.cpp
+++ b/src/pwgui/main.cpp
@@ -55,7 +55,7 @@ static void helper_killGui();
static bool helper_getpiduid(char *user, char *title);
static bool helper_loadlpuser();
static void helper_dropprivs();
-static void helper_copyenv();
+static void helper_copyenv(const char *only);
static char *helper_urlencode(char *s, char *enc);
static int helper_cupsError(const int code);
static void helper_messageBox(const char *caption, const char *text, const bool error = false);
@@ -181,7 +181,18 @@ int main(int argc, char *argv[])
chown(tmpfile, ruid, rgid);
// Try right away with what we got
- spoolres = run_backend(backend, device, argv[ARG_JOBID], argv[ARG_USER], argv[ARG_JOBTITLE], argv[ARG_NUMCOPIES], argv[ARG_PRINTOPTIONS], tmpfile, NULL);
+ char creds[NAMELEN];
+ /* copy the username but prefix it with the content of PRINTERGUI_USERPREFIX env var */
+ helper_copyenv(ENV_USERPREFIX);
+ char* user_prefix = getenv(ENV_USERPREFIX);
+ if (user_prefix == NULL) {
+ /* ok, user_prefix is empty */
+ snprintf(creds, NAMELEN, "%s", argv[ARG_USER]);
+ } else {
+ /* use prefix */
+ snprintf(creds, NAMELEN, "%s%s", user_prefix, argv[ARG_USER]);
+ }
+ spoolres = run_backend(backend, device, argv[ARG_JOBID], creds, argv[ARG_JOBTITLE], argv[ARG_NUMCOPIES], argv[ARG_PRINTOPTIONS], tmpfile, NULL);
helper_killGui();
if (spoolres != CUPS_BACKEND_AUTH_REQUIRED) {
@@ -191,18 +202,8 @@ int main(int argc, char *argv[])
// Seems we need the dialog
int status;
- char creds[NAMELEN], *pass = NULL;
-
- /* copy the username but prefix it with the content of PRINTERGUI_USERPREFIX env var */
- char* user_prefix = getenv(ENV_USERPREFIX);
+ char *pass = NULL;
- if (user_prefix == NULL) {
- /* ok, user_prefix is empty */
- snprintf(creds, NAMELEN, "%s", argv[ARG_USER]);
- } else {
- /* use prefix */
- snprintf(creds, NAMELEN, "%s%s", user_prefix, argv[ARG_USER]);
- }
do {
WARNING("Direct printing failed. Opening PW dialog....\n");
@@ -217,7 +218,7 @@ int main(int argc, char *argv[])
// Child - GUI
close(pfd[0]);
helper_dropprivs();
- helper_copyenv();
+ helper_copyenv(NULL);
QApplication a(argc, argv);
Backdrop *bg = new Backdrop;
bg->show();
@@ -525,7 +526,7 @@ static void helper_dropprivs()
}
}
-static void helper_copyenv()
+static void helper_copyenv(const char *only)
{
char *ptr = gui_env;
while (strlen(ptr) > 0) {
@@ -533,8 +534,10 @@ static void helper_copyenv()
if (equal != NULL) {
char *value = equal + 1;
*equal = '\0';
- setenv(ptr, value, 1);
- DEBUG("Setting Env: '%s' = '%s'\n", ptr, value);
+ if (only == NULL || strcmp(only, ptr) == 0) {
+ setenv(ptr, value, 1);
+ DEBUG("Setting Env: '%s' = '%s'\n", ptr, value);
+ }
*equal = '=';
}
ptr += strlen(ptr) + 1;
@@ -640,7 +643,7 @@ static void helper_messageBox(const char *caption, const char *text, const bool
argv[1] = NULL;
int argc = 1;
helper_dropprivs();
- helper_copyenv();
+ helper_copyenv(NULL);
QApplication a(argc, argv);
QMessageBox msgBox;
msgBox.setWindowTitle(QString::fromUtf8(caption));