~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source3/libsmb/dsgetdcname.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
*/
22
22
 
23
23
#include "includes.h"
 
24
#include "libads/sitename_cache.h"
 
25
#include "../librpc/gen_ndr/ndr_netlogon.h"
 
26
#include "libads/cldap.h"
 
27
#include "libads/dns.h"
 
28
#include "libsmb/clidgram.h"
24
29
 
25
 
#define DSGETDCNAME_FMT "DSGETDCNAME/DOMAIN/%s"
26
30
/* 15 minutes */
27
31
#define DSGETDCNAME_CACHE_TTL   60*15
28
32
 
122
126
                return NULL;
123
127
        }
124
128
 
125
 
        return talloc_asprintf_strupper_m(mem_ctx, DSGETDCNAME_FMT, domain);
 
129
        return talloc_asprintf_strupper_m(mem_ctx, "DSGETDCNAME/DOMAIN/%s",
 
130
                                          domain);
126
131
}
127
132
 
128
133
/****************************************************************
189
194
        r->sockaddr.sockaddr_family = 2; /* AF_INET */
190
195
        r->sockaddr.pdc_ip = talloc_strdup(mem_ctx, addr);
191
196
 
192
 
        ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, r,
 
197
        ndr_err = ndr_push_struct_blob(&blob, mem_ctx, r,
193
198
                       (ndr_push_flags_fn_t)ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX);
194
199
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
195
200
                return ndr_map_error2ntstatus(ndr_err);
196
201
        }
197
202
 
198
 
        if (r->domain) {
199
 
                status = dsgetdcname_cache_store(mem_ctx, r->domain, &blob);
 
203
        if (r->domain_name) {
 
204
                status = dsgetdcname_cache_store(mem_ctx, r->domain_name, &blob);
200
205
                if (!NT_STATUS_IS_OK(status)) {
201
206
                        goto done;
202
207
                }
203
208
                if (r->client_site) {
204
 
                        sitename_store(r->domain, r->client_site);
 
209
                        sitename_store(r->domain_name, r->client_site);
205
210
                }
206
211
        }
207
212
        if (r->dns_domain) {
340
345
                return NT_STATUS_NO_MEMORY;
341
346
        }
342
347
 
343
 
        ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, NULL, &r,
 
348
        ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r,
344
349
                      (ndr_pull_flags_fn_t)ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX);
345
350
 
346
351
        data_blob_free(&blob);
496
501
 
497
502
        dclist = TALLOC_ZERO_ARRAY(mem_ctx, struct ip_service_name, count);
498
503
        if (!dclist) {
 
504
                SAFE_FREE(iplist);
499
505
                return NT_STATUS_NO_MEMORY;
500
506
        }
501
507
 
511
517
                r->port = iplist[i].port;
512
518
                r->hostname = talloc_strdup(mem_ctx, addr);
513
519
                if (!r->hostname) {
 
520
                        SAFE_FREE(iplist);
514
521
                        return NT_STATUS_NO_MEMORY;
515
522
                }
516
523
 
518
525
 
519
526
        *returned_dclist = dclist;
520
527
        *returned_count = count;
 
528
        SAFE_FREE(iplist);
521
529
 
522
530
        return NT_STATUS_OK;
523
531
}
621
629
                 * back to netbios lookups is that our DNS server doesn't know
622
630
                 * anything about the DC's   -- jerry */
623
631
 
624
 
                if (!is_zero_addr((struct sockaddr *)(void *)&r->ss)) {
 
632
                if (!is_zero_addr(&r->ss)) {
625
633
                        count++;
626
634
                        continue;
627
635
                }
686
694
        if (forest_name && *forest_name) {
687
695
                info->forest_name = talloc_strdup(mem_ctx, forest_name);
688
696
                NT_STATUS_HAVE_NO_MEMORY(info->forest_name);
689
 
                flags |= DS_DNS_FOREST;
 
697
                flags |= DS_DNS_FOREST_ROOT;
690
698
        }
691
699
 
692
700
        info->dc_flags = flags;
782
790
 
783
791
        map_dc_and_domain_names(flags,
784
792
                                r->pdc_name,
785
 
                                r->domain,
 
793
                                r->domain_name,
786
794
                                r->pdc_dns_name,
787
795
                                r->dns_domain,
788
796
                                &dc_flags,
892
900
/****************************************************************
893
901
****************************************************************/
894
902
 
895
 
static struct event_context *ev_context(void)
896
 
{
897
 
        static struct event_context *ctx;
898
 
 
899
 
        if (!ctx && !(ctx = event_context_init(NULL))) {
900
 
                smb_panic("Could not init event context");
901
 
        }
902
 
        return ctx;
903
 
}
904
 
 
905
 
/****************************************************************
906
 
****************************************************************/
907
 
 
908
 
static struct messaging_context *msg_context(TALLOC_CTX *mem_ctx)
909
 
{
910
 
        static struct messaging_context *ctx;
911
 
 
912
 
        if (!ctx && !(ctx = messaging_init(mem_ctx, server_id_self(),
913
 
                                           ev_context()))) {
914
 
                smb_panic("Could not init messaging context");
915
 
        }
916
 
        return ctx;
917
 
}
918
 
 
919
903
/****************************************************************
920
904
****************************************************************/
921
905
 
940
924
                              NETLOGON_NT_VERSION_5 |
941
925
                              NETLOGON_NT_VERSION_5EX_WITH_IP;
942
926
 
943
 
        if (!msg_ctx) {
944
 
                msg_ctx = msg_context(mem_ctx);
 
927
        if (msg_ctx == NULL) {
 
928
                return NT_STATUS_INVALID_PARAMETER;
945
929
        }
946
930
 
947
931
        if (flags & DS_PDC_REQUIRED) {
953
937
        DEBUG(10,("process_dc_netbios\n"));
954
938
 
955
939
        for (i=0; i<num_dcs; i++) {
 
940
                uint16_t val;
 
941
                int dgm_id;
 
942
 
 
943
                generate_random_buffer((uint8_t *)&val, 2);
 
944
                dgm_id = val;
956
945
 
957
946
                ip_list.ss = dclist[i].ss;
958
947
                ip_list.port = 0;
961
950
                        return NT_STATUS_UNSUCCESSFUL;
962
951
                }
963
952
 
964
 
                if (send_getdc_request(mem_ctx, msg_ctx,
965
 
                                       &dclist[i].ss, domain_name,
966
 
                                       NULL, nt_version))
967
 
                {
968
 
                        int k;
969
 
                        smb_msleep(300);
970
 
                        for (k=0; k<5; k++) {
971
 
                                if (receive_getdc_response(mem_ctx,
972
 
                                                           &dclist[i].ss,
973
 
                                                           domain_name,
974
 
                                                           &nt_version,
975
 
                                                           &dc_name,
976
 
                                                           &r)) {
977
 
                                        store_cache = true;
978
 
                                        namecache_store(dc_name, NBT_NAME_SERVER, 1, &ip_list);
979
 
                                        goto make_reply;
980
 
                                }
981
 
                                smb_msleep(1500);
982
 
                        }
 
953
                status = nbt_getdc(msg_ctx, &dclist[i].ss, domain_name,
 
954
                                   NULL, nt_version,
 
955
                                   mem_ctx, &nt_version, &dc_name, &r);
 
956
                if (NT_STATUS_IS_OK(status)) {
 
957
                        store_cache = true;
 
958
                        namecache_store(dc_name, NBT_NAME_SERVER, 1, &ip_list);
 
959
                        goto make_reply;
983
960
                }
984
961
 
985
962
                if (name_status_find(domain_name,
998
975
                        nt_version = NETLOGON_NT_VERSION_1;
999
976
 
1000
977
                        logon1.nt_version = nt_version;
1001
 
                        logon1.server = tmp_dc_name;
1002
 
                        logon1.domain = talloc_strdup_upper(mem_ctx, domain_name);
1003
 
                        NT_STATUS_HAVE_NO_MEMORY(logon1.domain);
 
978
                        logon1.pdc_name = tmp_dc_name;
 
979
                        logon1.domain_name = talloc_strdup_upper(mem_ctx, domain_name);
 
980
                        NT_STATUS_HAVE_NO_MEMORY(logon1.domain_name);
1004
981
 
1005
982
                        r->data.nt4 = logon1;
1006
983
                        r->ntver = nt_version;