diff options
author | Günther Deschner <gd@samba.org> | 2011-05-13 10:02:42 +0200 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2011-05-16 12:54:33 +0200 |
commit | 854467851da48e02dcd8f869cb031c8943707017 (patch) | |
tree | 0d5e7b3b5b84bb26a32f76fbb9a28f65ef686795 /source3/printing | |
parent | d4d31b31760ac1e7361f453564b63f17685bf58f (diff) | |
download | samba-854467851da48e02dcd8f869cb031c8943707017.tar.gz samba-854467851da48e02dcd8f869cb031c8943707017.tar.bz2 samba-854467851da48e02dcd8f869cb031c8943707017.zip |
s3-printing: Get the location info from cups.
Signed-off-by: Günther Deschner <gd@samba.org>
Diffstat (limited to 'source3/printing')
-rw-r--r-- | source3/printing/pcap.c | 24 | ||||
-rw-r--r-- | source3/printing/pcap.h | 8 | ||||
-rw-r--r-- | source3/printing/print_aix.c | 4 | ||||
-rw-r--r-- | source3/printing/print_cups.c | 18 | ||||
-rw-r--r-- | source3/printing/print_iprint.c | 2 | ||||
-rw-r--r-- | source3/printing/print_standard.c | 2 | ||||
-rw-r--r-- | source3/printing/print_svid.c | 2 | ||||
-rw-r--r-- | source3/printing/printer_list.c | 42 | ||||
-rw-r--r-- | source3/printing/printer_list.h | 8 |
9 files changed, 80 insertions, 30 deletions
diff --git a/source3/printing/pcap.c b/source3/printing/pcap.c index 7208f4b7f8..62db4f5efc 100644 --- a/source3/printing/pcap.c +++ b/source3/printing/pcap.c @@ -43,10 +43,11 @@ struct pcap_cache { char *name; char *comment; + char *location; struct pcap_cache *next; }; -bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment) +bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment, const char *location) { struct pcap_cache *p; @@ -55,9 +56,11 @@ bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, cons p->name = SMB_STRDUP(name); p->comment = (comment && *comment) ? SMB_STRDUP(comment) : NULL; + p->location = (location && *location) ? SMB_STRDUP(location) : NULL; - DEBUG(11,("pcap_cache_add_specific: Adding name %s info %s\n", - p->name, p->comment ? p->comment : "")); + DEBUG(11,("pcap_cache_add_specific: Adding name %s info %s, location: %s\n", + p->name, p->comment ? p->comment : "", + p->location ? p->location : "")); p->next = *ppcache; *ppcache = p; @@ -74,17 +77,18 @@ void pcap_cache_destroy_specific(struct pcap_cache **pp_cache) SAFE_FREE(p->name); SAFE_FREE(p->comment); + SAFE_FREE(p->location); SAFE_FREE(p); } *pp_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) { NTSTATUS status; time_t t = time_mono(NULL); - status = printer_list_set_printer(talloc_tos(), name, comment, t); + status = printer_list_set_printer(talloc_tos(), name, comment, location, t); return NT_STATUS_IS_OK(status); } @@ -109,7 +113,7 @@ bool pcap_cache_replace(const struct pcap_cache *pcache) } for (p = pcache; p; p = p->next) { - pcap_cache_add(p->name, p->comment); + pcap_cache_add(p->name, p->comment, p->location); } status = printer_list_clean_old(); @@ -205,7 +209,7 @@ bool pcap_printername_ok(const char *printername) { NTSTATUS status; - status = printer_list_get_printer(talloc_tos(), printername, NULL, 0); + status = printer_list_get_printer(talloc_tos(), printername, NULL, NULL, 0); return NT_STATUS_IS_OK(status); } @@ -214,18 +218,18 @@ run a function on each printer name in the printcap file. ***************************************************************************/ void pcap_printer_fn_specific(const struct pcap_cache *pc, - void (*fn)(const char *, const char *, void *), + void (*fn)(const char *, const char *, const char *, void *), void *pdata) { const struct pcap_cache *p; for (p = pc; p != NULL; p = p->next) - fn(p->name, p->comment, pdata); + fn(p->name, p->comment, p->location, pdata); return; } -void pcap_printer_fn(void (*fn)(const char *, const char *, void *), void *pdata) +void pcap_printer_fn(void (*fn)(const char *, const char *, const char *, void *), void *pdata) { NTSTATUS status; diff --git a/source3/printing/pcap.h b/source3/printing/pcap.h index e24142e8b2..e8276f9aad 100644 --- a/source3/printing/pcap.h +++ b/source3/printing/pcap.h @@ -20,13 +20,13 @@ struct pcap_cache; /* The following definitions come from printing/pcap.c */ -bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment); +bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment, const char *location); void pcap_cache_destroy_specific(struct pcap_cache **ppcache); -bool pcap_cache_add(const char *name, const char *comment); +bool pcap_cache_add(const char *name, const char *comment, const char *location); bool pcap_cache_loaded(void); bool pcap_cache_replace(const struct pcap_cache *cache); -void pcap_printer_fn_specific(const struct pcap_cache *, void (*fn)(const char *, const char *, void *), void *); -void pcap_printer_fn(void (*fn)(const char *, const char *, void *), void *); +void pcap_printer_fn_specific(const struct pcap_cache *, void (*fn)(const char *, const char *, const char *, void *), void *); +void pcap_printer_fn(void (*fn)(const char *, const char *, const char *, void *), void *); void pcap_cache_reload(struct tevent_context *ev, struct messaging_context *msg_ctx, diff --git a/source3/printing/print_aix.c b/source3/printing/print_aix.c index b7198d3632..23d9a86fe3 100644 --- a/source3/printing/print_aix.c +++ b/source3/printing/print_aix.c @@ -86,7 +86,7 @@ bool aix_cache_reload(void) /* 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); TALLOC_FREE(ctx); @@ -101,7 +101,7 @@ bool aix_cache_reload(void) } 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); TALLOC_FREE(ctx); diff --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c index 077d82bcbf..44890131e8 100644 --- a/source3/printing/print_cups.c +++ b/source3/printing/print_cups.c @@ -163,6 +163,7 @@ static bool process_cups_printers_response(TALLOC_CTX *mem_ctx, ipp_attribute_t *attr; char *name; char *info; + char *location = NULL; struct pcap_printer *printer; bool ret_ok = false; @@ -206,6 +207,16 @@ static bool process_cups_printers_response(TALLOC_CTX *mem_ctx, } } + if (strcmp(attr->name, "printer-location") == 0 && + attr->value_tag == IPP_TAG_TEXT) { + if (!pull_utf8_talloc(mem_ctx, + &location, + attr->values[0].string.text, + &size)) { + goto err_out; + } + } + attr = attr->next; } @@ -229,6 +240,7 @@ static bool process_cups_printers_response(TALLOC_CTX *mem_ctx, pcap_data->printers = printer; pcap_data->printers[pcap_data->count].name = name; pcap_data->printers[pcap_data->count].info = info; + pcap_data->printers[pcap_data->count].location = location; pcap_data->count++; } @@ -252,7 +264,8 @@ static bool cups_cache_reload_async(int fd) static const char *requested[] =/* Requested attributes */ { "printer-name", - "printer-info" + "printer-info", + "printer-location" }; bool ret = False; enum ndr_err_code ndr_ret; @@ -478,7 +491,8 @@ static void cups_async_callback(struct event_context *event_ctx, for (i = 0; i < pcap_data.count; i++) { ret_ok = pcap_cache_add_specific(&tmp_pcap_cache, pcap_data.printers[i].name, - pcap_data.printers[i].info); + pcap_data.printers[i].info, + pcap_data.printers[i].location); if (!ret_ok) { DEBUG(0, ("failed to add to tmp pcap cache\n")); goto err_out; diff --git a/source3/printing/print_iprint.c b/source3/printing/print_iprint.c index ea375da3b7..1392cba7b8 100644 --- a/source3/printing/print_iprint.c +++ b/source3/printing/print_iprint.c @@ -297,7 +297,7 @@ static int iprint_cache_add_printer(http_t *http, */ if (name != NULL && !secure && smb_enabled) - pcap_cache_add(name, info); + pcap_cache_add(name, info, NULL); } out: diff --git a/source3/printing/print_standard.c b/source3/printing/print_standard.c index a8460935c9..6a86d84b1e 100644 --- a/source3/printing/print_standard.c +++ b/source3/printing/print_standard.c @@ -120,7 +120,7 @@ bool std_pcap_cache_reload(const char *pcap_name) 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); return false; } diff --git a/source3/printing/print_svid.c b/source3/printing/print_svid.c index 4929be14bc..222649308c 100644 --- a/source3/printing/print_svid.c +++ b/source3/printing/print_svid.c @@ -111,7 +111,7 @@ bool sysv_cache_reload(void) *tmp = '\0'; /* add it to the cache */ - if (!pcap_cache_add(name, NULL)) { + if (!pcap_cache_add(name, NULL, NULL)) { TALLOC_FREE(lines); return False; } diff --git a/source3/printing/printer_list.c b/source3/printing/printer_list.c index d8be89363e..d28278d069 100644 --- a/source3/printing/printer_list.c +++ b/source3/printing/printer_list.c @@ -27,7 +27,7 @@ #define PL_KEY_PREFIX "PRINTERLIST/PRN/" #define PL_KEY_FORMAT PL_KEY_PREFIX"%s" #define PL_TIMESTAMP_KEY "PRINTERLIST/GLOBAL/LAST_REFRESH" -#define PL_DATA_FORMAT "ddPP" +#define PL_DATA_FORMAT "ddPPP" #define PL_TSTAMP_FORMAT "dd" static struct db_context *get_printer_list_db(void) @@ -65,6 +65,7 @@ bool printer_list_parent_init(void) NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx, const char *name, const char **comment, + const char **location, time_t *last_refresh) { struct db_context *db; @@ -73,6 +74,7 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx, uint32_t time_h, time_l; char *nstr = NULL; char *cstr = NULL; + char *lstr = NULL; NTSTATUS status; int ret; @@ -96,7 +98,7 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx, ret = tdb_unpack(data.dptr, data.dsize, PL_DATA_FORMAT, - &time_h, &time_l, &nstr, &cstr); + &time_h, &time_l, &nstr, &cstr, &lstr); if (ret == -1) { DEBUG(1, ("Failed to un pack printer data")); status = NT_STATUS_INTERNAL_DB_CORRUPTION; @@ -116,6 +118,15 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx, } } + if (location) { + *location = talloc_strdup(mem_ctx, lstr); + if (*location == NULL) { + DEBUG(1, ("Failed to strdup location!\n")); + status = NT_STATUS_NO_MEMORY; + goto done; + } + } + status = NT_STATUS_OK; done: @@ -128,6 +139,7 @@ done: NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx, const char *name, const char *comment, + const char *location, time_t last_refresh) { struct db_context *db; @@ -136,6 +148,7 @@ NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx, uint64_t time_64; uint32_t time_h, time_l; const char *str = NULL; + const char *str2 = NULL; NTSTATUS status; int len; @@ -156,11 +169,18 @@ NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx, str = ""; } + if (location) { + str2 = location; + } else { + str2 = ""; + } + + time_64 = last_refresh; time_l = time_64 & 0xFFFFFFFFL; time_h = time_64 >> 32; - len = tdb_pack(NULL, 0, PL_DATA_FORMAT, time_h, time_l, name, str); + len = tdb_pack(NULL, 0, PL_DATA_FORMAT, time_h, time_l, name, str, str2); data.dptr = talloc_array(key, uint8_t, len); if (!data.dptr) { @@ -289,6 +309,7 @@ static int printer_list_clean_fn(struct db_record *rec, void *private_data) time_t refresh; char *name; char *comment; + char *location; int ret; /* skip anything that does not contain PL_DATA_FORMAT data */ @@ -298,7 +319,8 @@ static int printer_list_clean_fn(struct db_record *rec, void *private_data) } ret = tdb_unpack(rec->value.dptr, rec->value.dsize, - PL_DATA_FORMAT, &time_h, &time_l, &name, &comment); + PL_DATA_FORMAT, &time_h, &time_l, &name, &comment, + &location); if (ret == -1) { DEBUG(1, ("Failed to un pack printer data")); state->status = NT_STATUS_INTERNAL_DB_CORRUPTION; @@ -307,6 +329,7 @@ static int printer_list_clean_fn(struct db_record *rec, void *private_data) SAFE_FREE(name); SAFE_FREE(comment); + SAFE_FREE(location); refresh = (time_t)(((uint64_t)time_h << 32) + time_l); @@ -342,7 +365,7 @@ NTSTATUS printer_list_clean_old(void) } struct printer_list_exec_state { - void (*fn)(const char *, const char *, void *); + void (*fn)(const char *, const char *, const char *, void *); void *private_data; NTSTATUS status; }; @@ -354,6 +377,7 @@ static int printer_list_exec_fn(struct db_record *rec, void *private_data) uint32_t time_h, time_l; char *name; char *comment; + char *location; int ret; /* always skip PL_TIMESTAMP_KEY key */ @@ -362,21 +386,23 @@ static int printer_list_exec_fn(struct db_record *rec, void *private_data) } ret = tdb_unpack(rec->value.dptr, rec->value.dsize, - PL_DATA_FORMAT, &time_h, &time_l, &name, &comment); + PL_DATA_FORMAT, &time_h, &time_l, &name, &comment, + &location); if (ret == -1) { DEBUG(1, ("Failed to un pack printer data")); state->status = NT_STATUS_INTERNAL_DB_CORRUPTION; return -1; } - state->fn(name, comment, state->private_data); + state->fn(name, comment, location, state->private_data); SAFE_FREE(name); SAFE_FREE(comment); + SAFE_FREE(location); return 0; } -NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, void *), +NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, const char *, void *), void *private_data) { struct printer_list_exec_state state; diff --git a/source3/printing/printer_list.h b/source3/printing/printer_list.h index fce3e34248..fb2e007ae6 100644 --- a/source3/printing/printer_list.h +++ b/source3/printing/printer_list.h @@ -32,6 +32,8 @@ bool printer_list_parent_init(void); * * @param[out] comment A pointer to store the comment of the printer. * + * @param[out] location A pointer to store the location of the printer. + * * @param[out] last_refresh A pointer to store the last refresh time of the * printer. * @@ -41,6 +43,7 @@ bool printer_list_parent_init(void); NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx, const char *name, const char **comment, + const char **location, time_t *last_refresh); /** @@ -52,6 +55,8 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx, * * @param[in] comment The comment to store in the db. * + * @param[in] location The location to store in the db. + * * @param[in] last_refresh The last refresh time of the printer to store in * the db. * @@ -61,6 +66,7 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx, NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx, const char *name, const char *comment, + const char *location, time_t last_refresh); /** @@ -94,6 +100,6 @@ NTSTATUS printer_list_mark_reload(void); */ NTSTATUS printer_list_clean_old(void); -NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, void *), +NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, const char *, void *), void *private_data); #endif /* _PRINTER_LIST_H_ */ |