summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Klinger2016-08-23 22:32:29 +0200
committerChristian Klinger2016-08-23 22:32:29 +0200
commit04c480dfaec9723b9330d9c193ee30e55c030cfb (patch)
treee5efd00e67fb8ef3ed65413af928aeebd35c1559
parentadded x11 workaround. (diff)
downloadprintergui-04c480dfaec9723b9330d9c193ee30e55c030cfb.tar.gz
printergui-04c480dfaec9723b9330d9c193ee30e55c030cfb.tar.xz
printergui-04c480dfaec9723b9330d9c193ee30e55c030cfb.zip
read the environment PWGUI_USERPREFIX and prefix the username with it.
-rw-r--r--src/pwgui/main.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp
index 9f3bbef..81c7979 100644
--- a/src/pwgui/main.cpp
+++ b/src/pwgui/main.cpp
@@ -26,6 +26,8 @@
#define BUFLEN 9000
#define ENVLEN 20000
+#define ENV_USERPREFIX "PWGUI_USERPREFIX"
+
#define DEBUG(...) fprintf(stderr, "DEBUG: [pwgui] " __VA_ARGS__)
#define WARNING(...) fprintf(stderr, "WARNING: [pwgui] " __VA_ARGS__)
#define ERROR(...) fprintf(stderr, "ERROR: [pwgui] " __VA_ARGS__)
@@ -51,6 +53,15 @@ 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);
+static void demo();
+/*
+ * Note to the next HiWi who wants to refactor this to use something like boost::program_options:
+ * Don't do it unless you are certain that you understood the behaviour described here:
+ * > https://www.samba.org/samba/docs/man/manpages/smbspool.8.html
+ *
+ * Making all arguments positional and making the *first* argument optional was just not a good idea.
+ *
+ * */
int main(int argc, char *argv[])
{
char tmpfile[NAMELEN];
@@ -58,6 +69,8 @@ int main(int argc, char *argv[])
char backend[NAMELEN];
int spoolres;
+
+
// Pretty much what smbspool does, but in a generalized way
if (argc > 2 && strstr(argv[0], ":/") == NULL && strstr(argv[1], ":/") != NULL) {
argv++;
@@ -162,6 +175,7 @@ int main(int argc, char *argv[])
// Try right away with what we got
spoolres = run_backend(backend, device, argv[1], argv[2], argv[3], argv[4], argv[5], tmpfile, NULL);
+
helper_killGui();
if (spoolres != CUPS_BACKEND_AUTH_REQUIRED) {
remove(tmpfile);
@@ -171,7 +185,18 @@ int main(int argc, char *argv[])
// Seems we need the dialog
int status;
char creds[NAMELEN], *pass = NULL;
- snprintf(creds, NAMELEN, "%s", argv[2]);
+
+ /* 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]);
+ } else {
+ /* use prefix */
+ snprintf(creds, NAMELEN, "%s%s", user_prefix, argv[2]);
+ }
+
do {
WARNING("Direct printing failed. Opening PW dialog....\n");
int pfd[2];