The branch, master has been updated
       via  9ccef4e s3: Remove unused mem_ctx arg from set_getdc_request
       via  b2ba2b9 s3: Factor out prep_getdc_request
       via  e0abc5c s3: cli_send_mailslot -> cli_prep_mailslot
      from  bb6da9f s3: Fix some nonempty blank lines

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


- Log -----------------------------------------------------------------
commit 9ccef4e62b72a42b7281e6ad6bc1127ed9504bbb
Author: Volker Lendecke <[email protected]>
Date:   Sat Jan 1 16:21:12 2011 +0100

    s3: Remove unused mem_ctx arg from set_getdc_request
    
    Autobuild-User: Volker Lendecke <[email protected]>
    Autobuild-Date: Sat Jan  1 23:00:24 CET 2011 on sn-devel-104

commit b2ba2b956e2b6e8552c74afe65902aae70203843
Author: Volker Lendecke <[email protected]>
Date:   Sat Jan 1 16:18:48 2011 +0100

    s3: Factor out prep_getdc_request

commit e0abc5c15f8e3b226366d32925d1c50f42a9b225
Author: Volker Lendecke <[email protected]>
Date:   Sat Jan 1 15:29:11 2011 +0100

    s3: cli_send_mailslot -> cli_prep_mailslot

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

Summary of changes:
 source3/libsmb/clidgram.c      |  117 ++++++++++++++++++++++-----------------
 source3/libsmb/clidgram.h      |    3 +-
 source3/libsmb/dsgetdcname.c   |    2 +-
 source3/winbindd/winbindd_cm.c |    2 +-
 4 files changed, 69 insertions(+), 55 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/libsmb/clidgram.c b/source3/libsmb/clidgram.c
index df4d7f4..05a0edc 100644
--- a/source3/libsmb/clidgram.c
+++ b/source3/libsmb/clidgram.c
@@ -27,33 +27,21 @@
  * cli_send_mailslot, send a mailslot for client code ...
  */
 
-static bool cli_send_mailslot(struct messaging_context *msg_ctx,
-                      bool unique, const char *mailslot,
+static bool cli_prep_mailslot(bool unique, const char *mailslot,
                       uint16 priority,
                       char *buf, int len,
                       const char *srcname, int src_type,
                       const char *dstname, int dest_type,
                       const struct sockaddr_storage *dest_ss,
-                      int dgm_id)
+                      int dgm_id,
+                      struct packet_struct *p)
 {
-       struct packet_struct p;
-       struct dgram_packet *dgram = &p.packet.dgram;
+       struct dgram_packet *dgram = &p->packet.dgram;
        char *ptr, *p2;
        char tmp[4];
-       pid_t nmbd_pid;
        char addr[INET6_ADDRSTRLEN];
 
-       if ((nmbd_pid = pidfile_pid("nmbd")) == 0) {
-               DEBUG(3, ("No nmbd found\n"));
-               return False;
-       }
-
-       if (dest_ss->ss_family != AF_INET) {
-               DEBUG(3, ("cli_send_mailslot: can't send to IPv6 address.\n"));
-               return false;
-       }
-
-       memset((char *)&p, '\0', sizeof(p));
+       ZERO_STRUCTP(p);
 
        /*
         * Next, build the DGRAM ...
@@ -106,9 +94,9 @@ static bool cli_send_mailslot(struct messaging_context 
*msg_ctx,
 
        dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */
 
-       p.packet_type = DGRAM_PACKET;
-       p.ip = ((const struct sockaddr_in *)dest_ss)->sin_addr;
-       p.timestamp = time(NULL);
+       p->packet_type = DGRAM_PACKET;
+       p->ip = ((const struct sockaddr_in *)dest_ss)->sin_addr;
+       p->timestamp = time(NULL);
 
        DEBUG(4,("send_mailslot: Sending to mailslot %s from %s ",
                 mailslot, nmb_namestr(&dgram->source_name)));
@@ -116,10 +104,7 @@ static bool cli_send_mailslot(struct messaging_context 
*msg_ctx,
 
        DEBUGADD(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), addr));
 
-       return NT_STATUS_IS_OK(messaging_send_buf(msg_ctx,
-                                                 pid_to_procid(nmbd_pid),
-                                                 MSG_SEND_PACKET,
-                                                 (uint8 *)&p, sizeof(p)));
+       return true;
 }
 
 static const char *mailslot_name(TALLOC_CTX *mem_ctx, struct in_addr dc_ip)
@@ -128,43 +113,45 @@ static const char *mailslot_name(TALLOC_CTX *mem_ctx, 
struct in_addr dc_ip)
                               NBT_MAILSLOT_GETDC, dc_ip.s_addr);
 }
 
-bool send_getdc_request(TALLOC_CTX *mem_ctx,
-                       struct messaging_context *msg_ctx,
-                       const struct sockaddr_storage *dc_ss,
-                       const char *domain_name,
-                       const struct dom_sid *sid,
-                       uint32_t nt_version,
-                       int dgm_id)
+static bool prep_getdc_request(const struct sockaddr_storage *dc_ss,
+                              const char *domain_name,
+                              const struct dom_sid *sid,
+                              uint32_t nt_version,
+                              int dgm_id,
+                              struct packet_struct *p)
 {
+       TALLOC_CTX *frame = talloc_stackframe();
        struct in_addr dc_ip;
-       const char *my_acct_name = NULL;
-       const char *my_mailslot = NULL;
+       const char *my_acct_name;
+       const char *my_mailslot;
        struct nbt_netlogon_packet packet;
        struct NETLOGON_SAM_LOGON_REQUEST *s;
        enum ndr_err_code ndr_err;
-       DATA_BLOB blob;
+       DATA_BLOB blob = data_blob_null;
        struct dom_sid my_sid;
-
-       ZERO_STRUCT(packet);
-       ZERO_STRUCT(my_sid);
+       bool ret = false;
 
        if (dc_ss->ss_family != AF_INET) {
-               return false;
+               goto fail;
        }
 
-       if (sid) {
+       ZERO_STRUCT(packet);
+       ZERO_STRUCT(my_sid);
+
+       if (sid != NULL) {
                my_sid = *sid;
        }
 
        dc_ip = ((struct sockaddr_in *)dc_ss)->sin_addr;
-       my_mailslot = mailslot_name(mem_ctx, dc_ip);
-       if (!my_mailslot) {
-               return false;
+
+       my_mailslot = mailslot_name(talloc_tos(), dc_ip);
+       if (my_mailslot == NULL) {
+               goto fail;
        }
 
-       my_acct_name = talloc_asprintf(mem_ctx, "%s$", global_myname());
-       if (!my_acct_name) {
-               return false;
+       my_acct_name = talloc_asprintf(talloc_tos(), "%s$", global_myname());
+       if (my_acct_name == NULL) {
+               goto fail;
        }
 
        packet.command  = LOGON_SAM_LOGON_REQUEST;
@@ -184,17 +171,45 @@ bool send_getdc_request(TALLOC_CTX *mem_ctx,
                NDR_PRINT_DEBUG(nbt_netlogon_packet, &packet);
        }
 
-       ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &packet,
+       ndr_err = ndr_push_struct_blob(&blob, talloc_tos(), &packet,
                       (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               goto fail;
+       }
+
+       ret = cli_prep_mailslot(false, NBT_MAILSLOT_NTLOGON, 0,
+                               (char *)blob.data, blob.length,
+                               global_myname(), 0, domain_name, 0x1c,
+                               dc_ss, dgm_id, p);
+fail:
+       TALLOC_FREE(frame);
+       return ret;
+}
+
+bool send_getdc_request(struct messaging_context *msg_ctx,
+                       const struct sockaddr_storage *dc_ss,
+                       const char *domain_name,
+                       const struct dom_sid *sid,
+                       uint32_t nt_version,
+                       int dgm_id)
+{
+       struct packet_struct p;
+       pid_t nmbd_pid;
+
+       if ((nmbd_pid = pidfile_pid("nmbd")) == 0) {
+               DEBUG(3, ("No nmbd found\n"));
+               return False;
+       }
+
+       if (!prep_getdc_request(dc_ss, domain_name, sid, nt_version,
+                               dgm_id, &p)) {
                return false;
        }
 
-       return cli_send_mailslot(msg_ctx,
-                                false, NBT_MAILSLOT_NTLOGON, 0,
-                                (char *)blob.data, blob.length,
-                                global_myname(), 0, domain_name, 0x1c,
-                                dc_ss, dgm_id);
+       return NT_STATUS_IS_OK(messaging_send_buf(msg_ctx,
+                                                 pid_to_procid(nmbd_pid),
+                                                 MSG_SEND_PACKET,
+                                                 (uint8 *)&p, sizeof(p)));
 }
 
 bool receive_getdc_response(TALLOC_CTX *mem_ctx,
diff --git a/source3/libsmb/clidgram.h b/source3/libsmb/clidgram.h
index 7c650a0..af924f4 100644
--- a/source3/libsmb/clidgram.h
+++ b/source3/libsmb/clidgram.h
@@ -2,8 +2,7 @@
 
 /* The following definitions come from libsmb/clidgram.c  */
 
-bool send_getdc_request(TALLOC_CTX *mem_ctx,
-                       struct messaging_context *msg_ctx,
+bool send_getdc_request(struct messaging_context *msg_ctx,
                        const struct sockaddr_storage *dc_ss,
                        const char *domain_name,
                        const struct dom_sid *sid,
diff --git a/source3/libsmb/dsgetdcname.c b/source3/libsmb/dsgetdcname.c
index b1acee8..63621ed 100644
--- a/source3/libsmb/dsgetdcname.c
+++ b/source3/libsmb/dsgetdcname.c
@@ -950,7 +950,7 @@ static NTSTATUS process_dc_netbios(TALLOC_CTX *mem_ctx,
                        return NT_STATUS_UNSUCCESSFUL;
                }
 
-               if (send_getdc_request(mem_ctx, msg_ctx,
+               if (send_getdc_request(msg_ctx,
                                       &dclist[i].ss, domain_name,
                                       NULL, nt_version, dgm_id))
                {
diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c
index 5f42120..d5642a3 100644
--- a/source3/winbindd/winbindd_cm.c
+++ b/source3/winbindd/winbindd_cm.c
@@ -1177,7 +1177,7 @@ static bool dcip_to_name(TALLOC_CTX *mem_ctx,
        generate_random_buffer((uint8_t *)&val, 2);
        dgm_id = val;
 
-       if (send_getdc_request(mem_ctx, winbind_messaging_context(),
+       if (send_getdc_request(winbind_messaging_context(),
                               pss, domain->name, &domain->sid,
                               nt_version, dgm_id)) {
                const char *dc_name = NULL;


-- 
Samba Shared Repository

Reply via email to