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
|
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#ifndef _ADS_PRIV_H_RPCGEN
#define _ADS_PRIV_H_RPCGEN
#include <rpc/rpc.h>
#ifndef _KERNEL
#include <synch.h>
#include <thread.h>
#endif /* !_KERNEL */
#ifdef __cplusplus
extern "C" {
#endif
/*
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
/*
* from ads_priv.x
* Active Directory Services (ADS) Private interface between
* libads and the ADS deamon. (RPC over doors)
*/
/*
* Declarations for the ADS API
*/
#define ADSPRIV_MAX_XFER 16384
#define ADSPRIV_GUID_LEN 16
#define ADSPRIV_SOCKADDR_LEN 256
#define ADSPRIV_STR_MAX 256
typedef char adspriv_guid[ADSPRIV_GUID_LEN];
typedef char adspriv_sockaddr[ADSPRIV_SOCKADDR_LEN];
struct adspriv_dcinfo {
char *dci_DcName;
char *dci_DcAddr;
u_int dci_AddrType;
adspriv_guid dci_guid;
char *dci_DomainName;
char *dci_DnsForestName;
u_int dci_Flags;
char *dci_DcSiteName;
char *dci_ClientSiteName;
adspriv_sockaddr dci_sockaddr;
};
typedef struct adspriv_dcinfo adspriv_dcinfo;
struct DsForceRediscoveryArgs {
u_int Flags;
char *DomainName;
};
typedef struct DsForceRediscoveryArgs DsForceRediscoveryArgs;
struct DsGetDcNameArgs {
char *ComputerName;
char *DomainName;
char *DomainGuid;
char *SiteName;
u_int Flags;
};
typedef struct DsGetDcNameArgs DsGetDcNameArgs;
struct DsGetDcNameRes {
int status;
union {
adspriv_dcinfo res0;
} DsGetDcNameRes_u;
};
typedef struct DsGetDcNameRes DsGetDcNameRes;
#define ADSPRIV_PROGRAM 100001
#define ADSPRIV_V1 1
#if defined(__STDC__) || defined(__cplusplus)
#define ADSPRIV_NULL 0
extern enum clnt_stat adspriv_null_1(void *, CLIENT *);
extern bool_t adspriv_null_1_svc(void *, struct svc_req *);
#define ADSPRIV_ForceRediscovery 1
extern enum clnt_stat adspriv_forcerediscovery_1(DsForceRediscoveryArgs , int *, CLIENT *);
extern bool_t adspriv_forcerediscovery_1_svc(DsForceRediscoveryArgs , int *, struct svc_req *);
#define ADSPRIV_GetDcName 2
extern enum clnt_stat adspriv_getdcname_1(DsGetDcNameArgs , DsGetDcNameRes *, CLIENT *);
extern bool_t adspriv_getdcname_1_svc(DsGetDcNameArgs , DsGetDcNameRes *, struct svc_req *);
extern int adspriv_program_1_freeresult(SVCXPRT *, xdrproc_t, caddr_t);
#else /* K&R C */
#define ADSPRIV_NULL 0
extern enum clnt_stat adspriv_null_1();
extern bool_t adspriv_null_1_svc();
#define ADSPRIV_ForceRediscovery 1
extern enum clnt_stat adspriv_forcerediscovery_1();
extern bool_t adspriv_forcerediscovery_1_svc();
#define ADSPRIV_GetDcName 2
extern enum clnt_stat adspriv_getdcname_1();
extern bool_t adspriv_getdcname_1_svc();
extern int adspriv_program_1_freeresult();
#endif /* K&R C */
/* the xdr functions */
#if defined(__STDC__) || defined(__cplusplus)
extern bool_t xdr_adspriv_guid(XDR *, adspriv_guid);
extern bool_t xdr_adspriv_sockaddr(XDR *, adspriv_sockaddr);
extern bool_t xdr_adspriv_dcinfo(XDR *, adspriv_dcinfo*);
extern bool_t xdr_DsForceRediscoveryArgs(XDR *, DsForceRediscoveryArgs*);
extern bool_t xdr_DsGetDcNameArgs(XDR *, DsGetDcNameArgs*);
extern bool_t xdr_DsGetDcNameRes(XDR *, DsGetDcNameRes*);
#else /* K&R C */
extern bool_t xdr_adspriv_guid();
extern bool_t xdr_adspriv_sockaddr();
extern bool_t xdr_adspriv_dcinfo();
extern bool_t xdr_DsForceRediscoveryArgs();
extern bool_t xdr_DsGetDcNameArgs();
extern bool_t xdr_DsGetDcNameRes();
#endif /* K&R C */
#ifdef __cplusplus
}
#endif
#endif /* !_ADS_PRIV_H_RPCGEN */
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
%/*
% * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
% */
%/*
% * from ads_priv.x
% * Active Directory Services (ADS) Private interface between
% * libads and the ADS deamon. (RPC over doors)
% */
#ifdef RPC_HDR
%/*
% * Declarations for the ADS API
% */
#elif RPC_SVC
%
%/*
% * Server side stubs for the ADS API
% */
%
#elif RPC_CLNT
%
%/*
% * Client side stubs for the ADS API
% */
%
#elif RPC_XDR
%/*
% * XDR routines for the ADS API
% */
#endif
const ADSPRIV_MAX_XFER = 16384;
const ADSPRIV_GUID_LEN = 16;
const ADSPRIV_SOCKADDR_LEN = 256;
const ADSPRIV_STR_MAX = 256;
typedef opaque adspriv_guid[ADSPRIV_GUID_LEN];
typedef opaque adspriv_sockaddr[ADSPRIV_SOCKADDR_LEN];
/*
* Structure returned from DsGetDcName
* NB: Keep same as DOMAIN_CONTROLLER_INFO
*/
struct adspriv_dcinfo {
string dci_DcName<ADSPRIV_STR_MAX>;
string dci_DcAddr<ADSPRIV_STR_MAX>;
unsigned int dci_AddrType;
adspriv_guid dci_guid;
string dci_DomainName<ADSPRIV_STR_MAX>;
string dci_DnsForestName<ADSPRIV_STR_MAX>;
unsigned int dci_Flags;
string dci_DcSiteName<ADSPRIV_STR_MAX>;
string dci_ClientSiteName<ADSPRIV_STR_MAX>;
adspriv_sockaddr dci_sockaddr;
};
/*
* DsForceRediscovery args
*/
struct DsForceRediscoveryArgs {
unsigned int Flags;
string DomainName<ADSPRIV_STR_MAX>;
};
/*
* DsGetDcName args, result
*/
struct DsGetDcNameArgs {
string ComputerName<ADSPRIV_STR_MAX>;
string DomainName<ADSPRIV_STR_MAX>;
string DomainGuid<ADSPRIV_STR_MAX>;
string SiteName<ADSPRIV_STR_MAX>;
unsigned int Flags;
};
union DsGetDcNameRes switch (int status) {
case 0:
adspriv_dcinfo res0;
default:
void;
};
program ADSPRIV_PROGRAM {
version ADSPRIV_V1 {
void
ADSPRIV_NULL(void) = 0;
int
ADSPRIV_ForceRediscovery(DsForceRediscoveryArgs) = 1;
DsGetDcNameRes
ADSPRIV_GetDcName(DsGetDcNameArgs) = 2;
} = 1;
} = 100001;
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#include "ads_priv.h"
#ifndef _KERNEL
#include <stdlib.h>
#endif /* !_KERNEL */
/*
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
/*
* from ads_priv.x
* Active Directory Services (ADS) Private interface between
* libads and the ADS deamon. (RPC over doors)
*/
/*
* XDR routines for the ADS API
*/
bool_t
xdr_adspriv_guid(XDR *xdrs, adspriv_guid objp)
{
rpc_inline_t *buf __unused;
if (!xdr_opaque(xdrs, objp, ADSPRIV_GUID_LEN))
return (FALSE);
return (TRUE);
}
bool_t
xdr_adspriv_sockaddr(XDR *xdrs, adspriv_sockaddr objp)
{
rpc_inline_t *buf __unused;
if (!xdr_opaque(xdrs, objp, ADSPRIV_SOCKADDR_LEN))
return (FALSE);
return (TRUE);
}
bool_t
xdr_adspriv_dcinfo(XDR *xdrs, adspriv_dcinfo *objp)
{
rpc_inline_t *buf __unused;
if (!xdr_string(xdrs, &objp->dci_DcName, ADSPRIV_STR_MAX))
return (FALSE);
if (!xdr_string(xdrs, &objp->dci_DcAddr, ADSPRIV_STR_MAX))
return (FALSE);
if (!xdr_u_int(xdrs, &objp->dci_AddrType))
return (FALSE);
if (!xdr_adspriv_guid(xdrs, objp->dci_guid))
return (FALSE);
if (!xdr_string(xdrs, &objp->dci_DomainName, ADSPRIV_STR_MAX))
return (FALSE);
if (!xdr_string(xdrs, &objp->dci_DnsForestName, ADSPRIV_STR_MAX))
return (FALSE);
if (!xdr_u_int(xdrs, &objp->dci_Flags))
return (FALSE);
if (!xdr_string(xdrs, &objp->dci_DcSiteName, ADSPRIV_STR_MAX))
return (FALSE);
if (!xdr_string(xdrs, &objp->dci_ClientSiteName, ADSPRIV_STR_MAX))
return (FALSE);
if (!xdr_adspriv_sockaddr(xdrs, objp->dci_sockaddr))
return (FALSE);
return (TRUE);
}
bool_t
xdr_DsForceRediscoveryArgs(XDR *xdrs, DsForceRediscoveryArgs *objp)
{
rpc_inline_t *buf __unused;
if (!xdr_u_int(xdrs, &objp->Flags))
return (FALSE);
if (!xdr_string(xdrs, &objp->DomainName, ADSPRIV_STR_MAX))
return (FALSE);
return (TRUE);
}
bool_t
xdr_DsGetDcNameArgs(XDR *xdrs, DsGetDcNameArgs *objp)
{
rpc_inline_t *buf __unused;
if (!xdr_string(xdrs, &objp->ComputerName, ADSPRIV_STR_MAX))
return (FALSE);
if (!xdr_string(xdrs, &objp->DomainName, ADSPRIV_STR_MAX))
return (FALSE);
if (!xdr_string(xdrs, &objp->DomainGuid, ADSPRIV_STR_MAX))
return (FALSE);
if (!xdr_string(xdrs, &objp->SiteName, ADSPRIV_STR_MAX))
return (FALSE);
if (!xdr_u_int(xdrs, &objp->Flags))
return (FALSE);
return (TRUE);
}
bool_t
xdr_DsGetDcNameRes(XDR *xdrs, DsGetDcNameRes *objp)
{
rpc_inline_t *buf __unused;
if (!xdr_int(xdrs, &objp->status))
return (FALSE);
switch (objp->status) {
case 0:
if (!xdr_adspriv_dcinfo(xdrs, &objp->DsGetDcNameRes_u.res0))
return (FALSE);
break;
default:
break;
}
return (TRUE);
}
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
* Copyright 2021 RackTop Systems, Inc.
*/
/*
* MS-compatible Directory Server Discovery API, DsGetDC...()
*/
#include <stdlib.h>
#include <string.h>
#include <smb/nterror.h>
#include <smb/ntstatus.h>
#include <arpa/inet.h>
#include "dsgetdc.h"
#include "ads_priv.h"
#include <sys/debug.h>
#define DSGETDC_VALID_FLAGS ( \
DS_FORCE_REDISCOVERY | \
DS_DIRECTORY_SERVICE_REQUIRED | \
DS_DIRECTORY_SERVICE_PREFERRED | \
DS_GC_SERVER_REQUIRED | \
DS_PDC_REQUIRED | \
DS_BACKGROUND_ONLY | \
DS_IP_REQUIRED | \
DS_KDC_REQUIRED | \
DS_TIMESERV_REQUIRED | \
DS_WRITABLE_REQUIRED | \
DS_GOOD_TIMESERV_PREFERRED | \
DS_AVOID_SELF | \
DS_ONLY_LDAP_NEEDED | \
DS_IS_FLAT_NAME | \
DS_IS_DNS_NAME | \
DS_RETURN_FLAT_NAME | \
DS_RETURN_DNS_NAME)
static struct timeval TIMEOUT = { 15, 0 };
/*
* The Windows version of this would return a single allocation,
* where any strings pointed to in the returned structure would be
* stored in space following the top-level returned structure.
* This allows NetApiBufferFree() to be the same as free().
*
* However, we don't have an easy way to do that right now, so
* the dcinfo returned here will be free'd with DsFreeDcInfo().
*/
uint32_t
_DsGetDcName(const char *ComputerName,
const char *DomainName, const struct uuid *DomainGuid,
const char *SiteName, uint32_t Flags,
DOMAIN_CONTROLLER_INFO **dcinfo)
{
DsGetDcNameArgs args;
DsGetDcNameRes res;
CLIENT *clnt = NULL;
enum clnt_stat clstat;
*dcinfo = NULL;
(void) memset(&args, 0, sizeof (args));
(void) memset(&res, 0, sizeof (res));
/*
* Later check for over constrained optional args here,
* and return (ERROR_INVALID_PARAMETER);
*/
if (Flags & ~DSGETDC_VALID_FLAGS)
return (ERROR_INVALID_FLAGS);
/*
* Call the ADS deamon.
*/
clnt = clnt_door_create(ADSPRIV_PROGRAM, ADSPRIV_V1, ADSPRIV_MAX_XFER);
if (clnt == NULL)
return (RPC_S_NOT_LISTENING);
args.ComputerName = (char *)ComputerName;
args.DomainName = (char *)DomainName;
if (DomainGuid != NULL)
(void) memcpy(&args.DomainGuid, DomainGuid,
sizeof (args.DomainGuid));
args.SiteName = (char *)SiteName;
args.Flags = Flags;
clstat = clnt_call(clnt, ADSPRIV_GetDcName,
(xdrproc_t)xdr_DsGetDcNameArgs, (caddr_t)&args,
(xdrproc_t)xdr_DsGetDcNameRes, (caddr_t)&res, TIMEOUT);
clnt_destroy(clnt);
if (clstat != RPC_SUCCESS)
return (RPC_S_CALL_FAILED);
if (res.status != 0)
return (res.status);
*dcinfo = malloc(sizeof (**dcinfo));
if (*dcinfo == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
/*
* We have taken pains to make these two the same.
* DOMAIN_CONTROLLER_INFO / struct adspriv_dcinfo
*/
CTASSERT(sizeof (**dcinfo) == sizeof (res.DsGetDcNameRes_u.res0));
(void) memcpy(*dcinfo, &res.DsGetDcNameRes_u.res0, sizeof (**dcinfo));
/*
* NB: Do NOT xdr_free the result, because we're
* returning a copy of it to the caller.
*/
return (0);
}
int
DsGetDcName(const char *ComputerName,
const char *DomainName, const struct uuid *DomainGuid,
const char *SiteName, uint32_t Flags,
DOMAIN_CONTROLLER_INFO **dcinfo)
{
uint32_t status;
int rc;
status = _DsGetDcName(ComputerName, DomainName, DomainGuid,
SiteName, Flags, dcinfo);
switch (status) {
case 0:
rc = 0;
break;
case NT_STATUS_NO_SUCH_DOMAIN: /* Specified domain unknown */
case NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND:
case NT_STATUS_CANT_WAIT: /* or gave up waiting. */
case NT_STATUS_INVALID_SERVER_STATE: /* not in domain mode. */
rc = ERROR_NO_SUCH_DOMAIN;
break;
default:
rc = ERROR_INTERNAL_ERROR;
break;
}
return (rc);
}
void
DsFreeDcInfo(DOMAIN_CONTROLLER_INFO *dci)
{
if (dci != NULL) {
xdr_free(xdr_adspriv_dcinfo, (char *)dci);
free(dci);
}
}
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Declarations intentionally similar to the MSDN SDK file
* winsdk/Include/DsGetDC.h
*/
#ifndef _ADS_DSGETDC_H
#define _ADS_DSGETDC_H
#include <sys/types.h>
#include <sys/uuid.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Flags to passed to DsGetDcName
*/
#define DS_FORCE_REDISCOVERY 0x00000001
#define DS_DIRECTORY_SERVICE_REQUIRED 0x00000010
#define DS_DIRECTORY_SERVICE_PREFERRED 0x00000020
#define DS_GC_SERVER_REQUIRED 0x00000040
#define DS_PDC_REQUIRED 0x00000080
#define DS_BACKGROUND_ONLY 0x00000100
#define DS_IP_REQUIRED 0x00000200
#define DS_KDC_REQUIRED 0x00000400
#define DS_TIMESERV_REQUIRED 0x00000800
#define DS_WRITABLE_REQUIRED 0x00001000
#define DS_GOOD_TIMESERV_PREFERRED 0x00002000
#define DS_AVOID_SELF 0x00004000
#define DS_ONLY_LDAP_NEEDED 0x00008000
#define DS_IS_FLAT_NAME 0x00010000
#define DS_IS_DNS_NAME 0x00020000
#define DS_RETURN_DNS_NAME 0x40000000
#define DS_RETURN_FLAT_NAME 0x80000000
/*
* Structure returned from DsGetDcName
* NB: Keep same as adspriv_dcinfo
*/
typedef struct _DOMAIN_CONTROLLER_INFO {
char *DomainControllerName;
char *DomainControllerAddress;
uint32_t DomainControllerAddressType;
uuid_t DomainGuid;
char *DomainName;
char *DnsForestName;
uint32_t Flags;
char *DcSiteName;
char *ClientSiteName;
uint8_t _sockaddr[256];
} DOMAIN_CONTROLLER_INFO, *PDOMAIN_CONTROLLER_INFO;
/*
* Values for DomainControllerAddressType
*/
#define DS_INET_ADDRESS 1
#define DS_NETBIOS_ADDRESS 2
/*
* Values for returned Flags
*/
#define DS_PDC_FLAG 0x00000001 /* DC is PDC of Domain */
#define DS_GC_FLAG 0x00000004 /* DC is a GC of forest */
#define DS_LDAP_FLAG 0x00000008 /* supports an LDAP server */
#define DS_DS_FLAG 0x00000010 /* supports a DS and is a */
/* Domain Controller */
#define DS_KDC_FLAG 0x00000020 /* is running KDC service */
#define DS_TIMESERV_FLAG 0x00000040 /* is running time service */
#define DS_CLOSEST_FLAG 0x00000080 /* DC is in closest site */
/* to the client */
#define DS_WRITABLE_FLAG 0x00000100 /* DC has a writable DS */
#define DS_GOOD_TIMESERV_FLAG 0x00000200 /* is running time service */
/* (and has clock hardware) */
#define DS_NDNC_FLAG 0x00000400 /* DomainName is non-domain */
/* NC serviced by the */
/* LDAP server */
#define DS_PING_FLAGS 0x0000FFFF /* Flags returned on ping */
#define DS_DNS_CONTROLLER_FLAG 0x20000000 /* DC Name is a DNS name */
#define DS_DNS_DOMAIN_FLAG 0x40000000 /* DomainName is a DNS name */
#define DS_DNS_FOREST_FLAG 0x80000000 /* ForestName is a DNS name */
/*
* Function Prototypes
*/
/* Offial API. Returns an NT error number. */
extern int
DsGetDcName(const char *ComputerName,
const char *DomainName, const struct uuid *DomainGuid,
const char *SiteName, uint32_t Flags,
DOMAIN_CONTROLLER_INFO **dcinfo);
/* internal version of above - returns a detailed NT status */
extern uint32_t
_DsGetDcName(const char *ComputerName,
const char *DomainName, const struct uuid *DomainGuid,
const char *SiteName, uint32_t Flags,
DOMAIN_CONTROLLER_INFO **dcinfo);
extern int
DsGetSiteName(
const char *ComputerName,
char **SiteName);
/*
* XXX: Others from DsGetDc.h we may want later:
* DsValidateSubnetName()
* DsAddressToSiteNames()
* DsAddressToSiteNamesEx()
* DsEnumerateDomainTrusts()
* DsGetForestTrustInformation()
* DsGetDcSiteCoverage()
* DsDeregisterDnsHostRecords()
* DsGetDcOpen(), DsGetDcNext(), DsGetDcClose()
*/
/*
* Until we can easily allocate a DC Info as one big hunk.
* This will free a DC Info returned by DsGetDcName().
*/
extern void
DsFreeDcInfo(DOMAIN_CONTROLLER_INFO *);
/*
* Internal function to force DC Rediscovery.
*/
extern int
_DsForceRediscovery(char *domain, int flags);
#ifdef __cplusplus
}
#endif
#endif /* _ADS_DSGETDC_H */
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2014 Nexenta Systems, Inc. All rights reserved.
#
#
# MAPFILE HEADER START
#
# WARNING: STOP NOW. DO NOT MODIFY THIS FILE.
# Object versioning must comply with the rules detailed in
#
# usr/src/lib/README.mapfiles
#
# You should not be making modifications here until you've read the most current
# copy of that file. If you need help, contact a gatekeeper for guidance.
#
# MAPFILE HEADER END
#
$mapfile_version 2
SYMBOL_VERSION SUNWprivate {
global:
_DsForceRediscovery;
_DsGetDcName;
DsFreeDcInfo;
DsGetDcName;
xdr_adspriv_dcinfo;
xdr_DsForceRediscoveryArgs;
xdr_DsGetDcNameArgs;
xdr_DsGetDcNameRes;
local:
*;
};
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Private API to force DC Rediscovery.
*/
#include <stdlib.h>
#include <string.h>
#include <smb/nterror.h>
#include <arpa/inet.h>
#include "dsgetdc.h"
#include "ads_priv.h"
#include <assert.h>
static struct timeval TIMEOUT = { 15, 0 };
int
_DsForceRediscovery(char *domain, int flags)
{
DsForceRediscoveryArgs args;
CLIENT *clnt = NULL;
enum clnt_stat clstat;
int res;
(void) memset(&args, 0, sizeof (args));
args.Flags = flags;
args.DomainName = domain;
/*
* Call the ADS deamon.
*/
clnt = clnt_door_create(ADSPRIV_PROGRAM, ADSPRIV_V1, ADSPRIV_MAX_XFER);
if (clnt == NULL)
return (RPC_S_NOT_LISTENING);
clstat = clnt_call(clnt, ADSPRIV_ForceRediscovery,
(xdrproc_t)xdr_DsForceRediscoveryArgs, (caddr_t)&args,
(xdrproc_t)xdr_int, (caddr_t)&res, TIMEOUT);
clnt_destroy(clnt);
if (clstat != RPC_SUCCESS)
return (RPC_S_CALL_FAILED);
return (res);
}
|