diff options
author | Manuel Schneider | 2014-12-03 16:50:31 +0100 |
---|---|---|
committer | Manuel Schneider | 2014-12-03 16:50:31 +0100 |
commit | b243f801a50a7b6777a3e0061c1afb623c3b2793 (patch) | |
tree | b880205f7fdfacf31ce3a7529bf4f3d7695ba416 /src | |
parent | Fixed stupid bugs (diff) | |
download | printergui-b243f801a50a7b6777a3e0061c1afb623c3b2793.tar.gz printergui-b243f801a50a7b6777a3e0061c1afb623c3b2793.tar.xz printergui-b243f801a50a7b6777a3e0061c1afb623c3b2793.zip |
Fix printing problems
Diffstat (limited to 'src')
-rw-r--r-- | src/pwgui/main.cpp | 79 |
1 files changed, 59 insertions, 20 deletions
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp index 319cd40..1be1849 100644 --- a/src/pwgui/main.cpp +++ b/src/pwgui/main.cpp @@ -92,11 +92,11 @@ int main(int argc, char *argv[]) if (!helper_getpiduid(argv[2], argv[3])) { // 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) - helper_loadlpuser(); - struct stat st; - if (stat(backend, &st) != 0 || (st.st_mode & 0011) != 0) helper_dropprivs(); - kill(pid, SIGTERM); + // Mimic cups behaviour wrt dropping privs (Only 0700 or 0500 == root) + helper_loadlpuser(); + struct stat st; + if (stat(backend, &st) != 0 || (st.st_mode & 0011) != 0) + helper_dropprivs(); WARNING("Over and out.\n"); execv(backend, argv); exit(127); @@ -216,20 +216,58 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char * // Newer backend can read credentials from environment if (user != NULL) setenv("AUTH_USERNAME", user, 1); if (password != NULL) setenv("AUTH_PASSWORD", password, 1); - // For ipp14 (at least) we need to build a new URI with ://username:password@.... - if (user != NULL && password != NULL && strncmp(uri, "ipp14", 5) == 0) { - char *newstr = (char*)malloc(strlen(uri) + strlen(user) * 3 + strlen(password) * 3 + 20); + + // Compute proper string length + int len = strlen(uri) + 20 + strlen("?waitprinter=no&waitjob=no"); + if (user != NULL) + len += strlen(user) * 3; + + if(password != NULL) + len += strlen(password) * 3; + + char *newstr = (char*)malloc(len); + + // For ipp14 (at least) we need to build a new URI with ://username:password@.... + if (user != NULL && password != NULL && strncmp(uri, "ipp14:", 6) == 0) { char *ptr = newstr; ptr += sprintf(ptr, "ipp14://"); ptr = helper_urlencode(user, ptr); *ptr++ = ':'; ptr = helper_urlencode(password, ptr); *ptr++ = '@'; - ptr += sprintf(ptr, "%s", uri + 8); // TODO: If uri already contains credentials, skip over them (check if there's a @ before the first /, starting at index 8) - uri = newstr; - setenv("DEVICE_URI", uri, 1); + ptr += sprintf(ptr, "%s", uri + 8); // TODO: If uri already contains credentials, skip over them (check if there's a @ before the first /, starting at index 8) // Since we've already forked and execv anyways there's no need to clean up anything... } + else + strcpy(newstr, uri); + + uri = newstr; + + // Append wait options + if (strncmp(uri, "ipp:", 4) == 0 + || strncmp(uri, "ipp14:", 6) == 0 + || strncmp(uri, "ipps:", 5) == 0 + || strncmp(uri, "http:", 5) == 0 + || strncmp(uri, "https:", 6) == 0) + { + if (strchr(uri, '?') != NULL) + { + // Question mark has been found, parse the options for waitprinter and + // waitjob. + if(strstr(uri, "waitprinter=") == NULL) + strcat(uri, "&waitprinter=no"); + if(strstr(uri, "waitjob=") == NULL) + strcat(uri, "&waitjob=no"); + } + else + { + // No question mark found. Fine hence just add the options + strcat(uri, "?waitprinter=no&waitjob=no"); + } + } + setenv("DEVICE_URI", uri, 1); + ERROR("DEVICE_URI: '%s'", uri); + char *args[8]; args[0] = uri; args[1] = jobid; @@ -256,7 +294,7 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char * int readlen = 0; while ((readlen = read(pipefd[0], buffer, BUFLEN-1)) > 0) { buffer[readlen] = '\0'; - ERROR("BACKEND: %s\n", buffer); + ERROR("BACKEND: %s\n", buffer); if (strstr(buffer, "Unable to get printer status (Unauthorized)") != NULL) { needAuth = true; if (kill(pid, SIGTERM) < 0) { @@ -359,19 +397,20 @@ static bool helper_getpiduid(char *user, char *title) static bool helper_loadlpuser() { - struct passwd *pw = getpwnam("lp"); - if (pw == NULL) return false; - ruid = pw->pw_uid; - rgid = pw->pw_gid; - return true; + struct passwd *pw = getpwnam("lp"); + if (pw == NULL) return false; + ruid = pw->pw_uid; + rgid = pw->pw_gid; + return true; } static void helper_dropprivs() { if (ruid == 0) return; - initgroups(ruser, rgid); - setgid(rgid); - setuid(ruid); + initgroups(ruser, rgid); + setgid(rgid); + setuid(ruid); + ERROR("Set UID to %d and GID to %d.\n", (int)getuid(),(int)getgid()); chdir("/"); if (setuid(0) != -1) { ERROR("setuid-fu!?\n"); |