diff options
author | Simon Rettberg | 2016-09-02 16:06:15 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-09-02 16:06:15 +0200 |
commit | 834d274a651b58fb11a9faa0cc71861e97ce2082 (patch) | |
tree | 6b7db239f82c113cfc2dd6b0244679caf20acc6b /src | |
parent | read the environment PWGUI_USERPREFIX and prefix the username with it. (diff) | |
download | printergui-834d274a651b58fb11a9faa0cc71861e97ce2082.tar.gz printergui-834d274a651b58fb11a9faa0cc71861e97ce2082.tar.xz printergui-834d274a651b58fb11a9faa0cc71861e97ce2082.zip |
[pwgui] Fix formatting, introduce constants for argv index
Diffstat (limited to 'src')
-rw-r--r-- | src/pwgui/main.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp index 81c7979..34c677b 100644 --- a/src/pwgui/main.cpp +++ b/src/pwgui/main.cpp @@ -22,6 +22,13 @@ #include "../x11workaround.h" +#define ARG_JOBID 1 +#define ARG_USER 2 +#define ARG_JOBTITLE 3 +#define ARG_NUMCOPIES 4 +#define ARG_PRINTOPTIONS 5 +#define ARG_FILENAME 6 + #define NAMELEN 400 #define BUFLEN 9000 #define ENVLEN 20000 @@ -72,7 +79,7 @@ int main(int argc, char *argv[]) // Pretty much what smbspool does, but in a generalized way - if (argc > 2 && strstr(argv[0], ":/") == NULL && strstr(argv[1], ":/") != NULL) { + if (argc > 2 && strstr(argv[0], ":/") == NULL && strstr(argv[ARG_JOBID], ":/") != NULL) { argv++; argc--; } @@ -101,14 +108,14 @@ int main(int argc, char *argv[]) *colon = ':'; // Is valid? if (access(backend, X_OK | R_OK) != 0) { - helper_getpiduid(argv[2], argv[3]); + helper_getpiduid(argv[ARG_USER], argv[ARG_JOBTITLE]); helper_messageBox("PrinterGUI", "Kein Backend für den gewählten Drucker vorhanden."); ERROR("Backend %s is not executable. Over and out.\n", backend); return CUPS_BACKEND_CANCEL; } - // argv[3] is title, get printergui pid from it - if (!helper_getpiduid(argv[2], argv[3])) { + // argv[ARG_JOBTITLE] is title, get printergui pid from it + if (!helper_getpiduid(argv[ARG_USER], argv[ARG_JOBTITLE])) { // El cheapo validation failed. Don't enable "smart mode" (GUI etc), just exec real backend ERROR("Dumb mode - will exec actual backend.\n"); // Mimic cups behaviour wrt dropping privs (Only 0700 or 0500 == root) @@ -125,7 +132,7 @@ int main(int argc, char *argv[]) // Get document to print if (argc == 6) { // Data comes from stdin, save... - snprintf(tmpfile, NAMELEN, "/tmp/print-%s-%d-%s-%d", argv[1], (int)time(NULL), argv[2], (int)getpid()); + snprintf(tmpfile, NAMELEN, "/tmp/print-%s-%d-%s-%d", argv[ARG_JOBID], (int)time(NULL), argv[ARG_USER], (int)getpid()); int fh = open(tmpfile, O_CREAT | O_WRONLY | O_TRUNC, 0600); if (fh < 0) { helper_messageBox("PrinterGUI", "Konnte temporäre Datei für den Druckjob nicht anlegen."); @@ -161,7 +168,7 @@ int main(int argc, char *argv[]) // } else { // File given, check if file exists - snprintf(tmpfile, NAMELEN, "%s", argv[6]); + snprintf(tmpfile, NAMELEN, "%s", argv[ARG_FILENAME]); int fh = open(tmpfile, O_RDONLY); if (fh < 0) { helper_messageBox("PrinterGUI", "Konnte den Druckjob nicht vom Dateisystem lesen."); @@ -174,7 +181,7 @@ int main(int argc, char *argv[]) chown(tmpfile, ruid, rgid); // Try right away with what we got - spoolres = run_backend(backend, device, argv[1], argv[2], argv[3], argv[4], argv[5], tmpfile, NULL); + spoolres = run_backend(backend, device, argv[ARG_JOBID], argv[ARG_USER], argv[ARG_JOBTITLE], argv[ARG_NUMCOPIES], argv[ARG_PRINTOPTIONS], tmpfile, NULL); helper_killGui(); if (spoolres != CUPS_BACKEND_AUTH_REQUIRED) { @@ -186,15 +193,15 @@ int main(int argc, char *argv[]) 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); + /* copy the username but prefix it with the content of PRINTERGUI_USERPREFIX env var */ + char* user_prefix = getenv(ENV_USERPREFIX); if (user_prefix == NULL) { - /* ok, user_prefix is empty */ - snprintf(creds, NAMELEN, "%s", argv[2]); + /* ok, user_prefix is empty */ + snprintf(creds, NAMELEN, "%s", argv[ARG_USER]); } else { /* use prefix */ - snprintf(creds, NAMELEN, "%s%s", user_prefix, argv[2]); + snprintf(creds, NAMELEN, "%s%s", user_prefix, argv[ARG_USER]); } do { @@ -220,7 +227,7 @@ int main(int argc, char *argv[]) PwGui *w = new PwGui(pfd[1], creds); bg->setMainWindow(w); w->show(); - wiggle(); + wiggle(); exit(a.exec()); return CUPS_BACKEND_CANCEL; } @@ -243,7 +250,7 @@ int main(int argc, char *argv[]) pass = creds + len + 1; } // Run backend with pimped user/pass - status = run_backend(backend, device, argv[1], creds, argv[3], argv[4], argv[5], tmpfile, pass); + status = run_backend(backend, device, argv[ARG_JOBID], creds, argv[ARG_JOBTITLE], argv[ARG_NUMCOPIES], argv[ARG_PRINTOPTIONS], tmpfile, pass); helper_cupsError(status); } while (status != CUPS_BACKEND_OK); remove(tmpfile); @@ -628,8 +635,9 @@ static void helper_messageBox(const char *caption, const char *text, const bool const pid_t pid = fork(); if (pid == 0) { // Child - Qt - char *argv[1]; + char *argv[2]; argv[0] = (char*)"bla"; + argv[1] = NULL; int argc = 1; helper_dropprivs(); helper_copyenv(); |