summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2019-03-12 11:40:30 +0100
committerKarolin Seeger <kseeger@samba.org>2019-03-26 07:49:18 +0000
commit4a5868be3a9b15ed83731a31d42fbd3c5b11678a (patch)
tree1ec4c51c69589df15a3ac161f6f6eff7fd490251
parente28dd0f95b307fcbff2f06f73eb5fe7293b3c24c (diff)
downloadsamba-4a5868be3a9b15ed83731a31d42fbd3c5b11678a.tar.gz
s3:client: Fix smbspool device uri handling
If we are executed as a CUPS backend, argv[0] is set to the device uri. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13832 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Bryan Mason <bmason@redhat.com> Signed-off-by: Guenther Deschner <gd@samba.org> (cherry picked from commit 69d7a496d3bf52eaa10e81132bb61430863fdd8a)
-rw-r--r--source3/client/smbspool.c120
1 files changed, 96 insertions, 24 deletions
diff --git a/source3/client/smbspool.c b/source3/client/smbspool.c
index 4d78db7f77c..8be1009c0a8 100644
--- a/source3/client/smbspool.c
+++ b/source3/client/smbspool.c
@@ -99,10 +99,12 @@ main(int argc, /* I - Number of command-line arguments */
char empty_str[] = "";
int tries = 0;
bool need_auth = true;
- const char *dev_uri;
+ const char *dev_uri = NULL;
+ const char *env = NULL;
const char *config_file = NULL;
TALLOC_CTX *frame = talloc_stackframe();
- bool device_uri_cmdline = false;
+ const char *print_user = NULL;
+ const char *print_title = NULL;
const char *print_file = NULL;
const char *print_copies = NULL;
int cmp;
@@ -139,21 +141,81 @@ main(int argc, /* I - Number of command-line arguments */
}
/*
- * If we have 6 arguments find out if we have the device_uri from the
- * command line or the print data
+ * Find out if we have the device_uri in the command line.
+ *
+ * If we are started as a CUPS backend argv[0] is normally the
+ * device_uri!
*/
- if (argc == 7) {
- cmp = strncmp(argv[1], "smb://", 6);
- if (cmp == 0) {
- device_uri_cmdline = true;
+ if (argc == 8) {
+ /*
+ * smbspool <uri> <job> <user> <title> <copies> <options> <file>
+ * 0 1 2 3 4 5 6 7
+ */
+
+ dev_uri = argv[1];
+
+ print_user = argv[3];
+ print_title = argv[4];
+ print_copies = argv[5];
+ print_file = argv[7];
+ } else if (argc == 7) {
+ int cmp1;
+ int cmp2;
+
+ /*
+ * <uri> <job> <user> <title> <copies> <options> <file>
+ * smbspool <uri> <job> <user> <title> <copies> <options>
+ * smbspool <job> <user> <title> <copies> <options> <file> | DEVICE_URI
+ */
+ cmp1 = strncmp(argv[0], "smb://", 6);
+ cmp2 = strncmp(argv[1], "smb://", 6);
+
+ if (cmp1 == 0) {
+ /*
+ * <uri> <job> <user> <title> <copies> <options> <file>
+ * 0 1 2 3 4 5 6
+ */
+ dev_uri = argv[0];
+
+ print_user = argv[2];
+ print_title = argv[3];
+ print_copies = argv[4];
+ print_file = argv[6];
+ } else if (cmp2 == 0) {
+ /*
+ * smbspool <uri> <job> <user> <title> <copies> <options>
+ * 0 1 2 3 4 5 6
+ */
+ dev_uri = argv[1];
+
+ print_user = argv[3];
+ print_title = argv[4];
+ print_copies = argv[5];
+ print_file = NULL;
} else {
+ /*
+ * smbspool <job> <user> <title> <copies> <options> <file> | DEVICE_URI
+ * 0 1 2 3 4 5 6
+ */
+ print_user = argv[2];
+ print_title = argv[3];
print_copies = argv[4];
print_file = argv[6];
}
- } else if (argc == 8) {
- device_uri_cmdline = true;
- print_copies = argv[5];
- print_file = argv[7];
+ } else if (argc == 6) {
+ /*
+ * <uri> <job> <user> <title> <copies> <options>
+ * smbspool <job> <user> <title> <copies> <options> | DEVICE_URI
+ * 0 1 2 3 4 5
+ */
+ cmp = strncmp(argv[0], "smb://", 6);
+ if (cmp == 0) {
+ dev_uri = argv[0];
+ }
+
+ print_user = argv[2];
+ print_title = argv[3];
+ print_copies = argv[4];
}
if (print_file != NULL) {
@@ -178,18 +240,17 @@ main(int argc, /* I - Number of command-line arguments */
/*
* Find the URI ...
*/
- if (device_uri_cmdline) {
- dev_uri = argv[1];
- } else {
- dev_uri = getenv("DEVICE_URI");
- if (dev_uri == NULL || strlen(dev_uri) == 0) {
- dev_uri = "";
+ if (dev_uri == NULL) {
+ env = getenv("DEVICE_URI");
+ if (env != NULL && env[0] != '\0') {
+ dev_uri = env;
}
}
- auth_info_required = getenv("AUTH_INFO_REQUIRED");
- if (auth_info_required == NULL) {
- auth_info_required = "none";
+ if (dev_uri == NULL) {
+ fprintf(stderr,
+ "ERROR: No valid device URI has been specified\n");
+ goto done;
}
cmp = strncmp(dev_uri, "smb://", 6);
@@ -205,6 +266,11 @@ main(int argc, /* I - Number of command-line arguments */
goto done;
}
+ auth_info_required = getenv("AUTH_INFO_REQUIRED");
+ if (auth_info_required == NULL) {
+ auth_info_required = "none";
+ }
+
/*
* Extract the destination from the URI...
*/
@@ -301,8 +367,14 @@ main(int argc, /* I - Number of command-line arguments */
load_interfaces();
do {
- cli = smb_connect(workgroup, server, port, printer,
- username, password, argv[3], &need_auth);
+ cli = smb_connect(workgroup,
+ server,
+ port,
+ printer,
+ username,
+ password,
+ print_user,
+ &need_auth);
if (cli == NULL) {
if (need_auth) {
exit(2);
@@ -338,7 +410,7 @@ main(int argc, /* I - Number of command-line arguments */
*/
for (i = 0; i < copies; i++) {
- status = smb_print(cli, argv[4] /* title */ , fp);
+ status = smb_print(cli, print_title, fp);
if (status != 0) {
break;
}