forked from samba-team/samba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwinbindd_dual_srv.c
1901 lines (1639 loc) · 50.9 KB
/
winbindd_dual_srv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Unix SMB/CIFS implementation.
In-Child server implementation of the routines defined in wbint.idl
Copyright (C) Volker Lendecke 2009
Copyright (C) Guenther Deschner 2009
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 "winbindd/winbindd.h"
#include "winbindd/winbindd_proto.h"
#include "rpc_client/cli_pipe.h"
#include "ntdomain.h"
#include "librpc/gen_ndr/srv_winbind.h"
#include "../librpc/gen_ndr/ndr_netlogon_c.h"
#include "../librpc/gen_ndr/ndr_lsa_c.h"
#include "idmap.h"
#include "../libcli/security/security.h"
#include "../libcli/auth/netlogon_creds_cli.h"
#include "passdb.h"
#include "../source4/dsdb/samdb/samdb.h"
#include "rpc_client/cli_netlogon.h"
#include "rpc_client/util_netlogon.h"
#include "libsmb/dsgetdcname.h"
void _wbint_Ping(struct pipes_struct *p, struct wbint_Ping *r)
{
*r->out.out_data = r->in.in_data;
}
bool reset_cm_connection_on_error(struct winbindd_domain *domain,
struct dcerpc_binding_handle *b,
NTSTATUS status)
{
if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
NT_STATUS_EQUAL(status, NT_STATUS_RPC_SEC_PKG_ERROR) ||
NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_ACCESS_DENIED)) {
invalidate_cm_connection(domain);
domain->conn.netlogon_force_reauth = true;
return true;
}
if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT) ||
NT_STATUS_EQUAL(status, NT_STATUS_IO_DEVICE_ERROR))
{
invalidate_cm_connection(domain);
/* We invalidated the connection. */
return true;
}
if (b != NULL && !dcerpc_binding_handle_is_connected(b)) {
invalidate_cm_connection(domain);
return true;
}
return false;
}
NTSTATUS _wbint_LookupSid(struct pipes_struct *p, struct wbint_LookupSid *r)
{
struct winbindd_domain *domain = wb_child_domain();
char *dom_name;
char *name;
enum lsa_SidType type;
NTSTATUS status;
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
status = wb_cache_sid_to_name(domain, p->mem_ctx, r->in.sid,
&dom_name, &name, &type);
reset_cm_connection_on_error(domain, NULL, status);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
*r->out.domain = dom_name;
*r->out.name = name;
*r->out.type = type;
return NT_STATUS_OK;
}
NTSTATUS _wbint_LookupSids(struct pipes_struct *p, struct wbint_LookupSids *r)
{
struct winbindd_domain *domain = wb_child_domain();
struct lsa_RefDomainList *domains = r->out.domains;
NTSTATUS status;
bool retry = false;
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
/*
* This breaks the winbindd_domain->methods abstraction: This
* is only called for remote domains, and both winbindd_msrpc
* and winbindd_ad call into lsa_lookupsids anyway. Caching is
* done at the wbint RPC layer.
*/
again:
status = rpc_lookup_sids(p->mem_ctx, domain, r->in.sids,
&domains, &r->out.names);
if (domains != NULL) {
r->out.domains = domains;
}
if (!retry && reset_cm_connection_on_error(domain, NULL, status)) {
retry = true;
goto again;
}
return status;
}
NTSTATUS _wbint_LookupName(struct pipes_struct *p, struct wbint_LookupName *r)
{
struct winbindd_domain *domain = wb_child_domain();
NTSTATUS status;
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
status = wb_cache_name_to_sid(domain, p->mem_ctx, r->in.domain,
r->in.name, r->in.flags,
r->out.sid, r->out.type);
reset_cm_connection_on_error(domain, NULL, status);
return status;
}
NTSTATUS _wbint_Sids2UnixIDs(struct pipes_struct *p,
struct wbint_Sids2UnixIDs *r)
{
uint32_t i;
struct lsa_DomainInfo *d;
struct wbint_TransID *ids;
uint32_t num_ids;
struct id_map **id_map_ptrs = NULL;
struct idmap_domain *dom;
NTSTATUS status = NT_STATUS_NO_MEMORY;
if (r->in.domains->count != 1) {
return NT_STATUS_INVALID_PARAMETER;
}
d = &r->in.domains->domains[0];
ids = r->in.ids->ids;
num_ids = r->in.ids->num_ids;
dom = idmap_find_domain_with_sid(d->name.string, d->sid);
if (dom == NULL) {
struct dom_sid_buf buf;
DEBUG(10, ("idmap domain %s:%s not found\n",
d->name.string,
dom_sid_str_buf(d->sid, &buf)));
for (i=0; i<num_ids; i++) {
ids[i].xid = (struct unixid) {
.id = UINT32_MAX,
.type = ID_TYPE_NOT_SPECIFIED
};
}
return NT_STATUS_OK;
}
id_map_ptrs = id_map_ptrs_init(talloc_tos(), num_ids);
if (id_map_ptrs == NULL) {
goto nomem;
}
/*
* Convert the input data into a list of id_map structs
* suitable for handing in to the idmap sids_to_unixids
* method.
*/
for (i=0; i<num_ids; i++) {
struct id_map *m = id_map_ptrs[i];
sid_compose(m->sid, d->sid, ids[i].rid);
m->status = ID_UNKNOWN;
m->xid = (struct unixid) { .type = ids[i].type };
}
status = dom->methods->sids_to_unixids(dom, id_map_ptrs);
if (NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
/*
* This is okay. We need to transfer the mapped ones
* up to our caller. The individual mappings carry the
* information whether they are mapped or not.
*/
status = NT_STATUS_OK;
}
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("sids_to_unixids returned %s\n",
nt_errstr(status)));
goto done;
}
/*
* Extract the results for handing them back to the caller.
*/
for (i=0; i<num_ids; i++) {
struct id_map *m = id_map_ptrs[i];
if (!idmap_unix_id_is_in_range(m->xid.id, dom)) {
DBG_DEBUG("id %"PRIu32" is out of range "
"%"PRIu32"-%"PRIu32" for domain %s\n",
m->xid.id, dom->low_id, dom->high_id,
dom->name);
m->status = ID_UNMAPPED;
}
if (m->status == ID_MAPPED) {
ids[i].xid = m->xid;
} else {
ids[i].xid.id = UINT32_MAX;
ids[i].xid.type = ID_TYPE_NOT_SPECIFIED;
}
}
goto done;
nomem:
status = NT_STATUS_NO_MEMORY;
done:
TALLOC_FREE(id_map_ptrs);
return status;
}
NTSTATUS _wbint_UnixIDs2Sids(struct pipes_struct *p,
struct wbint_UnixIDs2Sids *r)
{
struct id_map **maps;
NTSTATUS status;
uint32_t i;
maps = id_map_ptrs_init(talloc_tos(), r->in.num_ids);
if (maps == NULL) {
return NT_STATUS_NO_MEMORY;
}
for (i=0; i<r->in.num_ids; i++) {
maps[i]->status = ID_UNKNOWN;
maps[i]->xid = r->in.xids[i];
}
status = idmap_backend_unixids_to_sids(maps, r->in.domain_name,
r->in.domain_sid);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(maps);
return status;
}
for (i=0; i<r->in.num_ids; i++) {
r->out.xids[i] = maps[i]->xid;
sid_copy(&r->out.sids[i], maps[i]->sid);
}
TALLOC_FREE(maps);
return NT_STATUS_OK;
}
NTSTATUS _wbint_AllocateUid(struct pipes_struct *p, struct wbint_AllocateUid *r)
{
struct unixid xid;
NTSTATUS status;
status = idmap_allocate_uid(&xid);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
*r->out.uid = xid.id;
return NT_STATUS_OK;
}
NTSTATUS _wbint_AllocateGid(struct pipes_struct *p, struct wbint_AllocateGid *r)
{
struct unixid xid;
NTSTATUS status;
status = idmap_allocate_gid(&xid);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
*r->out.gid = xid.id;
return NT_STATUS_OK;
}
NTSTATUS _wbint_GetNssInfo(struct pipes_struct *p, struct wbint_GetNssInfo *r)
{
struct idmap_domain *domain;
NTSTATUS status;
domain = idmap_find_domain(r->in.info->domain_name);
if ((domain == NULL) || (domain->query_user == NULL)) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
status = domain->query_user(domain, r->in.info);
return status;
}
NTSTATUS _wbint_LookupUserAliases(struct pipes_struct *p,
struct wbint_LookupUserAliases *r)
{
struct winbindd_domain *domain = wb_child_domain();
NTSTATUS status;
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
status = wb_cache_lookup_useraliases(domain, p->mem_ctx,
r->in.sids->num_sids,
r->in.sids->sids,
&r->out.rids->num_rids,
&r->out.rids->rids);
reset_cm_connection_on_error(domain, NULL, status);
return status;
}
NTSTATUS _wbint_LookupUserGroups(struct pipes_struct *p,
struct wbint_LookupUserGroups *r)
{
struct winbindd_domain *domain = wb_child_domain();
NTSTATUS status;
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
status = wb_cache_lookup_usergroups(domain, p->mem_ctx, r->in.sid,
&r->out.sids->num_sids,
&r->out.sids->sids);
reset_cm_connection_on_error(domain, NULL, status);
return status;
}
NTSTATUS _wbint_QuerySequenceNumber(struct pipes_struct *p,
struct wbint_QuerySequenceNumber *r)
{
struct winbindd_domain *domain = wb_child_domain();
NTSTATUS status;
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
status = wb_cache_sequence_number(domain, r->out.sequence);
reset_cm_connection_on_error(domain, NULL, status);
return status;
}
NTSTATUS _wbint_LookupGroupMembers(struct pipes_struct *p,
struct wbint_LookupGroupMembers *r)
{
struct winbindd_domain *domain = wb_child_domain();
uint32_t i, num_names;
struct dom_sid *sid_mem;
char **names;
uint32_t *name_types;
NTSTATUS status;
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
status = wb_cache_lookup_groupmem(domain, p->mem_ctx, r->in.sid,
r->in.type, &num_names, &sid_mem,
&names, &name_types);
reset_cm_connection_on_error(domain, NULL, status);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
r->out.members->num_principals = num_names;
r->out.members->principals = talloc_array(
r->out.members, struct wbint_Principal, num_names);
if (r->out.members->principals == NULL) {
return NT_STATUS_NO_MEMORY;
}
for (i=0; i<num_names; i++) {
struct wbint_Principal *m = &r->out.members->principals[i];
sid_copy(&m->sid, &sid_mem[i]);
m->name = talloc_move(r->out.members->principals, &names[i]);
m->type = (enum lsa_SidType)name_types[i];
}
return NT_STATUS_OK;
}
NTSTATUS _wbint_QueryGroupList(struct pipes_struct *p,
struct wbint_QueryGroupList *r)
{
TALLOC_CTX *frame = NULL;
struct winbindd_domain *domain = wb_child_domain();
uint32_t i;
uint32_t num_local_groups = 0;
struct wb_acct_info *local_groups = NULL;
uint32_t num_dom_groups = 0;
struct wb_acct_info *dom_groups = NULL;
uint32_t ti = 0;
uint64_t num_total = 0;
struct wbint_Principal *result;
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
bool include_local_groups = false;
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
frame = talloc_stackframe();
switch (lp_server_role()) {
case ROLE_ACTIVE_DIRECTORY_DC:
if (domain->internal) {
/*
* we want to include local groups
* for BUILTIN and WORKGROUP
*/
include_local_groups = true;
}
break;
default:
/*
* We might include local groups in more
* setups later, but that requires more work
* elsewhere.
*/
break;
}
if (include_local_groups) {
status = wb_cache_enum_local_groups(domain, frame,
&num_local_groups,
&local_groups);
reset_cm_connection_on_error(domain, NULL, status);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
}
status = wb_cache_enum_dom_groups(domain, frame,
&num_dom_groups,
&dom_groups);
reset_cm_connection_on_error(domain, NULL, status);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
num_total = num_local_groups + num_dom_groups;
if (num_total > UINT32_MAX) {
status = NT_STATUS_INTERNAL_ERROR;
goto out;
}
result = talloc_array(frame, struct wbint_Principal, num_total);
if (result == NULL) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
for (i = 0; i < num_local_groups; i++) {
struct wb_acct_info *lg = &local_groups[i];
struct wbint_Principal *rg = &result[ti++];
sid_compose(&rg->sid, &domain->sid, lg->rid);
rg->type = SID_NAME_ALIAS;
rg->name = talloc_strdup(result, lg->acct_name);
if (rg->name == NULL) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
}
num_local_groups = 0;
for (i = 0; i < num_dom_groups; i++) {
struct wb_acct_info *dg = &dom_groups[i];
struct wbint_Principal *rg = &result[ti++];
sid_compose(&rg->sid, &domain->sid, dg->rid);
rg->type = SID_NAME_DOM_GRP;
rg->name = talloc_strdup(result, dg->acct_name);
if (rg->name == NULL) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
}
num_dom_groups = 0;
r->out.groups->num_principals = ti;
r->out.groups->principals = talloc_move(r->out.groups, &result);
status = NT_STATUS_OK;
out:
TALLOC_FREE(frame);
return status;
}
NTSTATUS _wbint_QueryUserRidList(struct pipes_struct *p,
struct wbint_QueryUserRidList *r)
{
struct winbindd_domain *domain = wb_child_domain();
NTSTATUS status;
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
/*
* Right now this is overkill. We should add a backend call
* just querying the rids.
*/
status = wb_cache_query_user_list(domain, p->mem_ctx,
&r->out.rids->rids);
reset_cm_connection_on_error(domain, NULL, status);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
r->out.rids->num_rids = talloc_array_length(r->out.rids->rids);
return NT_STATUS_OK;
}
NTSTATUS _wbint_DsGetDcName(struct pipes_struct *p, struct wbint_DsGetDcName *r)
{
struct winbindd_domain *domain = wb_child_domain();
struct rpc_pipe_client *netlogon_pipe;
struct netr_DsRGetDCNameInfo *dc_info;
NTSTATUS status;
WERROR werr;
unsigned int orig_timeout;
struct dcerpc_binding_handle *b;
bool retry = false;
bool try_dsrgetdcname = false;
if (domain == NULL) {
return dsgetdcname(p->mem_ctx, global_messaging_context(),
r->in.domain_name, r->in.domain_guid,
r->in.site_name ? r->in.site_name : "",
r->in.flags,
r->out.dc_info);
}
if (domain->active_directory) {
try_dsrgetdcname = true;
}
reconnect:
status = cm_connect_netlogon(domain, &netlogon_pipe);
reset_cm_connection_on_error(domain, NULL, status);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("Can't contact the NETLOGON pipe\n"));
return status;
}
b = netlogon_pipe->binding_handle;
/* This call can take a long time - allow the server to time out.
35 seconds should do it. */
orig_timeout = rpccli_set_timeout(netlogon_pipe, 35000);
if (try_dsrgetdcname) {
status = dcerpc_netr_DsRGetDCName(b,
p->mem_ctx, domain->dcname,
r->in.domain_name, NULL, r->in.domain_guid,
r->in.flags, r->out.dc_info, &werr);
if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(werr)) {
goto done;
}
if (!retry &&
reset_cm_connection_on_error(domain, NULL, status))
{
retry = true;
goto reconnect;
}
try_dsrgetdcname = false;
retry = false;
}
/*
* Fallback to less capable methods
*/
dc_info = talloc_zero(r->out.dc_info, struct netr_DsRGetDCNameInfo);
if (dc_info == NULL) {
status = NT_STATUS_NO_MEMORY;
goto done;
}
if (r->in.flags & DS_PDC_REQUIRED) {
status = dcerpc_netr_GetDcName(b,
p->mem_ctx, domain->dcname,
r->in.domain_name, &dc_info->dc_unc, &werr);
} else {
status = dcerpc_netr_GetAnyDCName(b,
p->mem_ctx, domain->dcname,
r->in.domain_name, &dc_info->dc_unc, &werr);
}
if (!retry && reset_cm_connection_on_error(domain, b, status)) {
retry = true;
goto reconnect;
}
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("dcerpc_netr_Get[Any]DCName failed: %s\n",
nt_errstr(status)));
goto done;
}
if (!W_ERROR_IS_OK(werr)) {
DEBUG(10, ("dcerpc_netr_Get[Any]DCName failed: %s\n",
win_errstr(werr)));
status = werror_to_ntstatus(werr);
goto done;
}
*r->out.dc_info = dc_info;
status = NT_STATUS_OK;
done:
/* And restore our original timeout. */
rpccli_set_timeout(netlogon_pipe, orig_timeout);
return status;
}
NTSTATUS _wbint_LookupRids(struct pipes_struct *p, struct wbint_LookupRids *r)
{
struct winbindd_domain *domain = wb_child_domain();
char *domain_name;
char **names;
enum lsa_SidType *types;
struct wbint_Principal *result;
NTSTATUS status;
uint32_t i;
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
status = wb_cache_rids_to_names(domain, talloc_tos(), r->in.domain_sid,
r->in.rids->rids, r->in.rids->num_rids,
&domain_name, &names, &types);
reset_cm_connection_on_error(domain, NULL, status);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
*r->out.domain_name = talloc_move(r->out.domain_name, &domain_name);
result = talloc_array(p->mem_ctx, struct wbint_Principal,
r->in.rids->num_rids);
if (result == NULL) {
return NT_STATUS_NO_MEMORY;
}
for (i=0; i<r->in.rids->num_rids; i++) {
sid_compose(&result[i].sid, r->in.domain_sid,
r->in.rids->rids[i]);
result[i].type = types[i];
result[i].name = talloc_move(result, &names[i]);
}
TALLOC_FREE(types);
TALLOC_FREE(names);
r->out.names->num_principals = r->in.rids->num_rids;
r->out.names->principals = result;
return NT_STATUS_OK;
}
NTSTATUS _wbint_CheckMachineAccount(struct pipes_struct *p,
struct wbint_CheckMachineAccount *r)
{
struct winbindd_domain *domain;
int num_retries = 0;
NTSTATUS status;
domain = wb_child_domain();
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
again:
invalidate_cm_connection(domain);
domain->conn.netlogon_force_reauth = true;
{
struct rpc_pipe_client *netlogon_pipe = NULL;
struct netlogon_creds_cli_context *netlogon_creds_ctx = NULL;
status = cm_connect_netlogon_secure(domain,
&netlogon_pipe,
&netlogon_creds_ctx);
}
/* There is a race condition between fetching the trust account
password and the periodic machine password change. So it's
possible that the trust account password has been changed on us.
We are returned NT_STATUS_ACCESS_DENIED if this happens. */
#define MAX_RETRIES 3
if ((num_retries < MAX_RETRIES)
&& NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
num_retries++;
goto again;
}
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
goto done;
}
/* Pass back result code - zero for success, other values for
specific failures. */
DEBUG(3,("domain %s secret is %s\n", domain->name,
NT_STATUS_IS_OK(status) ? "good" : "bad"));
done:
DEBUG(NT_STATUS_IS_OK(status) ? 5 : 2,
("Checking the trust account password for domain %s returned %s\n",
domain->name, nt_errstr(status)));
return status;
}
NTSTATUS _wbint_ChangeMachineAccount(struct pipes_struct *p,
struct wbint_ChangeMachineAccount *r)
{
struct messaging_context *msg_ctx = global_messaging_context();
struct winbindd_domain *domain;
NTSTATUS status;
struct rpc_pipe_client *netlogon_pipe = NULL;
struct netlogon_creds_cli_context *netlogon_creds_ctx = NULL;
domain = wb_child_domain();
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
status = cm_connect_netlogon_secure(domain,
&netlogon_pipe,
&netlogon_creds_ctx);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
goto done;
}
status = trust_pw_change(netlogon_creds_ctx,
msg_ctx,
netlogon_pipe->binding_handle,
domain->name,
domain->dcname,
true); /* force */
/* Pass back result code - zero for success, other values for
specific failures. */
DEBUG(3,("domain %s secret %s\n", domain->name,
NT_STATUS_IS_OK(status) ? "changed" : "unchanged"));
done:
DEBUG(NT_STATUS_IS_OK(status) ? 5 : 2,
("Changing the trust account password for domain %s returned %s\n",
domain->name, nt_errstr(status)));
return status;
}
NTSTATUS _wbint_PingDc(struct pipes_struct *p, struct wbint_PingDc *r)
{
NTSTATUS status;
struct winbindd_domain *domain;
struct rpc_pipe_client *netlogon_pipe;
union netr_CONTROL_QUERY_INFORMATION info;
WERROR werr;
fstring logon_server;
struct dcerpc_binding_handle *b;
bool retry = false;
domain = wb_child_domain();
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
reconnect:
status = cm_connect_netlogon(domain, &netlogon_pipe);
reset_cm_connection_on_error(domain, NULL, status);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("could not open handle to NETLOGON pipe: %s\n",
nt_errstr(status)));
return status;
}
b = netlogon_pipe->binding_handle;
fstr_sprintf(logon_server, "\\\\%s", domain->dcname);
*r->out.dcname = talloc_strdup(p->mem_ctx, domain->dcname);
if (*r->out.dcname == NULL) {
DEBUG(2, ("Could not allocate memory\n"));
return NT_STATUS_NO_MEMORY;
}
/*
* This provokes a WERR_NOT_SUPPORTED error message. This is
* documented in the wspp docs. I could not get a successful
* call to work, but the main point here is testing that the
* netlogon pipe works.
*/
status = dcerpc_netr_LogonControl(b, p->mem_ctx,
logon_server, NETLOGON_CONTROL_QUERY,
2, &info, &werr);
if (!retry && reset_cm_connection_on_error(domain, b, status)) {
retry = true;
goto reconnect;
}
if (!NT_STATUS_IS_OK(status)) {
DEBUG(2, ("dcerpc_netr_LogonControl failed: %s\n",
nt_errstr(status)));
return status;
}
if (!W_ERROR_EQUAL(werr, WERR_NOT_SUPPORTED)) {
DEBUG(2, ("dcerpc_netr_LogonControl returned %s, expected "
"WERR_NOT_SUPPORTED\n",
win_errstr(werr)));
return werror_to_ntstatus(werr);
}
DEBUG(5, ("winbindd_dual_ping_dc succeeded\n"));
return NT_STATUS_OK;
}
NTSTATUS _winbind_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct *p,
struct winbind_DsrUpdateReadOnlyServerDnsRecords *r)
{
struct winbindd_domain *domain;
NTSTATUS status;
struct rpc_pipe_client *netlogon_pipe = NULL;
struct netlogon_creds_cli_context *netlogon_creds_ctx = NULL;
struct dcerpc_binding_handle *b = NULL;
bool retry = false;
domain = wb_child_domain();
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
reconnect:
status = cm_connect_netlogon_secure(domain,
&netlogon_pipe,
&netlogon_creds_ctx);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
goto done;
}
b = netlogon_pipe->binding_handle;
status = netlogon_creds_cli_DsrUpdateReadOnlyServerDnsRecords(netlogon_creds_ctx,
netlogon_pipe->binding_handle,
r->in.site_name,
r->in.dns_ttl,
r->in.dns_names);
if (!retry && reset_cm_connection_on_error(domain, b, status)) {
retry = true;
goto reconnect;
}
/* Pass back result code - zero for success, other values for
specific failures. */
DEBUG(3,("DNS records for domain %s %s\n", domain->name,
NT_STATUS_IS_OK(status) ? "changed" : "unchanged"));
done:
DEBUG(NT_STATUS_IS_OK(status) ? 5 : 2,
("Update of DNS records via RW DC %s returned %s\n",
domain->name, nt_errstr(status)));
return status;
}
NTSTATUS _winbind_SamLogon(struct pipes_struct *p,
struct winbind_SamLogon *r)
{
struct winbindd_domain *domain;
NTSTATUS status;
struct netr_IdentityInfo *identity_info = NULL;
const uint8_t chal_zero[8] = {0, };
const uint8_t *challenge = chal_zero;
DATA_BLOB lm_response, nt_response;
uint32_t flags = 0;
uint16_t validation_level;
union netr_Validation *validation = NULL;
bool interactive = false;
domain = wb_child_domain();
if (domain == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
switch (r->in.validation_level) {
case 3:
case 6:
break;
default:
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
switch (r->in.logon_level) {
case NetlogonInteractiveInformation:
case NetlogonServiceInformation:
case NetlogonInteractiveTransitiveInformation:
case NetlogonServiceTransitiveInformation:
if (r->in.logon.password == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
interactive = true;
identity_info = &r->in.logon.password->identity_info;
challenge = chal_zero;
lm_response = data_blob_talloc(p->mem_ctx,
r->in.logon.password->lmpassword.hash,
sizeof(r->in.logon.password->lmpassword.hash));
nt_response = data_blob_talloc(p->mem_ctx,
r->in.logon.password->ntpassword.hash,
sizeof(r->in.logon.password->ntpassword.hash));
break;
case NetlogonNetworkInformation:
case NetlogonNetworkTransitiveInformation:
if (r->in.logon.network == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
interactive = false;
identity_info = &r->in.logon.network->identity_info;
challenge = r->in.logon.network->challenge;
lm_response = data_blob_talloc(p->mem_ctx,
r->in.logon.network->lm.data,
r->in.logon.network->lm.length);
nt_response = data_blob_talloc(p->mem_ctx,
r->in.logon.network->nt.data,
r->in.logon.network->nt.length);
break;
case NetlogonGenericInformation:
if (r->in.logon.generic == NULL) {
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
identity_info = &r->in.logon.generic->identity_info;
/*
* Not implemented here...
*/
return NT_STATUS_REQUEST_NOT_ACCEPTED;
default:
return NT_STATUS_REQUEST_NOT_ACCEPTED;
}
status = winbind_dual_SamLogon(domain, p->mem_ctx,
interactive,
identity_info->parameter_control,