The branch, master has been updated
       via  db46b2b s3-winbindd: Use rpc_open_pipe_interface in winbindd.
       via  e580c6d s3-rpc_server: Use talloc_stackframe.
       via  8ec7aae s3-rpc_server: Moved ncacn_np declarations in common header 
file.
       via  390642a s3-rpc_server: Moved "external" pipe functions to 
rpc_ncacn_np.c.
       via  34225c9 s3-rpc_server: Added new parametric option 'rpc_server'
       via  738c843 s3-rpc_server: Renamed rpc_ncacn_np_internal.c.
       via  5685914 s3-rpc_server: Convert rpc_connect_spoolss_pipe into a 
generic interface.
       via  344260d s3-rpc_server: Added support for internal connections to 
external daemons.
       via  e7c4555 s3-rpc_server: Accept connections and process requests.
       via  f7f9916 s3-rpc_server: Added helper functions to read data from a 
ncacn socket.
       via  7b1748d s3-rpc_client: Added a tstream based transport.
       via  a1f1da7 s3-rpc_server: Addded function to create custom 
pipes_struct.
       via  b1fdc5a s3-rpc_server: Add generic listener callback.
       via  3c26e95 s3-rpc_server: Added initial generic RPC server 
infrastructure.
       via  1172187 s3-rpc_server: Added debug to see how much data has been 
read out.
       via  5ccd7a5 s3-rpc_server: Make process_incoming_data() public.
       via  2ef693e s3-rpc_server: Make pipe destructor public.
       via  3f04b54 s3-rpc_server: Fixed unhandled error condition.
       via  94d86a2 s3-misc: Introduce lp_ncalrpc_dir() in S3, like we have in 
S4.
       via  65bd8f8 s3-printing: Document the printer list functions.
       via  25a2d94 s3-printing: Add method to skip refresh if just happned.
       via  7022554 s3-printing: Use printer list tdb in pcap.
       via  d2a027e s3-printing: Added a printer list database.
      from  c35629c s3-nltest: add dsgetdc command.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit db46b2bdb04174b90508605911fa0325fb22fd7f
Author: Simo Sorce <[email protected]>
Date:   Tue Jul 6 15:29:32 2010 -0400

    s3-winbindd: Use rpc_open_pipe_interface in winbindd.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit e580c6d88f4f124e06562fe56c1d9437d1205658
Author: Andreas Schneider <[email protected]>
Date:   Wed Sep 15 11:38:53 2010 +0200

    s3-rpc_server: Use talloc_stackframe.

commit 8ec7aaef48c3d9a6b1f07602c5410b5524099d36
Author: Simo Sorce <[email protected]>
Date:   Wed Jul 7 15:24:30 2010 -0400

    s3-rpc_server: Moved ncacn_np declarations in common header file.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 390642a9e6d1b0d1aacbe17b48c4f3695ee1d80d
Author: Simo Sorce <[email protected]>
Date:   Wed Jul 7 15:24:00 2010 -0400

    s3-rpc_server: Moved "external" pipe functions to rpc_ncacn_np.c.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 34225c93af154fc205be7bf14edd609d39bbdb9c
Author: Andreas Schneider <[email protected]>
Date:   Tue Sep 14 13:37:46 2010 +0200

    s3-rpc_server: Added new parametric option 'rpc_server'
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 738c843e99b780e8b4457eef8c4f94d23e08c754
Author: Simo Sorce <[email protected]>
Date:   Tue Jul 6 13:03:35 2010 -0400

    s3-rpc_server: Renamed rpc_ncacn_np_internal.c.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 5685914344d21e5fdac98c367b3dd1eba555f227
Author: Simo Sorce <[email protected]>
Date:   Tue Jul 6 11:33:15 2010 -0400

    s3-rpc_server: Convert rpc_connect_spoolss_pipe into a generic interface.
    
    This way we have one common way to open internal pipes whether they
    are shortcircuited or piped to an external process.

commit 344260d03e9a50bce051e180df75f696e2478228
Author: Simo Sorce <[email protected]>
Date:   Tue Jun 22 18:03:55 2010 -0400

    s3-rpc_server: Added support for internal connections to external daemons.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit e7c4555b7caf379af38403fe497eea58415b51ed
Author: Simo Sorce <[email protected]>
Date:   Fri Jun 18 10:56:58 2010 -0400

    s3-rpc_server: Accept connections and process requests.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit f7f9916dc78d2fb31f65a5186ce68a66fd707cd7
Author: Simo Sorce <[email protected]>
Date:   Fri Jun 18 10:55:44 2010 -0400

    s3-rpc_server: Added helper functions to read data from a ncacn socket.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 7b1748d959d42ae69cfd2936cbc4fafd76046f02
Author: Simo Sorce <[email protected]>
Date:   Tue Jun 22 18:01:45 2010 -0400

    s3-rpc_client: Added a tstream based transport.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit a1f1da722633f0e52b85ee4bf3420b6c70b9907b
Author: Simo Sorce <[email protected]>
Date:   Fri Jun 18 10:40:19 2010 -0400

    s3-rpc_server: Addded function to create custom pipes_struct.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit b1fdc5a70457979d8aea6574ae135d83efd7628a
Author: Simo Sorce <[email protected]>
Date:   Thu May 20 09:16:29 2010 -0400

    s3-rpc_server: Add generic listener callback.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 3c26e95840454f8a311df037d90663abbda5854c
Author: Simo Sorce <[email protected]>
Date:   Fri Jun 18 11:00:38 2010 -0400

    s3-rpc_server: Added initial generic RPC server infrastructure.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 11721874c3bc47fe7612cae611fbe321f683df6f
Author: Simo Sorce <[email protected]>
Date:   Wed Jun 16 09:03:37 2010 -0400

    s3-rpc_server: Added debug to see how much data has been read out.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 5ccd7a56fa07426c19905d080d6202d7335b4847
Author: Simo Sorce <[email protected]>
Date:   Mon Jun 14 21:11:10 2010 -0400

    s3-rpc_server: Make process_incoming_data() public.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 2ef693e3c83fa0ce298ef8b592d7d4c4ec3dd845
Author: Simo Sorce <[email protected]>
Date:   Mon Jun 7 15:18:31 2010 -0400

    s3-rpc_server: Make pipe destructor public.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 3f04b54197ba7dadd9831d7b5d1f57cf9d0b4014
Author: Simo Sorce <[email protected]>
Date:   Tue Jun 22 18:03:17 2010 -0400

    s3-rpc_server: Fixed unhandled error condition.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 94d86a22a1ecfb74ccaa4ce441c33186544a69c8
Author: Simo Sorce <[email protected]>
Date:   Thu May 20 08:39:10 2010 -0400

    s3-misc: Introduce lp_ncalrpc_dir() in S3, like we have in S4.

commit 65bd8f881db3315c1369835fe6cfc2f27a04ae15
Author: Andreas Schneider <[email protected]>
Date:   Mon Sep 13 11:29:31 2010 +0200

    s3-printing: Document the printer list functions.

commit 25a2d94974c7befd13f90e52b61e297c31ae52e9
Author: Simo Sorce <[email protected]>
Date:   Fri May 14 15:49:29 2010 -0400

    s3-printing: Add method to skip refresh if just happned.
    
    This way if multiple process try to refresh at the same time we don't do it
    over and over again.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit 7022554915a0dc7522151eb2a9a21317372471b9
Author: Simo Sorce <[email protected]>
Date:   Thu May 13 18:42:55 2010 -0400

    s3-printing: Use printer list tdb in pcap.
    
    Signed-off-by: Andreas Schneider <[email protected]>

commit d2a027ea941a963de2ff2ee569440a408e883869
Author: Simo Sorce <[email protected]>
Date:   Thu May 13 11:35:59 2010 -0400

    s3-printing: Added a printer list database.
    
    Signed-off-by: Andreas Schneider <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 docs-xml/smbdotconf/misc/rpcserver.xml     |   46 ++
 source3/Makefile.in                        |   15 +-
 source3/include/proto.h                    |   19 +-
 source3/librpc/rpc/dcerpc.h                |    4 +
 source3/param/loadparm.c                   |   14 +
 source3/printing/nt_printing_migrate.c     |    1 +
 source3/printing/pcap.c                    |   62 ++-
 source3/printing/printer_list.c            |  415 +++++++++++++
 source3/printing/printer_list.h            |  108 ++++
 source3/printing/printspoolss.c            |   26 +-
 source3/rpc_client/rpc_transport_tstream.c |  361 ++++++++++++
 source3/rpc_server/rpc_ncacn_np.c          |  875 ++++++++++++++++++++++++++++
 source3/rpc_server/rpc_ncacn_np.h          |   61 ++
 source3/rpc_server/rpc_ncacn_np_internal.c |  579 ------------------
 source3/rpc_server/rpc_server.c            |  630 ++++++++++++++++++++
 source3/rpc_server/rpc_server.h            |    4 +-
 source3/rpc_server/srv_netlog_nt.c         |    1 +
 source3/rpc_server/srv_pipe_hnd.c          |  189 +------
 source3/rpc_server/srv_spoolss_util.c      |    1 +
 source3/smbd/lanman.c                      |   64 ++-
 source3/smbd/reply.c                       |    8 +-
 source3/winbindd/winbindd_samr.c           |    5 +-
 22 files changed, 2700 insertions(+), 788 deletions(-)
 create mode 100644 docs-xml/smbdotconf/misc/rpcserver.xml
 create mode 100644 source3/printing/printer_list.c
 create mode 100644 source3/printing/printer_list.h
 create mode 100644 source3/rpc_client/rpc_transport_tstream.c
 create mode 100644 source3/rpc_server/rpc_ncacn_np.c
 create mode 100644 source3/rpc_server/rpc_ncacn_np.h
 delete mode 100644 source3/rpc_server/rpc_ncacn_np_internal.c
 create mode 100644 source3/rpc_server/rpc_server.c


Changeset truncated at 500 lines:

diff --git a/docs-xml/smbdotconf/misc/rpcserver.xml 
b/docs-xml/smbdotconf/misc/rpcserver.xml
new file mode 100644
index 0000000..c69dc4a
--- /dev/null
+++ b/docs-xml/smbdotconf/misc/rpcserver.xml
@@ -0,0 +1,46 @@
+<samba:parameter name="rpc_server"
+                 context="G"
+                type="string"
+                advanced="1" print="1"
+                 xmlns:samba="http://www.samba.org/samba/DTD/samba-doc";>
+<description>
+       <para>
+       Defines what kind of rpc server to use for a named pipe.
+       The rpc_server prefix must be followed by the pipe name, and a value.
+       </para>
+
+       <para>
+       Three possible values are currently supported:
+               <command moreinfo="none">embedded</command>
+               <command moreinfo="none">daemon</command>
+               <command moreinfo="none">external</command>
+       </para>
+
+       <para>
+       The classic method is to run every pipe as an internal function
+       <emphasis>embedded</emphasis> in smbd.
+       </para>
+
+       <para>
+       An alternative method is to fork a <emphasis>daemon</emphasis>
+       early on at smbd startup time. this is supported only for selected
+       pipes.
+       </para>
+
+       <para>
+       Choosing the <emphasis>external</emphasis> option allows to run a
+       completely indipendent (3rd party) server capable of interfacing
+       with samba via the MS-RPC intrerface over named pipes.
+       </para>
+
+       <para>
+       Currently only the spoolss pipe can be configured in
+       <emphasis>daemon</emphasis> mode like this:
+       <programlisting>
+       rpc_server:spoolss = daemon
+       </programlisting>
+       </para>
+</description>
+
+<value type="default">none</value>
+</samba:parameter>
diff --git a/source3/Makefile.in b/source3/Makefile.in
index cde2d7d..8632745 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -599,6 +599,7 @@ LIBMSRPC_OBJ = $(SCHANNEL_OBJ) \
               librpc/rpc/rpc_common.o \
               rpc_client/rpc_transport_np.o \
               rpc_client/rpc_transport_sock.o \
+              rpc_client/rpc_transport_tstream.o \
               ../librpc/rpc/binding.o \
               ../librpc/rpc/dcerpc_util.o \
               ../librpc/rpc/binding_handle.o \
@@ -705,11 +706,13 @@ RPC_EVENTLOG_OBJ = rpc_server/srv_eventlog_nt.o \
 NPA_TSTREAM_OBJ = ../libcli/named_pipe_auth/npa_tstream.o \
                  librpc/gen_ndr/ndr_named_pipe_auth.o
 
-RPC_NCACN_NP_INTERNAL = rpc_server/srv_pipe_register.o 
rpc_server/rpc_ncacn_np_internal.o \
-                       rpc_server/rpc_handles.o
+RPC_NCACN_NP = rpc_server/srv_pipe_register.o rpc_server/rpc_ncacn_np.o \
+              rpc_server/rpc_handles.o
+
+RPC_SERVICE = rpc_server/rpc_server.o
 
 RPC_PIPE_OBJ = rpc_server/srv_pipe.o rpc_server/srv_pipe_hnd.o \
-              $(RPC_NCACN_NP_INTERNAL)
+              $(RPC_NCACN_NP) $(RPC_SERVICE)
 
 RPC_RPCECHO_OBJ = rpc_server/srv_echo_nt.o librpc/gen_ndr/srv_echo.o
 
@@ -906,7 +909,8 @@ SMBD_OBJ_BASE = $(PARAM_WITHOUT_REG_OBJ) $(SMBD_OBJ_SRV) 
$(LIBSMB_OBJ) \
 PRINTING_OBJ = printing/pcap.o printing/print_svid.o printing/print_aix.o \
                printing/print_cups.o printing/print_generic.o \
                printing/lpq_parse.o printing/load.o \
-               printing/print_iprint.o printing/print_standard.o
+               printing/print_iprint.o printing/print_standard.o \
+               printing/printer_list.o
 
 PRINTBASE_OBJ = printing/notify.o printing/printing_db.o
 PRINTBACKEND_OBJ = printing/printing.o \
@@ -1382,7 +1386,8 @@ WINBINDD_OBJ = \
                $(PROFILE_OBJ) $(SLCACHE_OBJ) $(SMBLDAP_OBJ) \
                $(LIBADS_OBJ) $(KRBCLIENT_OBJ) $(POPT_LIB_OBJ) \
                $(DCUTIL_OBJ) $(IDMAP_OBJ) $(NSS_INFO_OBJ) \
-               $(RPC_NCACN_NP_INTERNAL) $(RPC_SAMR_OBJ) $(RPC_LSARPC_OBJ) \
+               $(RPC_NCACN_NP) $(RPC_SAMR_OBJ) $(RPC_LSARPC_OBJ) \
+               $(NPA_TSTREAM_OBJ) \
                $(AFS_OBJ) $(AFS_SETTOKEN_OBJ) \
                $(LIBADS_SERVER_OBJ) \
                $(TDB_VALIDATE_OBJ) \
diff --git a/source3/include/proto.h b/source3/include/proto.h
index e1751e8..6fe8f64 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -3667,6 +3667,7 @@ int lp_min_receive_file_size(void);
 char* lp_perfcount_module(void);
 void lp_set_passdb_backend(const char *backend);
 void widelinks_warning(int snum);
+char *lp_ncalrpc_dir(void);
 
 /* The following definitions come from param/loadparm_server_role.c  */
 
@@ -4162,8 +4163,12 @@ NTSTATUS rpc_pipe_open_internal(TALLOC_CTX *mem_ctx,
                                struct client_address *client_id,
                                struct messaging_context *msg_ctx,
                                struct rpc_pipe_client **presult);
-NTSTATUS rpc_connect_spoolss_pipe(connection_struct *conn,
-                                 struct rpc_pipe_client **spoolss_pipe);
+NTSTATUS rpc_pipe_open_interface(TALLOC_CTX *mem_ctx,
+                                const struct ndr_syntax_id *syntax,
+                                struct auth_serversupplied_info *server_info,
+                                struct client_address *client_id,
+                                struct messaging_context *msg_ctx,
+                                struct rpc_pipe_client **cli_pipe);
 NTSTATUS cli_rpc_pipe_open_noauth(struct cli_state *cli,
                                  const struct ndr_syntax_id *interface,
                                  struct rpc_pipe_client **presult);
@@ -4282,6 +4287,13 @@ struct cli_state *rpc_pipe_smbd_smb_conn(struct 
rpc_pipe_client *p);
 NTSTATUS rpc_transport_sock_init(TALLOC_CTX *mem_ctx, int fd,
                                 struct rpc_cli_transport **presult);
 
+/* The following definitions come from rpc_client/rpc_transport_tstream.c  */
+NTSTATUS rpc_transport_tstream_init(TALLOC_CTX *mem_ctx,
+                               struct tstream_context *npipe,
+                               struct tevent_queue *read_queue,
+                               struct tevent_queue *write_queue,
+                                struct rpc_cli_transport **presult);
+
 /* The following definitions come from rpc_server/srv_eventlog_nt.c  */
 
 /* The following definitions come from rpc_server/rpc_handles.c  */
@@ -4344,6 +4356,7 @@ bool is_known_pipename(const char *cli_filename, struct 
ndr_syntax_id *syntax);
 struct pipes_struct *get_first_internal_pipe(void);
 struct pipes_struct *get_next_internal_pipe(struct pipes_struct *p);
 bool check_open_pipes(void);
+int close_internal_rpc_pipe_hnd(struct pipes_struct *p);
 
 bool fsp_is_np(struct files_struct *fsp);
 struct tsocket_address;
@@ -4365,6 +4378,8 @@ struct tevent_req *np_read_send(TALLOC_CTX *mem_ctx, 
struct event_context *ev,
 NTSTATUS np_read_recv(struct tevent_req *req, ssize_t *nread,
                      bool *is_data_outstanding);
 
+ssize_t process_incoming_data(struct pipes_struct *p, char *data, size_t n);
+
 /* The following definitions come from rpc_server/srv_spoolss_nt.c  */
 void srv_spoolss_cleanup(void);
 
diff --git a/source3/librpc/rpc/dcerpc.h b/source3/librpc/rpc/dcerpc.h
index 56d6d32..3183645 100644
--- a/source3/librpc/rpc/dcerpc.h
+++ b/source3/librpc/rpc/dcerpc.h
@@ -168,6 +168,10 @@ struct ndr_pull;
 struct tevent_context;
 struct tstream_context;
 
+/* from ../librpc/rpc/dcerpc_util.c */
+void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v);
+uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob);
+void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v);
 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
                                                 struct tevent_context *ev,
                                                 struct tstream_context 
*stream);
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index bb6e132..4ae699a 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -376,6 +376,7 @@ struct global {
        int ismb2_max_read;
        int ismb2_max_write;
        int ismb2_max_trans;
+       char *ncalrpc_dir;
 };
 
 static struct global Globals;
@@ -4722,6 +4723,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_ADVANCED,
        },
+       {
+               .label          = "ncalrpc dir",
+               .type           = P_STRING,
+               .p_class        = P_GLOBAL,
+               .ptr            = &Globals.ncalrpc_dir,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_ADVANCED,
+       },
 
        {NULL,  P_BOOL,  P_NONE,  NULL,  NULL,  NULL,  0}
 };
@@ -5365,6 +5375,8 @@ static void init_globals(bool reinit_globals)
        Globals.ismb2_max_write = 1024*1024;
        Globals.ismb2_max_trans = 1024*1024;
 
+       string_set(&Globals.ncalrpc_dir, get_dyn_NCALRPCDIR());
+
        /* Now put back the settings that were set with lp_set_cmdline() */
        apply_lp_set_cmdline();
 }
@@ -5895,6 +5907,8 @@ FN_GLOBAL_INTEGER(lp_client_signing, 
&Globals.client_signing)
 FN_GLOBAL_INTEGER(lp_server_signing, &Globals.server_signing)
 FN_GLOBAL_INTEGER(lp_client_ldap_sasl_wrapping, 
&Globals.client_ldap_sasl_wrapping)
 
+FN_GLOBAL_STRING(lp_ncalrpc_dir, &Globals.ncalrpc_dir)
+
 /* local prototypes */
 
 static int map_parameter_canonical(const char *pszParmName, bool *inverse);
diff --git a/source3/printing/nt_printing_migrate.c 
b/source3/printing/nt_printing_migrate.c
index 2060b91..c646676 100644
--- a/source3/printing/nt_printing_migrate.c
+++ b/source3/printing/nt_printing_migrate.c
@@ -25,6 +25,7 @@
 #include "librpc/gen_ndr/cli_spoolss.h"
 #include "rpc_client/cli_spoolss.h"
 #include "librpc/gen_ndr/ndr_security.h"
+#include "rpc_server/rpc_ncacn_np.h"
 
 #define FORMS_PREFIX "FORMS/"
 #define DRIVERS_PREFIX "DRIVERS/"
diff --git a/source3/printing/pcap.c b/source3/printing/pcap.c
index d9c2941..3bc8e9e 100644
--- a/source3/printing/pcap.c
+++ b/source3/printing/pcap.c
@@ -38,6 +38,7 @@
 
 #include "includes.h"
 #include "printing/pcap.h"
+#include "printer_list.h"
 
 struct pcap_cache {
        char *name;
@@ -45,9 +46,6 @@ struct pcap_cache {
        struct pcap_cache *next;
 };
 
-/* The systemwide printcap cache. */
-static struct pcap_cache *pcap_cache = NULL;
-
 bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, 
const char *comment)
 {
        struct pcap_cache *p;
@@ -83,19 +81,26 @@ void pcap_cache_destroy_specific(struct pcap_cache 
**pp_cache)
 
 bool pcap_cache_add(const char *name, const char *comment)
 {
-       return pcap_cache_add_specific(&pcap_cache, name, comment);
+       NTSTATUS status;
+       time_t t = time(NULL);
+
+       status = printer_list_set_printer(talloc_tos(), name, comment, t);
+       return NT_STATUS_IS_OK(status);
 }
 
 bool pcap_cache_loaded(void)
 {
-       return (pcap_cache != NULL);
+       NTSTATUS status;
+       time_t last;
+
+       status = printer_list_get_last_refresh(&last);
+       return NT_STATUS_IS_OK(status);
 }
 
 void pcap_cache_replace(const struct pcap_cache *pcache)
 {
        const struct pcap_cache *p;
 
-       pcap_cache_destroy_specific(&pcap_cache);
        for (p = pcache; p; p = p->next) {
                pcap_cache_add(p->name, p->comment);
        }
@@ -106,7 +111,7 @@ void pcap_cache_reload(struct tevent_context *ev,
 {
        const char *pcap_name = lp_printcapname();
        bool pcap_reloaded = False;
-       struct pcap_cache *tmp_cache = NULL;
+       NTSTATUS status;
 
        DEBUG(3, ("reloading printcap cache\n"));
 
@@ -116,8 +121,17 @@ void pcap_cache_reload(struct tevent_context *ev,
                return;
        }
 
-       tmp_cache = pcap_cache;
-       pcap_cache = NULL;
+       if (!printer_list_need_refresh()) {
+               /* has been just refeshed, skip */
+               DEBUG(5, ("Refresh just happend, skipping.\n"));
+               return;
+       }
+
+       status = printer_list_mark_reload();
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("Failed to mark printer list for reload!\n"));
+               return;
+       }
 
 #ifdef HAVE_CUPS
        if (strequal(pcap_name, "cups")) {
@@ -152,11 +166,14 @@ void pcap_cache_reload(struct tevent_context *ev,
 done:
        DEBUG(3, ("reload status: %s\n", (pcap_reloaded) ? "ok" : "error"));
 
-       if (pcap_reloaded)
-               pcap_cache_destroy_specific(&tmp_cache);
-       else {
-               pcap_cache_destroy_specific(&pcap_cache);
-               pcap_cache = tmp_cache;
+       if (pcap_reloaded) {
+               /* cleanup old entries only if the operation was successful,
+                * otherwise keep around the old entries until we can
+                * successfuly reaload */
+               status = printer_list_clean_old();
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("Failed to cleanup printer list!\n"));
+               }
        }
 
        return;
@@ -165,13 +182,10 @@ done:
 
 bool pcap_printername_ok(const char *printername)
 {
-       struct pcap_cache *p;
-
-       for (p = pcap_cache; p != NULL; p = p->next)
-               if (strequal(p->name, printername))
-                       return True;
+       NTSTATUS status;
 
-       return False;
+       status = printer_list_get_printer(talloc_tos(), printername, NULL, 0);
+       return NT_STATUS_IS_OK(status);
 }
 
 /***************************************************************************
@@ -192,5 +206,11 @@ void pcap_printer_fn_specific(const struct pcap_cache *pc,
 
 void pcap_printer_fn(void (*fn)(const char *, const char *, void *), void 
*pdata)
 {
-       pcap_printer_fn_specific(pcap_cache, fn, pdata);
+       NTSTATUS status;
+
+       status = printer_list_run_fn(fn, pdata);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(3, ("Failed to run fn for all printers!\n"));
+       }
+       return;
 }
diff --git a/source3/printing/printer_list.c b/source3/printing/printer_list.c
new file mode 100644
index 0000000..6392755
--- /dev/null
+++ b/source3/printing/printer_list.c
@@ -0,0 +1,415 @@
+/*
+   Unix SMB/CIFS implementation.
+   Share Database of available printers.
+   Copyright (C) Simo Sorce 2010
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "dbwrap.h"
+#include "printer_list.h"
+
+#define PL_DB_NAME() lock_path("printer_list.tdb")
+#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_TSTAMP_FORMAT "dd"
+
+static struct db_context *get_printer_list_db(void)
+{
+       static struct db_context *db;
+
+       if (db != NULL) {
+               return db;
+       }
+       db = db_open(talloc_autofree_context(), PL_DB_NAME(), 0,
+                    TDB_DEFAULT|TDB_CLEAR_IF_FIRST,
+                    O_RDWR|O_CREAT, 0644);
+       return db;
+}
+
+bool printer_list_parent_init(void)
+{
+       struct db_context *db;
+
+       /*
+        * Open the tdb in the parent process (smbd) so that our
+        * CLEAR_IF_FIRST optimization in tdb_reopen_all can properly
+        * work.
+        */
+
+       db = get_printer_list_db();
+       if (db == NULL) {
+               DEBUG(1, ("could not open Printer List Database: %s\n",
+                         strerror(errno)));
+               return false;
+       }
+       return true;
+}
+
+NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx,
+                                 const char *name,
+                                 const char **comment,
+                                 time_t *last_refresh)
+{
+       struct db_context *db;
+       char *key;
+       TDB_DATA data;
+       uint32_t time_h, time_l;
+       char *nstr = NULL;
+       char *cstr = NULL;
+       NTSTATUS status;
+       int ret;
+
+       db = get_printer_list_db();
+       if (db == NULL) {
+               return NT_STATUS_INTERNAL_DB_CORRUPTION;
+       }
+
+       key = talloc_asprintf(mem_ctx, PL_KEY_FORMAT, name);
+       if (!key) {
+               DEBUG(0, ("Failed to allocate key name!\n"));
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       data = dbwrap_fetch_bystring_upper(db, key, key);
+       if (data.dptr == NULL) {
+               DEBUG(1, ("Failed to fetch record!\n"));
+               status = NT_STATUS_NOT_FOUND;
+               goto done;
+       }
+
+       ret = tdb_unpack(data.dptr, data.dsize,
+                        PL_DATA_FORMAT,
+                        &time_h, &time_l, &nstr, &cstr);
+       if (ret == -1) {
+               DEBUG(1, ("Failed to un pack printer data"));
+               status = NT_STATUS_INTERNAL_DB_CORRUPTION;
+               goto done;
+       }
+
+       if (last_refresh) {
+               *last_refresh = (time_t)(((uint64_t)time_h << 32) + time_l);
+       }
+
+       if (comment) {
+               *comment = talloc_strdup(mem_ctx, cstr);
+               if (!*comment) {
+                       DEBUG(1, ("Failed to strdup comment!\n"));
+                       status = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
+       }
+
+       status = NT_STATUS_OK;
+
+done:
+       SAFE_FREE(nstr);
+       SAFE_FREE(cstr);
+       TALLOC_FREE(key);
+       return status;
+}
+
+NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx,
+                                 const char *name,
+                                 const char *comment,
+                                 time_t last_refresh)
+{
+       struct db_context *db;


-- 
Samba Shared Repository

Reply via email to