summaryrefslogtreecommitdiffstats
path: root/source3/lib/netapi/tests/common.c
blob: 22175afb48a1cb81f5f7dad9ff5d3e268046e854 (plain)
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
/*
 *  Unix SMB/CIFS implementation.
 *  NetApi testsuite
 *  Copyright (C) Guenther Deschner 2008
 *
 *  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 <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <inttypes.h>

#include <popt.h>
#include <netapi.h>

#include "common.h"

void popt_common_callback(poptContext con,
			 enum poptCallbackReason reason,
			 const struct poptOption *opt,
			 const char *arg, const void *data)
{
	struct libnetapi_ctx *ctx = NULL;

	libnetapi_getctx(&ctx);

	if (reason == POPT_CALLBACK_REASON_PRE) {
	}

	if (reason == POPT_CALLBACK_REASON_POST) {
	}

	if (!opt) {
		return;
	}
	switch (opt->val) {
		case 'U': {
			char *puser = strdup(arg);
			char *p = NULL;

			if ((p = strchr(puser,'%'))) {
				size_t len;
				*p = 0;
				libnetapi_set_username(ctx, puser);
				libnetapi_set_password(ctx, p+1);
				len = strlen(p+1);
				memset(strchr(arg,'%')+1,'X',len);
			} else {
				libnetapi_set_username(ctx, puser);
			}
			free(puser);
			break;
		}
		case 'd':
			libnetapi_set_debuglevel(ctx, arg);
			break;
		case 'p':
			libnetapi_set_password(ctx, arg);
			break;
		case 'k':
			libnetapi_set_use_kerberos(ctx);
			break;
	}
}

struct poptOption popt_common_netapi_examples[] = {
	{ NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_callback },
	{ "user", 'U', POPT_ARG_STRING, NULL, 'U', "Username used for connection", "USERNAME" },
	{ "password", 'p', POPT_ARG_STRING, NULL, 'p', "Password used for connection", "PASSWORD" },
	{ "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Debuglevel", "DEBUGLEVEL" },
	{ "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use Kerberos", NULL },
	POPT_TABLEEND
};

'#n339'>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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470
/*
  netlogon interface
  much of this was derived from the ethereal sources - thanks to everyone 
  who contributed!
*/

import "misc.idl", "lsa.idl", "samr.idl", "security.idl", "nbt.idl";

#include "idl_types.h"

[
  uuid("12345678-1234-abcd-ef00-01234567cffb"),
  version(1.0),
  endpoint("ncacn_np:[\\pipe\\netlogon]","ncacn_ip_tcp:","ncalrpc:"),
  pointer_default(unique)
]

interface netlogon
{
	typedef bitmap samr_AcctFlags samr_AcctFlags;
	typedef bitmap samr_GroupAttrs samr_GroupAttrs;

	/*****************/
	/* Function 0x00 */

	typedef struct {
		[string,charset(UTF16)] uint16 *account_name;
		uint32 priv;
		uint32 auth_flags;
		uint32 logon_count;
		uint32 bad_pw_count;
		time_t last_logon;
		time_t last_logoff;
		time_t logoff_time;
		time_t kickoff_time;
		uint32 password_age;
		time_t pw_can_change;
		time_t pw_must_change;
		[string,charset(UTF16)] uint16 *computer;
		[string,charset(UTF16)] uint16 *domain;
		[string,charset(UTF16)] uint16 *script_path;
		uint32 unknown;
	} netr_UasInfo;

	WERROR netr_LogonUasLogon(
		[in,unique] [string,charset(UTF16)] uint16 *server_name,
		[in]   [string,charset(UTF16)] uint16 account_name[],
		[in]   [string,charset(UTF16)] uint16 workstation[],
		[out,ref]  netr_UasInfo *info
		);


	/*****************/
	/* Function 0x01 */

	typedef struct {
		uint32 duration;
		uint16 logon_count;
	} netr_UasLogoffInfo;

	WERROR netr_LogonUasLogoff(
		[in,unique] [string,charset(UTF16)] uint16 *server_name,
		[in] [string,charset(UTF16)] uint16 account_name[],
		[in] [string,charset(UTF16)] uint16 workstation[],
		[out,ref] netr_UasLogoffInfo *info
		);


	/*****************/
	/* Function 0x02 */

	/* in netr_AcctLockStr size seems to be be 24, and rrenard thinks 
	   that the structure of the bindata looks like this:

		dlong  lockout_duration;
		udlong reset_count;
		uint32 bad_attempt_lockout;
		uint32 dummy;	

	   but it doesn't look as though this structure is reflected at the
	   NDR level. Maybe it is left to the application to decode the bindata array.
	*/
	typedef [public] struct {
		dlong lockout_duration;
		udlong reset_count;
		uint32 bad_attempt_lockout;
		uint32 dummy;
	} netr_AcctLockStr;

	/* - MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
	 *   sets the NETLOGON_SERVER_TRUST_ACCOUNT user_flag
	 * - MSV1_0_UPDATE_LOGON_STATISTICS
	 *   sets the logon time on network logon
	 * - MSV1_0_RETURN_USER_PARAMETERS
	 *   sets the user parameters in the driveletter
	 * - MSV1_0_RETURN_PROFILE_PATH
	 *   returns the profilepath in the driveletter and
	 *   sets LOGON_PROFILE_PATH_RETURNED user_flag
	 */

	typedef [public,bitmap32bit] bitmap {
		MSV1_0_CLEARTEXT_PASSWORD_ALLOWED	= 0x00000002,
		MSV1_0_UPDATE_LOGON_STATISTICS		= 0x00000004,
		MSV1_0_RETURN_USER_PARAMETERS		= 0x00000008,
		MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT	= 0x00000020,
		MSV1_0_RETURN_PROFILE_PATH		= 0x00000200,
		MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT	= 0x00000800
	} netr_LogonParameterControl;

	typedef struct {
		lsa_String  domain_name;
		netr_LogonParameterControl parameter_control; /* see MSV1_0_* */
		uint32      logon_id_low;
		uint32      logon_id_high;
		lsa_String  account_name;
		lsa_String  workstation;
	} netr_IdentityInfo;

	typedef struct {
		netr_IdentityInfo identity_info;
		samr_Password lmpassword;
		samr_Password ntpassword;
	} netr_PasswordInfo;

	typedef [flag(NDR_PAHEX)] struct {
		uint16 length;
		[value(length)] uint16 size;
		[size_is(length),length_is(length)] uint8 *data;
	} netr_ChallengeResponse;

	typedef [flag(NDR_PAHEX)] struct {
		netr_IdentityInfo identity_info;
		uint8 challenge[8];
		netr_ChallengeResponse nt;
		netr_ChallengeResponse lm;
	} netr_NetworkInfo;

	typedef [flag(NDR_PAHEX)] struct {
		netr_IdentityInfo identity_info;
		lsa_String  package_name;
		uint32 length;
		[size_is(length)] uint8 *data;
	} netr_GenericInfo;

	typedef enum {
		NetlogonInteractiveInformation = 1,
		NetlogonNetworkInformation = 2,
		NetlogonServiceInformation = 3,
		NetlogonGenericInformation = 4,
		NetlogonInteractiveTransitiveInformation = 5,
		NetlogonNetworkTransitiveInformation = 6,
		NetlogonServiceTransitiveInformation = 7
	} netr_LogonInfoClass;

	typedef [public,switch_type(netr_LogonInfoClass)] union {
		[case(NetlogonInteractiveInformation)]           netr_PasswordInfo *password;
		[case(NetlogonNetworkInformation)]               netr_NetworkInfo  *network;
 		[case(NetlogonServiceInformation)]               netr_PasswordInfo *password;
 		[case(NetlogonGenericInformation)]               netr_GenericInfo  *generic;
		[case(NetlogonInteractiveTransitiveInformation)] netr_PasswordInfo *password;
		[case(NetlogonNetworkTransitiveInformation)]     netr_NetworkInfo  *network;
 		[case(NetlogonServiceTransitiveInformation)]     netr_PasswordInfo *password;
	} netr_LogonLevel;

	typedef [public,flag(NDR_PAHEX)] struct {
		uint8 key[16];
	} netr_UserSessionKey;

	typedef [public,flag(NDR_PAHEX)] struct {
		uint8 key[8];
	} netr_LMSessionKey;

	/* Flags for user_flags below */
	typedef [public,bitmap32bit] bitmap {
		NETLOGON_GUEST			= 0x00000001,
		NETLOGON_NOENCRYPTION		= 0x00000002,
		NETLOGON_CACHED_ACCOUNT		= 0x00000004,
		NETLOGON_USED_LM_PASSWORD	= 0x00000008,
		NETLOGON_EXTRA_SIDS 		= 0x00000020,
		NETLOGON_SUBAUTH_SESSION_KEY	= 0x00000040,
		NETLOGON_SERVER_TRUST_ACCOUNT	= 0x00000080,
		NETLOGON_NTLMV2_ENABLED		= 0x00000100,
		NETLOGON_RESOURCE_GROUPS	= 0x00000200,
		NETLOGON_PROFILE_PATH_RETURNED	= 0x00000400,
		NETLOGON_GRACE_LOGON		= 0x01000000
	} netr_UserFlags;

	typedef struct {
		NTTIME last_logon;
		NTTIME last_logoff;
		NTTIME acct_expiry;
		NTTIME last_password_change;
		NTTIME allow_password_change;
		NTTIME force_password_change;
		lsa_String account_name;
		lsa_String full_name;
		lsa_String logon_script;
		lsa_String profile_path;
		lsa_String home_directory;
		lsa_String home_drive;
		uint16 logon_count;
		uint16 bad_password_count;
		uint32 rid;
		uint32 primary_gid;
		samr_RidWithAttributeArray groups;
		netr_UserFlags user_flags;
		netr_UserSessionKey key;
		lsa_StringLarge logon_server;
		lsa_StringLarge domain;
		dom_sid2 *domain_sid;
		netr_LMSessionKey LMSessKey;
		samr_AcctFlags acct_flags;
		uint32 unknown[7];
	} netr_SamBaseInfo;

	typedef struct {
		netr_SamBaseInfo base;
	} netr_SamInfo2;

	typedef struct {
		dom_sid2 *sid;
		samr_GroupAttrs attributes;
	} netr_SidAttr;

	typedef [public] struct {
		netr_SamBaseInfo base;
		uint32 sidcount;
		[size_is(sidcount)] netr_SidAttr *sids;
	} netr_SamInfo3;

	typedef struct {
		netr_SamBaseInfo base;
		uint32 sidcount;
		[size_is(sidcount)] netr_SidAttr *sids;
		lsa_String forest;
		lsa_String principle;
		uint32 unknown4[20];
	} netr_SamInfo6;

	typedef struct {
		uint32 pac_size;
		[size_is(pac_size)] uint8 *pac;
		lsa_String logon_domain;
		lsa_String logon_server;
		lsa_String principal_name;
		uint32 auth_size;
		[size_is(auth_size)] uint8 *auth;
		netr_UserSessionKey user_session_key;
		uint32 expansionroom[10];
		lsa_String unknown1;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
	} netr_PacInfo;

	typedef [flag(NDR_PAHEX)] struct {
		uint32 length;
		[size_is(length)] uint8 *data;
	} netr_GenericInfo2;

	typedef enum {
		NetlogonValidationUasInfo = 1,
		NetlogonValidationSamInfo = 2,
		NetlogonValidationSamInfo2 = 3,
		NetlogonValidationGenericInfo2 = 5,
		NetlogonValidationSamInfo4 = 6
	} netr_ValidationInfoClass;

	typedef [public,switch_type(uint16)] union {
		[case(NetlogonValidationSamInfo)] netr_SamInfo2 *sam2;
		[case(NetlogonValidationSamInfo2)] netr_SamInfo3 *sam3;
		[case(4)] netr_PacInfo  *pac;
		[case(NetlogonValidationGenericInfo2)] netr_GenericInfo2  *generic;
		[case(NetlogonValidationSamInfo4)] netr_SamInfo6 *sam6;
	} netr_Validation;

	typedef [public, flag(NDR_PAHEX)] struct {
		uint8 data[8];
	} netr_Credential;

	typedef [public] struct {
		netr_Credential cred;
		time_t timestamp;
	} netr_Authenticator;

	NTSTATUS netr_LogonSamLogon(
		[in,unique] [string,charset(UTF16)] uint16         *server_name,
		[in,unique] [string,charset(UTF16)] uint16         *computer_name,
		[in,unique] netr_Authenticator                     *credential,
		[in,out,unique] netr_Authenticator                 *return_authenticator,
		[in]  netr_LogonInfoClass                           logon_level,
		[in]  [switch_is(logon_level)] netr_LogonLevel      logon,
		[in]  uint16                                        validation_level,
		[out] [switch_is(validation_level)] netr_Validation validation,
		[out] uint8                                         authoritative
		);


	/*****************/
	/* Function 0x03 */

	NTSTATUS netr_LogonSamLogoff(
		[in,unique] [string,charset(UTF16)] uint16 *server_name,
		[in,unique] [string,charset(UTF16)] uint16 *computer_name,
		[in,unique] netr_Authenticator *credential,
		[in,out,unique] netr_Authenticator *return_authenticator,
		[in] uint16 logon_level,
		[in] [switch_is(logon_level)] netr_LogonLevel logon
		);
	


	/*****************/
	/* Function 0x04 */

	[public] NTSTATUS netr_ServerReqChallenge(
		[in,unique,string,charset(UTF16)] uint16 *server_name,
		[in,string,charset(UTF16)] uint16 computer_name[],
		[in,out,ref] netr_Credential *credentials
		);


	/*****************/
	/* Function 0x05 */

	typedef enum netr_SchannelType netr_SchannelType;

	NTSTATUS netr_ServerAuthenticate(
		[in,unique,string,charset(UTF16)] uint16 *server_name,
		[in,string,charset(UTF16)] uint16 account_name[],
		[in]                       netr_SchannelType secure_channel_type,
		[in,string,charset(UTF16)] uint16 computer_name[],
		[in,out,ref] netr_Credential *credentials
		);


	/*****************/
	/* Function 0x06 */

	NTSTATUS netr_ServerPasswordSet(
		[in,unique] [string,charset(UTF16)] uint16 *server_name,
		[in]  [string,charset(UTF16)] uint16 account_name[],
		[in]  netr_SchannelType secure_channel_type,
		[in]  [string,charset(UTF16)] uint16 computer_name[],
		[in]  netr_Authenticator credential,
		[in]  samr_Password new_password,
		[out] netr_Authenticator return_authenticator
		);


	/*****************/
	/* Function 0x07 */

	typedef enum netr_SamDatabaseID netr_SamDatabaseID;

	typedef struct {
		[string,charset(UTF16)] uint16 *account_name;
		lsa_String unknown1;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
		uint32 unknown5;
		uint32 unknown6;
		uint32 unknown7;
		uint32 unknown8;
	} netr_DELTA_DELETE_USER;

	typedef struct {
		uint16 length;
		[value(length)] uint16 size;
		uint32 flags;
		samr_Password pwd;
	} netr_USER_KEY16;

	typedef struct {
		uint16 nt_length;
		[value(nt_length)] uint16 nt_size;
		uint32 nt_flags;
		uint16 lm_length;
		[value(lm_length)] uint16 lm_size;
		uint32 lm_flags;
		uint8 nt_history[nt_length];
		uint8 lm_history[lm_length];
	} netr_PasswordHistory;

	typedef struct {
		netr_USER_KEY16 lmpassword;
		netr_USER_KEY16 ntpassword;
		netr_PasswordHistory history;
	} netr_USER_KEYS2;

	typedef struct { /* TODO: make this a union! */
		netr_USER_KEYS2 keys2;
	} netr_USER_KEY_UNION;

	typedef [public] struct {
		uint32 version;
		netr_USER_KEY_UNION keys;
	} netr_USER_KEYS;

	typedef struct {
		boolean8  SensitiveDataFlag;
		uint32 DataLength;

		/* netr_USER_KEYS encrypted with the session key */
		[size_is(DataLength)][flag(NDR_PAHEX)] uint8 *SensitiveData;
	} netr_USER_PRIVATE_INFO;

	typedef struct {
		lsa_String account_name;
		lsa_String full_name;
		uint32 rid;
		uint32 primary_gid;
		lsa_String home_directory;
		lsa_String home_drive;
		lsa_String logon_script;
		lsa_String description;
		lsa_String workstations;
		NTTIME last_logon;
		NTTIME last_logoff;
		samr_LogonHours logon_hours;
		uint16 bad_password_count;
		uint16 logon_count;
		NTTIME last_password_change;
		NTTIME acct_expiry;
		samr_AcctFlags acct_flags;
		samr_Password lmpassword;
		samr_Password ntpassword;
		boolean8 nt_password_present;
		boolean8 lm_password_present;
		boolean8 password_expired;
		lsa_String comment;
		lsa_String parameters;
		uint16 country_code;
		uint16 code_page;
		netr_USER_PRIVATE_INFO user_private_info;
		uint32 SecurityInformation;
		sec_desc_buf sdbuf;
		lsa_String profile_path;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
		uint32 unknown5;
		uint32 unknown6;
		uint32 unknown7;
		uint32 unknown8;
	} netr_DELTA_USER;

	typedef struct {
		lsa_String domain_name;
		lsa_String oem_information; /* comment */
		dlong force_logoff_time;
		uint16 min_password_length;
		uint16 password_history_length;
		/* yes, these are signed. They are in negative 100ns */
		dlong  max_password_age;
		dlong  min_password_age;
		udlong sequence_num;
		NTTIME domain_create_time;
		uint32 SecurityInformation;
		sec_desc_buf sdbuf;
		lsa_BinaryString account_lockout;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
		uint32 logon_to_chgpass;
		uint32 unknown6;
		uint32 unknown7;
		uint32 unknown8;
	} netr_DELTA_DOMAIN;

	typedef struct {
		lsa_String group_name;
		uint32 rid;
		uint32 attributes;
		lsa_String description;
		uint32 SecurityInformation;
		sec_desc_buf sdbuf;
		lsa_String unknown1;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
		uint32 unknown5;
		uint32 unknown6;
		uint32 unknown7;
		uint32 unknown8;
	} netr_DELTA_GROUP;

	typedef struct {
		lsa_String OldName;
		lsa_String NewName;
		lsa_String unknown1;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
		uint32 unknown5;
		uint32 unknown6;
		uint32 unknown7;
		uint32 unknown8;
	} netr_DELTA_RENAME;

	typedef struct {
		[size_is(num_rids)] uint32 *rids;
		[size_is(num_rids)] uint32 *attribs;
		uint32 num_rids;
		uint32 unknown1;
		uint32 unknown2;
		uint32 unknown3;
		uint32 unknown4;
	} netr_DELTA_GROUP_MEMBER;

	typedef struct {
		lsa_String alias_name;
		uint32 rid;
		uint32 SecurityInformation;
		sec_desc_buf sdbuf;
		lsa_String description;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
		uint32 unknown5;
		uint32 unknown6;
		uint32 unknown7;
		uint32 unknown8;
	} netr_DELTA_ALIAS;

	typedef struct {
		lsa_SidArray sids;
		uint32 unknown1;
		uint32 unknown2;
		uint32 unknown3;
		uint32 unknown4;
	} netr_DELTA_ALIAS_MEMBER;

	typedef struct {
		uint32 pagedpoollimit;
		uint32 nonpagedpoollimit;
		uint32 minimumworkingsetsize;
		uint32 maximumworkingsetsize;
		uint32 pagefilelimit;
		NTTIME timelimit;
	} netr_QUOTA_LIMITS;

	typedef struct {
		uint32 maxlogsize;
		NTTIME auditretentionperiod;
		boolean8 auditingmode;
		uint32 maxauditeventcount;
		[size_is(maxauditeventcount+1)] uint32 *eventauditoptions;
		lsa_String primary_domain_name;
		dom_sid2 *sid;
		netr_QUOTA_LIMITS quota_limits;
		udlong sequence_num;
		NTTIME db_create_time;
		uint32 SecurityInformation;
		sec_desc_buf sdbuf;
		lsa_String unknown1;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
		uint32 unknown5;
		uint32 unknown6;
		uint32 unknown7;
		uint32 unknown8;
	} netr_DELTA_POLICY;

	typedef struct {
		lsa_String domain_name;
		uint32 num_controllers;
		[size_is(num_controllers)] lsa_String *controller_names;
		uint32 SecurityInformation;
		sec_desc_buf sdbuf;
		lsa_String unknown1;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
		uint32 posix_offset;
		uint32 unknown6;
		uint32 unknown7;
		uint32 unknown8;
	} netr_DELTA_TRUSTED_DOMAIN;

	typedef struct {
		uint16 unknown;
	} netr_DELTA_DELETE_TRUST;

	typedef struct {
		uint32 privilege_entries;
		uint32 privilege_control;
		[size_is(privilege_entries)] uint32 *privilege_attrib;
		[size_is(privilege_entries)] lsa_String *privilege_name;
		netr_QUOTA_LIMITS quotalimits;
		uint32 system_flags;
		uint32 SecurityInformation;
		sec_desc_buf sdbuf;
		lsa_String unknown1;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
		uint32 unknown5;
		uint32 unknown6;
		uint32 unknown7;
		uint32 unknown8;
	} netr_DELTA_ACCOUNT;

	typedef struct {
		uint16 unknown;
	} netr_DELTA_DELETE_ACCOUNT;

	typedef struct {
		uint16 unknown;
	} netr_DELTA_DELETE_SECRET;

	typedef struct {
		uint32 len;
		uint32 maxlen;
		[size_is(maxlen)][length_is(len)] uint8 *cipher_data;
	} netr_CIPHER_VALUE;

	typedef struct {
		netr_CIPHER_VALUE current_cipher;
		NTTIME current_cipher_set_time;
		netr_CIPHER_VALUE old_cipher;
		NTTIME old_cipher_set_time;
		uint32 SecurityInformation;
		sec_desc_buf sdbuf;
		lsa_String unknown1;
		lsa_String unknown2;
		lsa_String unknown3;
		lsa_String unknown4;
		uint32 unknown5;
		uint32 unknown6;
		uint32 unknown7;
		uint32 unknown8;
	} netr_DELTA_SECRET;

	typedef enum {
		NETR_DELTA_DOMAIN           = 1,
		NETR_DELTA_GROUP            = 2,
		NETR_DELTA_DELETE_GROUP     = 3,
		NETR_DELTA_RENAME_GROUP     = 4,
		NETR_DELTA_USER             = 5,
		NETR_DELTA_DELETE_USER      = 6,
		NETR_DELTA_RENAME_USER      = 7,
		NETR_DELTA_GROUP_MEMBER     = 8,
		NETR_DELTA_ALIAS            = 9,
		NETR_DELTA_DELETE_ALIAS     = 10,
		NETR_DELTA_RENAME_ALIAS     = 11,
		NETR_DELTA_ALIAS_MEMBER     = 12,
		NETR_DELTA_POLICY           = 13,
		NETR_DELTA_TRUSTED_DOMAIN   = 14,
		NETR_DELTA_DELETE_TRUST     = 15,
		NETR_DELTA_ACCOUNT          = 16,
		NETR_DELTA_DELETE_ACCOUNT   = 17,
		NETR_DELTA_SECRET           = 18,
		NETR_DELTA_DELETE_SECRET    = 19,
		NETR_DELTA_DELETE_GROUP2    = 20,
		NETR_DELTA_DELETE_USER2     = 21,
		NETR_DELTA_MODIFY_COUNT     = 22
	} netr_DeltaEnum;

	typedef [switch_type(netr_DeltaEnum)] union {
		[case(NETR_DELTA_DOMAIN)]          netr_DELTA_DOMAIN          *domain;
		[case(NETR_DELTA_GROUP)]           netr_DELTA_GROUP           *group;
		[case(NETR_DELTA_DELETE_GROUP)]    ; /* rid only */
		[case(NETR_DELTA_RENAME_GROUP)]    netr_DELTA_RENAME          *rename_group;
		[case(NETR_DELTA_USER)]            netr_DELTA_USER            *user;
		[case(NETR_DELTA_DELETE_USER)]     ; /* rid only */
		[case(NETR_DELTA_RENAME_USER)]     netr_DELTA_RENAME          *rename_user;
		[case(NETR_DELTA_GROUP_MEMBER)]    netr_DELTA_GROUP_MEMBER    *group_member;
		[case(NETR_DELTA_ALIAS)]           netr_DELTA_ALIAS           *alias;
		[case(NETR_DELTA_DELETE_ALIAS)]    ; /* rid only */
		[case(NETR_DELTA_RENAME_ALIAS)]    netr_DELTA_RENAME          *rename_alias;
		[case(NETR_DELTA_ALIAS_MEMBER)]    netr_DELTA_ALIAS_MEMBER    *alias_member;
		[case(NETR_DELTA_POLICY)]          netr_DELTA_POLICY          *policy;
		[case(NETR_DELTA_TRUSTED_DOMAIN)]  netr_DELTA_TRUSTED_DOMAIN   *trusted_domain;
		[case(NETR_DELTA_DELETE_TRUST)]    netr_DELTA_DELETE_TRUST     delete_trust;
		[case(NETR_DELTA_ACCOUNT)]         netr_DELTA_ACCOUNT         *account;
		[case(NETR_DELTA_DELETE_ACCOUNT)]  netr_DELTA_DELETE_ACCOUNT   delete_account;
		[case(NETR_DELTA_SECRET)]          netr_DELTA_SECRET          *secret;
		[case(NETR_DELTA_DELETE_SECRET)]   netr_DELTA_DELETE_SECRET    delete_secret;
		[case(NETR_DELTA_DELETE_GROUP2)]   netr_DELTA_DELETE_USER     *delete_group;
		[case(NETR_DELTA_DELETE_USER2)]    netr_DELTA_DELETE_USER     *delete_user;
		[case(NETR_DELTA_MODIFY_COUNT)]    udlong                     *modified_count;
	} netr_DELTA_UNION;

	typedef [switch_type(netr_DeltaEnum)] union {
		[case(NETR_DELTA_DOMAIN)]          uint32 rid;
		[case(NETR_DELTA_GROUP)]           uint32 rid;
		[case(NETR_DELTA_DELETE_GROUP)]    uint32 rid;
		[case(NETR_DELTA_RENAME_GROUP)]    uint32 rid;
		[case(NETR_DELTA_USER)]            uint32 rid;
		[case(NETR_DELTA_DELETE_USER)]     uint32 rid;
		[case(NETR_DELTA_RENAME_USER)]     uint32 rid;
		[case(NETR_DELTA_GROUP_MEMBER)]    uint32 rid;
		[case(NETR_DELTA_ALIAS)]           uint32 rid;
		[case(NETR_DELTA_DELETE_ALIAS)]    uint32 rid;
		[case(NETR_DELTA_RENAME_ALIAS)]    uint32 rid;
		[case(NETR_DELTA_ALIAS_MEMBER)]    uint32 rid;
		[case(NETR_DELTA_POLICY)]          dom_sid2 *sid;
		[case(NETR_DELTA_TRUSTED_DOMAIN)]  dom_sid2 *sid;
		[case(NETR_DELTA_DELETE_TRUST)]    dom_sid2 *sid;
		[case(NETR_DELTA_ACCOUNT)]         dom_sid2 *sid;
		[case(NETR_DELTA_DELETE_ACCOUNT)]  dom_sid2 *sid;
		[case(NETR_DELTA_SECRET)]          [string,charset(UTF16)] uint16 *name;
		[case(NETR_DELTA_DELETE_SECRET)]   [string,charset(UTF16)] uint16 *name;
		[case(NETR_DELTA_DELETE_GROUP2)]   uint32 rid;
		[case(NETR_DELTA_DELETE_USER2)]    uint32 rid;
		[case(NETR_DELTA_MODIFY_COUNT)]    ;
	} netr_DELTA_ID_UNION;

	typedef struct {
		netr_DeltaEnum delta_type;
		[switch_is(delta_type)] netr_DELTA_ID_UNION delta_id_union;
		[switch_is(delta_type)] netr_DELTA_UNION delta_union;
	} netr_DELTA_ENUM;

	typedef struct {
		uint32 num_deltas;
		[size_is(num_deltas)] netr_DELTA_ENUM *delta_enum;
	} netr_DELTA_ENUM_ARRAY;


	NTSTATUS netr_DatabaseDeltas(
		[in]      [string,charset(UTF16)] uint16 logon_server[],
		[in]      [string,charset(UTF16)] uint16 computername[],
		[in]      netr_Authenticator credential,
		[in,out]  netr_Authenticator return_authenticator,
		[in]      netr_SamDatabaseID database_id,
		[in,out]  udlong sequence_num,
		[in]      uint32 preferredmaximumlength,
		[out,unique] netr_DELTA_ENUM_ARRAY *delta_enum_array
		);


	/*****************/
	/* Function 0x08 */

	NTSTATUS netr_DatabaseSync(
		[in]     [string,charset(UTF16)] uint16 logon_server[],
		[in]     [string,charset(UTF16)] uint16 computername[],
		[in]     netr_Authenticator credential,
		[in,out] netr_Authenticator return_authenticator,
		[in]     netr_SamDatabaseID database_id,
		[in,out] uint32 sync_context,
		[in]     uint32 preferredmaximumlength,
		[out,unique] netr_DELTA_ENUM_ARRAY *delta_enum_array
		);


	/*****************/
	/* Function 0x09 */

	/* w2k3 returns NT_STATUS_NOT_IMPLEMENTED for this call */

	typedef [flag(NDR_PAHEX)] struct {
		uint8 computer_name[16];
		uint32 timecreated;
		uint32 serial_number;
	} netr_UAS_INFO_0;

	typedef struct {
		[flag(NDR_REMAINING)] DATA_BLOB blob;
	} netr_AccountBuffer;

	NTSTATUS netr_AccountDeltas(
		[in,unique] [string,charset(UTF16)] uint16 *logon_server,
		[in]     [string,charset(UTF16)] uint16 computername[],
		[in]     netr_Authenticator credential,
		[in,out] netr_Authenticator return_authenticator,
		[in]     netr_UAS_INFO_0 uas,
		[in]     uint32 count,
		[in]     uint32 level,
		[in]     uint32 buffersize,
		[out,subcontext(4)] netr_AccountBuffer buffer,
		[out]    uint32 count_returned,
		[out]    uint32 total_entries,
		[out]    netr_UAS_INFO_0 recordid
		);


	/*****************/
	/* Function 0x0A */

	NTSTATUS netr_AccountSync(
		[in,unique] [string,charset(UTF16)] uint16 *logon_server,
		[in]      [string,charset(UTF16)] uint16 computername[],
		[in]      netr_Authenticator credential,
		[in,out]  netr_Authenticator return_authenticator,
		[in]      uint32 reference,
		[in]      uint32 level,
		[in]      uint32 buffersize,
		[out,subcontext(4)] netr_AccountBuffer buffer,
		[out]     uint32 count_returned,
		[out]     uint32 total_entries,
		[out]     uint32 next_reference,
		[in,out]  netr_UAS_INFO_0 recordid
		);


	/*****************/
	/* Function 0x0B */

	WERROR netr_GetDcName(
		[in]  [string,charset(UTF16)] uint16 logon_server[],
		[in,unique] [string,charset(UTF16)] uint16 *domainname,
		[out,unique] [string,charset(UTF16)] uint16 *dcname
		);

	/*****************/
	/* Function 0x0C */

	typedef [bitmap32bit] bitmap {
		NETLOGON_CTRL_REPL_NEEDED	= 0x0001,
		NETLOGON_CTRL_REPL_IN_PROGRESS	= 0x0002,
		NETLOGON_CTRL_REPL_FULL_SYNC	= 0x0004
	} netr_InfoFlags;

	typedef struct {
		netr_InfoFlags flags;
		uint32 pdc_connection_status;
	} netr_NETLOGON_INFO_1;

	typedef struct {
		netr_InfoFlags flags;
		uint32 pdc_connection_status;
		[string,charset(UTF16)] uint16 trusted_dc_name[];
		uint32 tc_connection_status;
	} netr_NETLOGON_INFO_2;

	typedef struct {
		netr_InfoFlags flags;
		uint32 logon_attempts;
		uint32 unknown1;
		uint32 unknown2;
		uint32 unknown3;
		uint32 unknown4;
		uint32 unknown5;
	} netr_NETLOGON_INFO_3;

	typedef union {
		[case(1)]  netr_NETLOGON_INFO_1 *info1;
		[case(2)]  netr_NETLOGON_INFO_2 *info2;
		[case(3)]  netr_NETLOGON_INFO_3 *info3;
	} netr_CONTROL_QUERY_INFORMATION;

	/* function_code values */
	typedef [v1_enum] enum {
		NETLOGON_CONTROL_SYNC             = 2,
		NETLOGON_CONTROL_REDISCOVER       = 5,
		NETLOGON_CONTROL_TC_QUERY         = 6,
		NETLOGON_CONTROL_TRANSPORT_NOTIFY = 7,
		NETLOGON_CONTROL_SET_DBFLAG       = 65534
	} netr_LogonControlCode;

	WERROR netr_LogonControl(
		[in,unique] [string,charset(UTF16)] uint16 *logon_server,
		[in]   netr_LogonControlCode function_code,
		[in]   uint32 level,
		[out,switch_is(level)]  netr_CONTROL_QUERY_INFORMATION info
		);


	/*****************/
	/* Function 0x0D */

	WERROR netr_GetAnyDCName(
		[in,unique] [string,charset(UTF16)] uint16 *logon_server,
		[in,unique] [string,charset(UTF16)] uint16 *domainname,
		[out,unique] [string,charset(UTF16)] uint16 *dcname
		);


	/*****************/
	/* Function 0x0E */

	typedef union {
		[case(NETLOGON_CONTROL_REDISCOVER)]        [string,charset(UTF16)] uint16 *domain;
		[case(NETLOGON_CONTROL_TC_QUERY)]          [string,charset(UTF16)] uint16 *domain;
		[case(NETLOGON_CONTROL_TRANSPORT_NOTIFY)]  [string,charset(UTF16)] uint16 *domain;
		[case(NETLOGON_CONTROL_SET_DBFLAG)]        uint32 debug_level;
	} netr_CONTROL_DATA_INFORMATION;

	WERROR netr_LogonControl2(
		[in,unique] [string,charset(UTF16)] uint16 *logon_server,
		[in]    netr_LogonControlCode function_code,
		[in]    uint32 level,
		[in][switch_is(function_code)] netr_CONTROL_DATA_INFORMATION  data,
		[out][switch_is(level)]        netr_CONTROL_QUERY_INFORMATION query
		);


	/* If NETLOGON_NEG_ARCFOUR flag is not set, then the passwords and LM
	 * session keys are encrypted with DES calls.  (And the user session key
	 * is unencrypted) */

	/*****************/
	/* Function 0x0F */

	typedef [bitmap32bit] bitmap {
		NETLOGON_NEG_ACCOUNT_LOCKOUT		= 0x00000001,
		NETLOGON_NEG_PERSISTENT_SAMREPL		= 0x00000002,
		NETLOGON_NEG_ARCFOUR			= 0x00000004,
		NETLOGON_NEG_PROMOTION_COUNT		= 0x00000008,
		NETLOGON_NEG_CHANGELOG_BDC		= 0x00000010,
		NETLOGON_NEG_FULL_SYNC_REPL		= 0x00000020,
		NETLOGON_NEG_MULTIPLE_SIDS		= 0x00000040,
		NETLOGON_NEG_REDO			= 0x00000080,
		NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL	= 0x00000100,
		NETLOGON_NEG_SEND_PASSWORD_INFO_PDC	= 0x00000200,