More printer publishing code.
authorJim McDonough <jmcd@samba.org>
Fri, 13 Dec 2002 18:56:48 +0000 (18:56 +0000)
committerJim McDonough <jmcd@samba.org>
Fri, 13 Dec 2002 18:56:48 +0000 (18:56 +0000)
- Add published attribute to info2, needed for win clients to work properly
- Return proper info on getprinter 7

This means you can now look at the sharing tab of a printer and get correct
info about whether it is published or not, and change it.
(This used to be commit adda04379ee46f105436262663652f3f576fa3cf)

source3/include/rpc_spoolss.h
source3/libads/ldap.c
source3/printing/nt_printing.c
source3/rpc_server/srv_spoolss_nt.c

index 3a6d6eb9ec62aed4ca2898cece8c6760ebdd4100..249053403d17de0d74a1e0ff9fa93bbb14b27e51 100755 (executable)
@@ -371,6 +371,7 @@ PRINTER_MESSAGE_INFO;
 #define PRINTER_ATTRIBUTE_ENABLE_BIDI          0x00000800
 
 #define PRINTER_ATTRIBUTE_RAW_ONLY             0x00001000
+#define PRINTER_ATTRIBUTE_PUBLISHED            0x00002000
 
 #define NO_PRIORITY     0
 #define MAX_PRIORITY   99
@@ -991,8 +992,8 @@ PRINTER_INFO_5;
 
 #define SPOOL_DS_PUBLISH       1
 #define SPOOL_DS_UPDATE                2
-#define SPOOL_DS_UNPUBLISH     3
-#define SPOOL_DS_REPUBLISH     4
+#define SPOOL_DS_UNPUBLISH     4
+#define SPOOL_DS_PENDING        0x80000000
 
 typedef struct printer_info_7
 {
index fcb96dd174e9849673675e87667cd2c4e8411484..af9a6451fe32e9f2909da4f6b38c2ff850797033 100644 (file)
@@ -1581,6 +1581,32 @@ BOOL ads_pull_uint32(ADS_STRUCT *ads,
        return True;
 }
 
+/**
+ * pull a single objectGUID from an ADS result
+ * @param ads connection to ADS server
+ * @param msg results of search
+ * @param guid 37-byte area to receive text guid
+ * @return boolean indicating success
+ **/
+BOOL ads_pull_guid(ADS_STRUCT *ads,
+                  void *msg, GUID *guid)
+{
+       char **values;
+
+       values = ldap_get_values(ads->ld, msg, "objectGUID");
+       if (!values) return False;
+       
+       if (values[0]) {
+               memcpy(guid, values[0], sizeof(GUID));
+               ldap_value_free(values);
+               return True;
+       }
+       ldap_value_free(values);
+       return False;
+
+}
+
+
 /**
  * pull a single DOM_SID from a ADS result
  * @param ads connection to ads server
index cdcca6bbfed4fa6b0497e3f36f399dcd2ced1e2e..532ab0794cd29f6db3bf2478d3e3fef4d07265aa 100644 (file)
@@ -2540,7 +2540,8 @@ static BOOL map_nt_printer_info2_to_dsspooler(NT_PRINTER_INFO_LEVEL_2 *info2)
        map_dword_into_ctr(ctr, SPOOL_REG_PRIORITY, info2->priority);
 
        map_bool_into_ctr(ctr, SPOOL_REG_PRINTKEEPPRINTEDJOBS,
-                         (info2->attributes & 0x100));
+                         (info2->attributes & 
+                          PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
 
        switch (info2->attributes & 0x3) {
        case 0:
@@ -2583,11 +2584,12 @@ WERROR nt_printer_publish(int snum, int action)
        if (!W_ERROR_IS_OK(win_rc))
                return win_rc;
 
-       if ((SPOOL_DS_PUBLISH == action) || (SPOOL_DS_UPDATE == action) ||
-           (SPOOL_DS_REPUBLISH == action)) {
+       if ((SPOOL_DS_PUBLISH == action) || (SPOOL_DS_UPDATE == action)) {
                if (!(map_nt_printer_info2_to_dsspooler(printer->info_2)))
                        return WERR_NOMEM;
 
+               printer->info_2->attributes |= PRINTER_ATTRIBUTE_PUBLISHED;
+
                win_rc = mod_a_printer(*printer, 2);
                if (!W_ERROR_IS_OK(win_rc)) {
                        DEBUG(3, ("nt_printer_publish: err %d saving data\n",
@@ -2600,13 +2602,22 @@ WERROR nt_printer_publish(int snum, int action)
                                                  &printer->info_2->data);
                ads_mod_str(ctx, &mods, SPOOL_REG_PRINTERNAME, 
                            lp_servicename(snum));
+       } else {
+               printer->info_2->attributes ^= PRINTER_ATTRIBUTE_PUBLISHED;
+               win_rc = mod_a_printer(*printer, 2);
+               if (!W_ERROR_IS_OK(win_rc)) {
+                       DEBUG(3, ("nt_printer_publish: err %d saving data\n",
+                                 W_ERROR_V(win_rc)));
+                       free_a_printer(&printer, 2);
+                       return win_rc;
+               }
        }
 
        ads = ads_init(NULL, NULL, lp_ads_server());
 
        ads_rc = ads_connect(ads);
 
-       if ((SPOOL_DS_UNPUBLISH == action) || (SPOOL_DS_REPUBLISH == action)) {
+       if (SPOOL_DS_UNPUBLISH == action) {
                ads_rc = ads_find_printer_on_server(ads, &res, 
                                printer->info_2->sharename, global_myname());
                if (ADS_ERR_OK(ads_rc) && ads_count_replies(ads, res)) {
@@ -2617,8 +2628,7 @@ WERROR nt_printer_publish(int snum, int action)
                }
        }
 
-       if ((SPOOL_DS_PUBLISH == action) || (SPOOL_DS_UPDATE == action) ||
-           (SPOOL_DS_REPUBLISH == action)) {
+       if ((SPOOL_DS_PUBLISH == action) || (SPOOL_DS_UPDATE == action)) {
                ads_find_machine_acct(ads, &res, global_myname());
                srv_dn = ldap_get_dn(ads->ld, res);
                ads_msgfree(ads, res);
index fd223304498f1b82a7a357cf7d260443d502e725..0e3d69924b6a597004c024db9564eabdd910f1b3 100644 (file)
@@ -4148,14 +4148,50 @@ static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum)
 }
 
 /********************************************************************
- * construct_printer_info_5
- * fill a printer_info_5 struct
+ * construct_printer_info_7
+ * fill a printer_info_7 struct
  ********************************************************************/
 
-static BOOL construct_printer_info_7(PRINTER_INFO_7 *printer)
+static BOOL construct_printer_info_7(PRINTER_INFO_7 *printer, int snum)
 {
+#ifdef HAVE_ADS
+       char *guid_str = NULL;
+       GUID guid;
+       ADS_STRUCT *ads;
+       ADS_STATUS ads_rc;
+       void *res = NULL;
+       char *prt_dn;
+       const char *attrs[] = {"objectGUID", NULL};
+       
+       printer->action = SPOOL_DS_UNPUBLISH;
+
+       ads = ads_init(NULL, NULL, lp_ads_server());
+       ads_rc = ads_connect(ads);
+       ads_rc = ads_find_printer_on_server(ads, &res, lp_servicename(snum),
+                                           global_myname());
+       if (ADS_ERR_OK(ads_rc) && ads_count_replies(ads, res)) {
+               prt_dn = ads_get_dn(ads, res);
+               ads_msgfree(ads, res);
+               if (prt_dn && 
+                   ADS_ERR_OK(ads_search_dn(ads, &res, prt_dn, attrs))) {
+                       ads_rc = ads_search_dn(ads, &res, prt_dn, attrs);
+                       ads_memfree(ads, prt_dn);
+                       ads_pull_guid(ads, res, &guid);
+                       printer->action = SPOOL_DS_PUBLISH;
+               }
+       }
+
+       ads_msgfree(ads, res);
+       
+       asprintf(&guid_str, "{%s}", uuid_string_static(guid));
+       strupper(guid_str);
+       init_unistr(&printer->guid, guid_str);
+
+#else
+       printer->action = SPOOL_DS_UNPUBLISH;
        init_unistr(&printer->guid, "");
-       printer->action = 0;
+#endif
+
        return True;
 }
 
@@ -4722,7 +4758,7 @@ static WERROR getprinter_level_7(int snum, NEW_BUFFER *buffer, uint32 offered, u
        if((printer=(PRINTER_INFO_7*)malloc(sizeof(PRINTER_INFO_7)))==NULL)
                return WERR_NOMEM;
 
-       if (!construct_printer_info_7(printer))
+       if (!construct_printer_info_7(printer, snum))
                return WERR_NOMEM;
        
        /* check the required size. */