printer location string
Martin Zielinski
mz at seh.de
Thu Dec 20 10:51:13 GMT 2007
Hello!
When samba uses CUPS for printing, the location string of a printer is
pulled from the server every time, a printer info 2 is requested (if
either the comment or location string ist empty).
This happens v e r y frequently.
The attached patch for 3.0.28 adds the location to the pcap_cache struct
and afterwards the string is pulled from the service struct.
I'd appreciate, if someone could review the patch and make a comment, if
it has a chance to make it into the mainline.
Greetings,
Martin
-------------- next part --------------
diff -ur samba-3.0.28.orig/source/param/loadparm.c samba-3.0.28.patchset/source/param/loadparm.c
--- samba-3.0.28.orig/source/param/loadparm.c 2007-11-15 04:15:04.000000000 +0100
+++ samba-3.0.28.patchset/source/param/loadparm.c 2007-12-18 13:41:45.000000000 +0100
@@ -359,6 +359,7 @@
char *szHideFiles;
char *szVetoOplockFiles;
char *comment;
+ char *location;
char *force_user;
char *force_group;
char **readlist;
@@ -501,6 +502,7 @@
NULL, /* szHideFiles */
NULL, /* szVetoOplockFiles */
NULL, /* comment */
+ NULL, /* location */
NULL, /* force user */
NULL, /* force group */
NULL, /* readlist */
@@ -2050,6 +2052,7 @@
FN_LOCAL_STRING(lp_magicscript, szMagicScript)
FN_LOCAL_STRING(lp_magicoutput, szMagicOutput)
FN_LOCAL_STRING(lp_comment, comment)
+FN_LOCAL_STRING(lp_location, location)
FN_LOCAL_STRING(lp_force_user, force_user)
FN_LOCAL_STRING(lp_force_group, force_group)
FN_LOCAL_LIST(lp_readlist, readlist)
@@ -4121,7 +4124,7 @@
Auto-load one printer.
***************************************************************************/
-void lp_add_one_printer(char *name, char *comment)
+void lp_add_one_printer(char *name, char *comment, char *location)
{
int printers = lp_servicenumber(PRINTERS_NAME);
int i;
@@ -4130,6 +4133,7 @@
lp_add_printer(name, printers);
if ((i = lp_servicenumber(name)) >= 0) {
string_set(&ServicePtrs[i]->comment, comment);
+ string_set(&ServicePtrs[i]->location, location);
ServicePtrs[i]->autoloaded = True;
}
}
diff -ur samba-3.0.28.orig/source/printing/nt_printing.c samba-3.0.28.patchset/source/printing/nt_printing.c
--- samba-3.0.28.orig/source/printing/nt_printing.c 2007-11-15 04:15:04.000000000 +0100
+++ samba-3.0.28.patchset/source/printing/nt_printing.c 2007-12-20 09:19:34.000000000 +0100
@@ -3769,7 +3769,7 @@
fstrcpy(info->printprocessor, "winprint");
fstrcpy(info->datatype, "RAW");
-#ifdef HAVE_CUPS
+#ifdef HAVE_CUPS_BLOAT
if ( (enum printing_types)lp_printing(snum) == PRINT_CUPS ) {
/* Pull the location and comment strings from cups if we don't
already have one */
@@ -3873,7 +3873,7 @@
fstrcpy(info->printername, printername);
-#ifdef HAVE_CUPS
+#ifdef HAVE_CUPS_BLOAT
if ( (enum printing_types)lp_printing(snum) == PRINT_CUPS ) {
/* Pull the location and comment strings from cups if we don't
already have one */
diff -ur samba-3.0.28.orig/source/printing/pcap.c samba-3.0.28.patchset/source/printing/pcap.c
--- samba-3.0.28.orig/source/printing/pcap.c 2007-11-15 04:15:04.000000000 +0100
+++ samba-3.0.28.patchset/source/printing/pcap.c 2007-12-18 13:41:45.000000000 +0100
@@ -67,12 +67,13 @@
typedef struct pcap_cache {
char *name;
char *comment;
+ char *location;
struct pcap_cache *next;
} pcap_cache_t;
static pcap_cache_t *pcap_cache = NULL;
-BOOL pcap_cache_add(const char *name, const char *comment)
+BOOL pcap_cache_add(const char *name, const char *comment, const char *location)
{
pcap_cache_t *p;
@@ -81,6 +82,7 @@
p->name = SMB_STRDUP(name);
p->comment = (comment && *comment) ? SMB_STRDUP(comment) : NULL;
+ p->location = (location && *location) ? SMB_STRDUP(location) : NULL;
p->next = pcap_cache;
pcap_cache = p;
@@ -97,6 +99,7 @@
SAFE_FREE(p->name);
SAFE_FREE(p->comment);
+ SAFE_FREE(p->location);
SAFE_FREE(p);
}
}
@@ -210,7 +213,7 @@
comment[60] = 0;
name[MAXPRINTERLEN] = 0;
- if (*name && !pcap_cache_add(name, comment)) {
+ if (*name && !pcap_cache_add(name, comment, NULL)) {
x_fclose(pcap_file);
goto done;
}
@@ -252,12 +255,12 @@
XXX: I'm not sure if this comment still applies.. Anyone? -Rob
***************************************************************************/
-void pcap_printer_fn(void (*fn)(char *, char *))
+void pcap_printer_fn(void (*fn)(char *, char *, char *))
{
pcap_cache_t *p;
for (p = pcap_cache; p != NULL; p = p->next)
- fn(p->name, p->comment);
+ fn(p->name, p->comment, p->location);
return;
}
diff -ur samba-3.0.28.orig/source/printing/print_aix.c samba-3.0.28.patchset/source/printing/print_aix.c
--- samba-3.0.28.orig/source/printing/print_aix.c 2007-11-15 04:15:04.000000000 +0100
+++ samba-3.0.28.patchset/source/printing/print_aix.c 2007-12-20 09:08:29.000000000 +0100
@@ -75,7 +75,7 @@
/* name is found without stanza device */
/* probably a good printer ??? */
iEtat = 0;
- if (!pcap_cache_add(name, NULL)) {
+ if (!pcap_cache_add(name, NULL, NULL)) {
safe_free(line);
x_fclose(pfile);
return False;
@@ -89,7 +89,7 @@
} else if (strstr_m(line, "device")) {
/* it's a good virtual printer */
iEtat = 0;
- if (!pcap_cache_add(name, NULL)) {
+ if (!pcap_cache_add(name, NULL, NULL)) {
safe_free(line);
x_fclose(pfile);
return False;
diff -ur samba-3.0.28.orig/source/printing/print_cups.c samba-3.0.28.patchset/source/printing/print_cups.c
--- samba-3.0.28.orig/source/printing/print_cups.c 2007-11-15 04:15:04.000000000 +0100
+++ samba-3.0.28.patchset/source/printing/print_cups.c 2007-12-20 09:52:19.000000000 +0100
@@ -83,11 +83,14 @@
ipp_attribute_t *attr; /* Current attribute */
cups_lang_t *language = NULL; /* Default language */
char *name, /* printer-name attribute */
- *info; /* printer-info attribute */
+ *info, /* printer-info attribute */
+ *location; /* printer-location attribute */
+
static const char *requested[] =/* Requested attributes */
{
"printer-name",
"printer-info"
+ "printer-location"
};
BOOL ret = False;
@@ -161,6 +164,7 @@
name = NULL;
info = NULL;
+ location = NULL;
while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
if (strcmp(attr->name, "printer-name") == 0 &&
@@ -170,6 +174,10 @@
if (strcmp(attr->name, "printer-info") == 0 &&
attr->value_tag == IPP_TAG_TEXT)
info = attr->values[0].string.text;
+
+ if (strcmp(attr->name, "printer-location") == 0 &&
+ attr->value_tag == IPP_TAG_TEXT)
+ location = attr->values[0].string.text;
attr = attr->next;
}
@@ -181,7 +189,7 @@
if (name == NULL)
break;
- if (!pcap_cache_add(name, info)) {
+ if (!pcap_cache_add(name, info, location)) {
goto out;
}
}
@@ -241,6 +249,7 @@
name = NULL;
info = NULL;
+ location = NULL;
while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
if (strcmp(attr->name, "printer-name") == 0 &&
@@ -251,6 +260,10 @@
attr->value_tag == IPP_TAG_TEXT)
info = attr->values[0].string.text;
+ if (strcmp(attr->name, "printer-location") == 0 &&
+ attr->value_tag == IPP_TAG_TEXT)
+ location = attr->values[0].string.text;
+
attr = attr->next;
}
@@ -261,7 +274,7 @@
if (name == NULL)
break;
- if (!pcap_cache_add(name, info)) {
+ if (!pcap_cache_add(name, info, location)) {
goto out;
}
}
diff -ur samba-3.0.28.orig/source/printing/print_iprint.c samba-3.0.28.patchset/source/printing/print_iprint.c
--- samba-3.0.28.orig/source/printing/print_iprint.c 2007-11-15 04:15:04.000000000 +0100
+++ samba-3.0.28.patchset/source/printing/print_iprint.c 2007-12-20 09:11:27.000000000 +0100
@@ -169,6 +169,7 @@
cups_lang_t *language = NULL; /* Default language */
char *name, /* printer-name attribute */
*info, /* printer-info attribute */
+ *location, /* printer-location attribute */
smb_enabled, /* smb-enabled attribute */
secure; /* security-enabled attrib. */
@@ -179,6 +180,7 @@
"printer-name",
"security-enabled",
"printer-info",
+ "printer-location",
"smb-enabled"
};
@@ -247,6 +249,7 @@
name = NULL;
info = NULL;
+ location = NULL;
smb_enabled= 1;
secure = 0;
@@ -260,6 +263,11 @@
attr->value_tag == IPP_TAG_TEXTLANG))
info = attr->values[0].string.text;
+ if (strcmp(attr->name, "printer-location") == 0 &&
+ (attr->value_tag == IPP_TAG_TEXT ||
+ attr->value_tag == IPP_TAG_TEXTLANG))
+ location = attr->values[0].string.text;
+
/*
* If the smb-enabled attribute is present and the
* value is set to 0, don't show the printer.
@@ -297,7 +305,7 @@
*/
if (name != NULL && !secure && smb_enabled)
- pcap_cache_add(name, info);
+ pcap_cache_add(name, info, location);
}
out:
diff -ur samba-3.0.28.orig/source/printing/print_svid.c samba-3.0.28.patchset/source/printing/print_svid.c
--- samba-3.0.28.orig/source/printing/print_svid.c 2007-11-15 04:15:04.000000000 +0100
+++ samba-3.0.28.patchset/source/printing/print_svid.c 2007-12-20 09:13:31.000000000 +0100
@@ -111,7 +111,7 @@
*tmp = '\0';
/* add it to the cache */
- if (!pcap_cache_add(name, NULL)) {
+ if (!pcap_cache_add(name, NULL, NULL)) {
file_lines_free(lines);
return False;
}
diff -ur samba-3.0.28.orig/source/rpc_server/srv_spoolss_nt.c samba-3.0.28.patchset/source/rpc_server/srv_spoolss_nt.c
--- samba-3.0.28.orig/source/rpc_server/srv_spoolss_nt.c 2007-12-10 16:05:44.000000000 +0100
+++ samba-3.0.28.patchset/source/rpc_server/srv_spoolss_nt.c 2007-12-20 11:04:12.000000000 +0100
@@ -2902,7 +2902,9 @@
pstring temp;
uint32 len;
- len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE);
+ if (*printer->info_2->location == '\0')
+ len = rpcstr_push(temp, lp_location(snum), sizeof(temp)-2, STR_TERMINATE); else
+ len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
if (len) {
@@ -4205,8 +4207,10 @@
init_unistr(&printer->comment, lp_comment(snum)); /* comment */
else
init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */
-
- init_unistr(&printer->location, ntprinter->info_2->location); /* location */
+ if (*ntprinter->info_2->location == '\0')
+ init_unistr(&printer->location, lp_location(snum)); /* location */
+ else
+ init_unistr(&printer->location, ntprinter->info_2->location); /* saved location */
init_unistr(&printer->sepfile, ntprinter->info_2->sepfile); /* separator file */
init_unistr(&printer->printprocessor, ntprinter->info_2->printprocessor);/* print processor */
init_unistr(&printer->datatype, ntprinter->info_2->datatype); /* datatype */
More information about the samba-technical
mailing list