forked from jandubois/win32api-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Net.xs
2254 lines (2034 loc) · 56.8 KB
/
Net.xs
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
#include <windows.h>
#ifndef __CYGWIN__
# include <winsock.h>
#endif
#include <lmcons.h> /* LAN Manager common definitions */
#include <lmerr.h> /* LAN Manager network error definitions */
#include <lmUseFlg.h>
#include <lmAccess.h>
#include <lmAPIBuf.h>
#include <lmwksta.h>
#undef LPTSTR
#define LPTSTR LPWSTR
#include <lmServer.h>
#undef LPTSTR
#ifndef __SDDL_H__
WINADVAPI BOOL WINAPI ConvertSidToStringSidA(PSID, LPSTR*);
#endif
/* old versions of lmaccess.h don't include these Windows 2003 additions */
typedef struct {
LPWSTR usri4_name;
LPWSTR usri4_password;
DWORD usri4_password_age;
DWORD usri4_priv;
LPWSTR usri4_home_dir;
LPWSTR usri4_comment;
DWORD usri4_flags;
LPWSTR usri4_script_path;
DWORD usri4_auth_flags;
LPWSTR usri4_full_name;
LPWSTR usri4_usr_comment;
LPWSTR usri4_parms;
LPWSTR usri4_workstations;
DWORD usri4_last_logon;
DWORD usri4_last_logoff;
DWORD usri4_acct_expires;
DWORD usri4_max_storage;
DWORD usri4_units_per_week;
PBYTE usri4_logon_hours;
DWORD usri4_bad_pw_count;
DWORD usri4_num_logons;
LPWSTR usri4_logon_server;
DWORD usri4_country_code;
DWORD usri4_code_page;
PSID usri4_user_sid;
DWORD usri4_primary_group_id;
LPWSTR usri4_profile;
LPWSTR usri4_home_dir_drive;
DWORD usri4_password_expired;
} MY_USER_INFO_4, *PMY_USER_INFO_4;
typedef struct {
LPWSTR usri23_name;
LPWSTR usri23_full_name;
LPWSTR usri23_comment;
DWORD usri23_flags;
PSID usri23_user_sid;
} MY_USER_INFO_23, *PMY_USER_INFO_23;
typedef struct {
LPWSTR grpi3_name;
LPWSTR grpi3_comment;
PSID grpi3_group_sid;
DWORD grpi3_attributes;
} MY_GROUP_INFO_3, *PMY_GROUP_INFO_3;
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#ifndef _WIN64
# define DWORD_PTR DWORD
#endif
static int
not_here(char *s)
{
croak("%s not implemented on this architecture", s);
return -1;
}
static double
constant(char *name, int arg)
{
errno = 0;
switch (*name) {
case 'A':
break;
case 'B':
break;
case 'C':
break;
case 'D':
break;
case 'E':
break;
case 'F':
if (strEQ(name, "FILTER_TEMP_DUPLICATE_ACCOUNTS"))
#ifdef FILTER_TEMP_DUPLICATE_ACCOUNTS
return FILTER_TEMP_DUPLICATE_ACCOUNTS;
#else
goto not_there;
#endif
if (strEQ(name, "FILTER_NORMAL_ACCOUNT"))
#ifdef FILTER_NORMAL_ACCOUNT
return FILTER_NORMAL_ACCOUNT;
#else
goto not_there;
#endif
if (strEQ(name, "FILTER_INTERDOMAIN_TRUST_ACCOUNT"))
#ifdef FILTER_INTERDOMAIN_TRUST_ACCOUNT
return FILTER_INTERDOMAIN_TRUST_ACCOUNT;
#else
goto not_there;
#endif
if (strEQ(name, "FILTER_WORKSTATION_TRUST_ACCOUNT"))
#ifdef FILTER_WORKSTATION_TRUST_ACCOUNT
return FILTER_WORKSTATION_TRUST_ACCOUNT;
#else
goto not_there;
#endif
if (strEQ(name, "FILTER_SERVER_TRUST_ACCOUNT"))
#ifdef FILTER_SERVER_TRUST_ACCOUNT
return FILTER_SERVER_TRUST_ACCOUNT;
#else
goto not_there;
#endif
break;
case 'G':
if (strEQ(name, "GROUP_ATTRIBUTES_PARMNUM"))
#ifdef GROUP_ATTRIBUTES_PARMNUM
return GROUP_ATTRIBUTES_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "GROUP_COMMENT_PARMNUM"))
#ifdef GROUP_COMMENT_PARMNUM
return GROUP_COMMENT_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "GROUP_NAME_PARMNUM"))
#ifdef GROUP_NAME_PARMNUM
return GROUP_NAME_PARMNUM;
#else
goto not_there;
#endif
break;
case 'H':
break;
case 'I':
break;
case 'J':
break;
case 'K':
break;
case 'L':
if (strEQ(name, "LG_INCLUDE_INDIRECT"))
#ifdef LG_INCLUDE_INDIRECT
return LG_INCLUDE_INDIRECT;
#else
goto not_there;
#endif
if (strEQ(name, "LOCALGROUP_NAME_PARMNUM"))
#ifdef LOCALGROUP_NAME_PARMNUM
return LOCALGROUP_NAME_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "LOCALGROUP_COMMENT_PARMNUM"))
#ifdef LOCALGROUP_COMMENT_PARMNUM
return LOCALGROUP_COMMENT_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "LOGON32_LOGON_BATCH"))
#ifdef LOGON32_LOGON_BATCH
return LOGON32_LOGON_BATCH;
#else
goto not_there;
#endif
if (strEQ(name, "LOGON32_LOGON_INTERACTIVE"))
#ifdef LOGON32_LOGON_INTERACTIVE
return LOGON32_LOGON_INTERACTIVE;
#else
goto not_there;
#endif
break;
case 'M':
break;
case 'N':
break;
case 'O':
break;
case 'P':
break;
case 'Q':
break;
case 'R':
break;
case 'S':
break;
case 'T':
break;
case 'U':
if (strEQ(name, "UF_TEMP_DUPLICATE_ACCOUNT"))
#ifdef UF_TEMP_DUPLICATE_ACCOUNT
return UF_TEMP_DUPLICATE_ACCOUNT;
#else
goto not_there;
#endif
if (strEQ(name, "UF_NORMAL_ACCOUNT"))
#ifdef UF_NORMAL_ACCOUNT
return UF_NORMAL_ACCOUNT;
#else
goto not_there;
#endif
if (strEQ(name, "UF_INTERDOMAIN_TRUST_ACCOUNT"))
#ifdef UF_INTERDOMAIN_TRUST_ACCOUNT
return UF_INTERDOMAIN_TRUST_ACCOUNT;
#else
goto not_there;
#endif
if (strEQ(name, "UF_WORKSTATION_TRUST_ACCOUNT"))
#ifdef UF_WORKSTATION_TRUST_ACCOUNT
return UF_WORKSTATION_TRUST_ACCOUNT;
#else
goto not_there;
#endif
if (strEQ(name, "UF_SERVER_TRUST_ACCOUNT"))
#ifdef UF_SERVER_TRUST_ACCOUNT
return UF_SERVER_TRUST_ACCOUNT;
#else
goto not_there;
#endif
if (strEQ(name, "UF_MACHINE_ACCOUNT_MASK"))
#ifdef UF_MACHINE_ACCOUNT_MASK
return UF_MACHINE_ACCOUNT_MASK;
#else
goto not_there;
#endif
if (strEQ(name, "UF_ACCOUNT_TYPE_MASK"))
#ifdef UF_ACCOUNT_TYPE_MASK
return UF_ACCOUNT_TYPE_MASK;
#else
goto not_there;
#endif
if (strEQ(name, "UF_DONT_EXPIRE_PASSWD"))
#ifdef UF_DONT_EXPIRE_PASSWD
return UF_DONT_EXPIRE_PASSWD;
#else
goto not_there;
#endif
if (strEQ(name, "UF_SETTABLE_BITS"))
#ifdef UF_SETTABLE_BITS
return UF_SETTABLE_BITS;
#else
goto not_there;
#endif
if (strEQ(name, "UF_SCRIPT"))
#ifdef UF_SCRIPT
return UF_SCRIPT;
#else
goto not_there;
#endif
if (strEQ(name, "UF_ACCOUNTDISABLE"))
#ifdef UF_ACCOUNTDISABLE
return UF_ACCOUNTDISABLE;
#else
goto not_there;
#endif
if (strEQ(name, "UF_HOMEDIR_REQUIRED"))
#ifdef UF_HOMEDIR_REQUIRED
return UF_HOMEDIR_REQUIRED;
#else
goto not_there;
#endif
if (strEQ(name, "UF_LOCKOUT"))
#ifdef UF_LOCKOUT
return UF_LOCKOUT;
#else
goto not_there;
#endif
if (strEQ(name, "UF_PASSWD_NOTREQD"))
#ifdef UF_PASSWD_NOTREQD
return UF_PASSWD_NOTREQD;
#else
goto not_there;
#endif
if (strEQ(name, "UF_PASSWD_CANT_CHANGE"))
#ifdef UF_PASSWD_CANT_CHANGE
return UF_PASSWD_CANT_CHANGE;
#else
goto not_there;
#endif
if (strEQ(name, "USE_FORCE"))
#ifdef USE_FORCE
return USE_FORCE;
#else
goto not_there;
#endif
if (strEQ(name, "USE_LOTS_OF_FORCE"))
#ifdef USE_LOTS_OF_FORCE
return USE_LOTS_OF_FORCE;
#else
goto not_there;
#endif
if (strEQ(name, "USE_NOFORCE"))
#ifdef USE_NOFORCE
return USE_NOFORCE;
#else
goto not_there;
#endif
/* PRIV MASKS */
if (strEQ(name, "USER_PRIV_MASK"))
#ifdef USER_PRIV_MASK
return USER_PRIV_MASK;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PRIV_GUEST"))
#ifdef USER_PRIV_GUEST
return USER_PRIV_GUEST;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PRIV_USER"))
#ifdef USER_PRIV_USER
return USER_PRIV_USER;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PRIV_ADMIN"))
#ifdef USER_PRIV_ADMIN
return USER_PRIV_ADMIN;
#else
goto not_there;
#endif
/* USER_XXX_PARMNUM FIELDS */
if (strEQ(name, "USER_NAME_PARMNUM"))
#ifdef USER_NAME_PARMNUM
return USER_NAME_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PASSWORD_PARMNUM"))
#ifdef USER_PASSWORD_PARMNUM
return USER_PASSWORD_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PASSWORD_AGE_PARMNUM"))
#ifdef USER_PASSWORD_AGE_PARMNUM
return USER_PASSWORD_AGE_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PRIV_PARMNUM"))
#ifdef USER_PRIV_PARMNUM
return USER_PRIV_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_HOME_DIR_PARMNUM"))
#ifdef USER_HOME_DIR_PARMNUM
return USER_HOME_DIR_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_COMMENT_PARMNUM"))
#ifdef USER_COMMENT_PARMNUM
return USER_COMMENT_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_FLAGS_PARMNUM"))
#ifdef USER_FLAGS_PARMNUM
return USER_FLAGS_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_SCRIPT_PATH_PARMNUM"))
#ifdef USER_SCRIPT_PATH_PARMNUM
return USER_SCRIPT_PATH_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_AUTH_FLAGS_PARMNUM"))
#ifdef USER_AUTH_FLAGS_PARMNUM
return USER_AUTH_FLAGS_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_FULL_NAME_PARMNUM"))
#ifdef USER_FULL_NAME_PARMNUM
return USER_FULL_NAME_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_USR_COMMENT_PARMNUM"))
#ifdef USER_USR_COMMENT_PARMNUM
return USER_USR_COMMENT_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PARMS_PARMNUM"))
#ifdef USER_PARMS_PARMNUM
return USER_PARMS_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_WORKSTATIONS_PARMNUM"))
#ifdef USER_WORKSTATIONS_PARMNUM
return USER_WORKSTATIONS_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_LAST_LOGON_PARMNUM"))
#ifdef USER_LAST_LOGON_PARMNUM
return USER_LAST_LOGON_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_LAST_LOGOFF_PARMNUM"))
#ifdef USER_LAST_LOGOFF_PARMNUM
return USER_LAST_LOGOFF_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_ACCT_EXPIRES_PARMNUM"))
#ifdef USER_ACCT_EXPIRES_PARMNUM
return USER_ACCT_EXPIRES_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_MAX_STORAGE_PARMNUM"))
#ifdef USER_MAX_STORAGE_PARMNUM
return USER_MAX_STORAGE_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_UNITS_PER_WEEK_PARMNUM"))
#ifdef USER_UNITS_PER_WEEK_PARMNUM
return USER_UNITS_PER_WEEK_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_LOGON_HOURS_PARMNUM"))
#ifdef USER_LOGON_HOURS_PARMNUM
return USER_LOGON_HOURS_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PAD_PW_COUNT_PARMNUM"))
#ifdef USER_PAD_PW_COUNT_PARMNUM
return USER_PAD_PW_COUNT_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_NUM_LOGONS_PARMNUM"))
#ifdef USER_NUM_LOGONS_PARMNUM
return USER_NUM_LOGONS_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_LOGON_SERVER_PARMNUM"))
#ifdef USER_LOGON_SERVER_PARMNUM
return USER_LOGON_SERVER_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_COUNTRY_CODE_PARMNUM"))
#ifdef USER_COUNTRY_CODE_PARMNUM
return USER_COUNTRY_CODE_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_CODE_PAGE_PARMNUM"))
#ifdef USER_CODE_PAGE_PARMNUM
return USER_CODE_PAGE_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PRIMARY_GROUP_PARMNUM"))
#ifdef USER_PRIMARY_GROUP_PARMNUM
return USER_PRIMARY_GROUP_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PROFILE_PARMNUM"))
#ifdef USER_PROFILE_PARMNUM
return USER_PROFILE_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_PROFILE_PARMNUM"))
#ifdef USER_PROFILE_PARMNUM
return USER_PROFILE_PARMNUM;
#else
goto not_there;
#endif
if (strEQ(name, "USER_HOME_DIR_DRIVE_PARMNUM"))
#ifdef USER_HOME_DIR_DRIVE_PARMNUM
return USER_HOME_DIR_DRIVE_PARMNUM;
#else
goto not_there;
#endif
break;
case 'V':
break;
case 'W':
break;
case 'X':
break;
case 'Y':
break;
case 'Z':
break;
}
errno = EINVAL;
return 0;
not_there:
errno = ENOENT;
return 0;
}
#define PREFLEN 0x20000 /* for *Enum() */
/* MultiByte 2 WideChar */
LPWSTR
MBTWC(char* name)
{
int length;
LPWSTR lpPtr = NULL;
if (name) { // && *name != '\0') {
length = (int)strlen(name)+1;
Newz(0, lpPtr, length, WCHAR);
MultiByteToWideChar(CP_ACP, 0, name, -1, lpPtr,
length * sizeof(WCHAR));
}
return lpPtr;
}
/* The following MACROs assume that the following are in scope
* hv - HV*, the hv into/from which information is placed/extracted
* svPtr - temporary SV** for intermediate SV ** values
* uiX - LPBYTE alloc'ed appropriate to CAST
* tmpBuf - char * for temporary string values
*/
#define HV_GET_PV(CAST, field, name) \
STMT_START { \
if ((svPtr = hv_fetch((HV*)hv, name, (I32)strlen(name), 0)) == NULL) \
croak("Required argument not supplied (%s),", name); \
if (SvOK(*svPtr)) \
((CAST)uiX)->field = MBTWC(SvPV_nolen(*svPtr)); \
else /* fields set to "undef" pass NULL to underlying API */ \
((CAST)uiX)->field = (LPWSTR)NULL; \
} STMT_END
#define HV_GET_IV(CAST, field, name) \
STMT_START { \
if ((svPtr = hv_fetch((HV*)hv, name, (I32)strlen(name), 0)) == NULL) \
croak("Required argument not supplied (%s),", name); \
if (!SvIOK(*svPtr)) \
croak("Bad data for %s, ", name); \
((CAST)uiX)->field = (DWORD)SvIV(*svPtr); \
} STMT_END
#define HV_GET_AV(CAST, field, name, n) \
STMT_START { \
int i = 0; \
SV **svTmp, *svPtrIndirect; \
Newz(0, ((CAST)uiX)->field, n, BYTE); \
if ((svPtr = hv_fetch((HV*)hv, name, (I32)strlen(name), 0)) == NULL) \
croak("Required argument not supplied (%s), ", name); \
if (!(SvROK(*svPtr) && (svPtrIndirect = SvRV(*svPtr)) \
&& SvTYPE(svPtrIndirect) == SVt_PVAV)) \
croak("Value in logonHours should be an array reference,"); \
while (i < n) { \
if ((svTmp = av_fetch((AV*)svPtrIndirect, i, 0)) != NULL) \
(((CAST)uiX)->field)[i] = (BYTE)SvIV(*svTmp); \
else \
(((CAST)uiX)->field)[i] = 0; \
i++; \
} \
} STMT_END
#define uiX_INIT(t) \
STMT_START { \
if (!uiX) { \
Newc(0,uiX,1,t,LPBYTE); \
memzero((char*)uiX,sizeof(t)); \
} \
} STMT_END
LPBYTE *
allocUserInfoX(int level, HV *hv)
{
LPBYTE *uiX = NULL;
SV **svPtr;
dTHX;
switch (level) {
case 3:
uiX_INIT(USER_INFO_3);
HV_GET_IV(PUSER_INFO_3, usri3_password_expired, "passwordExpired");
HV_GET_PV(PUSER_INFO_3, usri3_home_dir_drive, "homeDirDrive");
HV_GET_PV(PUSER_INFO_3, usri3_profile, "profile");
HV_GET_IV(PUSER_INFO_3, usri3_primary_group_id, "primaryGroupId");
HV_GET_IV(PUSER_INFO_3, usri3_user_id, "userId");
/* fall through to 2... */
case 2:
uiX_INIT(USER_INFO_2);
HV_GET_IV(PUSER_INFO_2, usri2_code_page, "codePage");
HV_GET_IV(PUSER_INFO_2, usri2_country_code, "countryCode");
HV_GET_PV(PUSER_INFO_2, usri2_logon_server, "logonServer");
HV_GET_IV(PUSER_INFO_2, usri2_num_logons, "numLogons");
HV_GET_IV(PUSER_INFO_2, usri2_bad_pw_count, "badPwCount");
HV_GET_AV(PUSER_INFO_2, usri2_logon_hours, "logonHours", 21);
HV_GET_IV(PUSER_INFO_2, usri2_units_per_week, "unitsPerWeek");
HV_GET_IV(PUSER_INFO_2, usri2_max_storage, "maxStorage");
HV_GET_IV(PUSER_INFO_2, usri2_acct_expires, "acctExpires");
HV_GET_IV(PUSER_INFO_2, usri2_last_logoff, "lastLogoff");
HV_GET_IV(PUSER_INFO_2, usri2_last_logon, "lastLogon");
HV_GET_PV(PUSER_INFO_2, usri2_workstations, "workstations");
HV_GET_PV(PUSER_INFO_2, usri2_parms, "parms");
HV_GET_PV(PUSER_INFO_2, usri2_usr_comment, "usrComment");
HV_GET_PV(PUSER_INFO_2, usri2_full_name, "fullName");
HV_GET_IV(PUSER_INFO_2, usri2_auth_flags, "authFlags");
/* fall through to 1... */
case 1:
uiX_INIT(USER_INFO_1);
HV_GET_PV(PUSER_INFO_1, usri1_script_path, "scriptPath");
HV_GET_IV(PUSER_INFO_1, usri1_flags, "flags");
HV_GET_PV(PUSER_INFO_1, usri1_comment, "comment");
HV_GET_PV(PUSER_INFO_1, usri1_home_dir, "homeDir");
HV_GET_IV(PUSER_INFO_1, usri1_priv, "priv");
HV_GET_IV(PUSER_INFO_1, usri1_password_age, "passwordAge");
HV_GET_PV(PUSER_INFO_1, usri1_password, "password");
/* fall through to 0... */
case 0:
uiX_INIT(USER_INFO_0);
HV_GET_PV(PUSER_INFO_0, usri0_name, "name");
break;
case 11:
uiX_INIT(USER_INFO_11);
HV_GET_IV(PUSER_INFO_11, usri11_code_page, "codePage");
HV_GET_AV(PUSER_INFO_11, usri11_logon_hours, "logonHours", 21);
HV_GET_IV(PUSER_INFO_11, usri11_units_per_week, "unitsPerWeek");
HV_GET_IV(PUSER_INFO_11, usri11_max_storage, "maxStorage");
HV_GET_PV(PUSER_INFO_11, usri11_workstations, "workstations");
HV_GET_IV(PUSER_INFO_11, usri11_country_code, "countryCode");
HV_GET_PV(PUSER_INFO_11, usri11_logon_server, "logonServer");
HV_GET_IV(PUSER_INFO_11, usri11_num_logons, "numLogons");
HV_GET_IV(PUSER_INFO_11, usri11_bad_pw_count, "badPwCount");
HV_GET_IV(PUSER_INFO_11, usri11_last_logoff, "lastLogoff");
HV_GET_IV(PUSER_INFO_11, usri11_last_logon, "lastLogon");
HV_GET_PV(PUSER_INFO_11, usri11_parms, "parms");
HV_GET_PV(PUSER_INFO_11, usri11_home_dir, "homeDir");
HV_GET_IV(PUSER_INFO_11, usri11_password_age, "passwordAge");
HV_GET_IV(PUSER_INFO_11, usri11_auth_flags, "authFlags");
HV_GET_IV(PUSER_INFO_11, usri11_priv, "priv");
/* fall through to 10... */
case 10:
uiX_INIT(USER_INFO_10);
HV_GET_PV(PUSER_INFO_10, usri10_full_name, "fullName");
HV_GET_PV(PUSER_INFO_10, usri10_usr_comment, "usrComment");
HV_GET_PV(PUSER_INFO_10, usri10_comment, "comment");
HV_GET_PV(PUSER_INFO_10, usri10_name, "name");
break;
case 20:
uiX_INIT(USER_INFO_20);
HV_GET_IV(PUSER_INFO_20, usri20_user_id, "userId");
HV_GET_IV(PUSER_INFO_20, usri20_flags, "flags");
HV_GET_PV(PUSER_INFO_20, usri20_comment, "comment");
HV_GET_PV(PUSER_INFO_20, usri20_full_name, "fullName");
HV_GET_PV(PUSER_INFO_20, usri20_name, "name");
break;
case 21:
case 22:
croak("level %d not yet implemented for User*() functions\n");
case 1003:
/* need to put a value in (can't rely on Get) */
uiX_INIT(USER_INFO_1003);
HV_GET_PV(PUSER_INFO_1003, usri1003_password, "password");
break;
case 1005:
uiX_INIT(USER_INFO_1005);
HV_GET_IV(PUSER_INFO_1005, usri1005_priv, "priv");
break;
case 1006:
uiX_INIT(USER_INFO_1006);
HV_GET_PV(PUSER_INFO_1006, usri1006_home_dir, "homeDir");
break;
case 1007:
uiX_INIT(USER_INFO_1007);
HV_GET_PV(PUSER_INFO_1007, usri1007_comment, "comment");
break;
case 1008:
uiX_INIT(USER_INFO_1008);
HV_GET_IV(PUSER_INFO_1008, usri1008_flags, "flags");
break;
case 1009:
uiX_INIT(USER_INFO_1009);
HV_GET_PV(PUSER_INFO_1009, usri1009_script_path, "scriptPath");
break;
case 1010:
uiX_INIT(USER_INFO_1010);
HV_GET_IV(PUSER_INFO_1010, usri1010_auth_flags, "authFlags");
break;
case 1011:
uiX_INIT(USER_INFO_1011);
HV_GET_PV(PUSER_INFO_1011, usri1011_full_name, "fullName");
break;
case 1012:
uiX_INIT(USER_INFO_1012);
HV_GET_PV(PUSER_INFO_1012, usri1012_usr_comment, "usrComment");
break;
case 1013:
uiX_INIT(USER_INFO_1013);
HV_GET_PV(PUSER_INFO_1013, usri1013_parms, "parms");
break;
case 1014:
uiX_INIT(USER_INFO_1014);
HV_GET_PV(PUSER_INFO_1014, usri1014_workstations, "workstations");
break;
case 1017:
uiX_INIT(USER_INFO_1017);
HV_GET_IV(PUSER_INFO_1017, usri1017_acct_expires, "acctExpires");
break;
case 1018:
uiX_INIT(USER_INFO_1018);
HV_GET_IV(PUSER_INFO_1018, usri1018_max_storage, "maxStorage");
break;
case 1020:
uiX_INIT(USER_INFO_1020);
HV_GET_IV(PUSER_INFO_1020, usri1020_units_per_week, "unitsPerWeek");
HV_GET_AV(PUSER_INFO_1020, usri1020_logon_hours, "logonHours", 21);
break;
case 1023:
uiX_INIT(USER_INFO_1023);
HV_GET_PV(PUSER_INFO_1023, usri1023_logon_server, "logonServer");
break;
case 1024:
uiX_INIT(USER_INFO_1024);
HV_GET_IV(PUSER_INFO_1024, usri1024_country_code, "countryCode");
break;
case 1025:
uiX_INIT(USER_INFO_1025);
HV_GET_IV(PUSER_INFO_1025, usri1025_code_page, "codePage");
break;
case 1051:
uiX_INIT(USER_INFO_1051);
HV_GET_IV(PUSER_INFO_1051, usri1051_primary_group_id, "primaryGroupId");
break;
case 1052:
uiX_INIT(USER_INFO_1052);
HV_GET_PV(PUSER_INFO_1052, usri1052_profile, "profile");
break;
case 1053:
uiX_INIT(USER_INFO_1053);
HV_GET_PV(PUSER_INFO_1053, usri1053_home_dir_drive, "homeDirDrive");
break;
default:
croak("Level %d is not a valid level for NetUser functions\n", level);
break;
}
return uiX;
}
void
freeWideName(LPWSTR lpPtr)
{
Safefree(lpPtr);
}
#define WCFREE(CAST, field) freeWideName(((CAST)uiX)->field)
#define PBFREE(CAST, field) Safefree(((CAST)uiX)->field)
void
freeUserInfoX(LPBYTE *uiX, int level)
{
dTHX;
switch (level) {
case 3:
WCFREE(PUSER_INFO_3, usri3_home_dir_drive);
WCFREE(PUSER_INFO_3, usri3_profile);
/* fall through to 2... */
case 2:
WCFREE(PUSER_INFO_2, usri2_logon_server);
PBFREE(PUSER_INFO_2, usri2_logon_hours);
WCFREE(PUSER_INFO_2, usri2_workstations);
WCFREE(PUSER_INFO_2, usri2_parms);
WCFREE(PUSER_INFO_2, usri2_usr_comment);
WCFREE(PUSER_INFO_2, usri2_full_name);
/* fall through to 1... */
case 1:
WCFREE(PUSER_INFO_1, usri1_script_path);
WCFREE(PUSER_INFO_1, usri1_comment);
WCFREE(PUSER_INFO_1, usri1_home_dir);
WCFREE(PUSER_INFO_1, usri1_password);
case 0:
WCFREE(PUSER_INFO_0, usri0_name);
break;
case 11:
PBFREE(PUSER_INFO_11, usri11_logon_hours);
WCFREE(PUSER_INFO_11, usri11_workstations);
WCFREE(PUSER_INFO_11, usri11_logon_server);
WCFREE(PUSER_INFO_11, usri11_parms);
WCFREE(PUSER_INFO_11, usri11_home_dir);
/* fall through to 10... */
case 10:
WCFREE(PUSER_INFO_10, usri10_full_name);
WCFREE(PUSER_INFO_10, usri10_usr_comment);
WCFREE(PUSER_INFO_10, usri10_comment);
WCFREE(PUSER_INFO_10, usri10_name);
break;
case 20:
WCFREE(PUSER_INFO_20, usri20_comment);
WCFREE(PUSER_INFO_20, usri20_full_name);
WCFREE(PUSER_INFO_20, usri20_name);
break;
case 1003:
/* need to put a value in (can't rely on Get) */
WCFREE(PUSER_INFO_1003, usri1003_password);
break;
case 1005:
break;
case 1006:
WCFREE(PUSER_INFO_1006, usri1006_home_dir);
break;
case 1007:
WCFREE(PUSER_INFO_1007, usri1007_comment);
case 1008:
break;
case 1009:
WCFREE(PUSER_INFO_1009, usri1009_script_path);
break;
case 1010:
break;
case 1011:
WCFREE(PUSER_INFO_1011, usri1011_full_name);
break;
case 1012:
WCFREE(PUSER_INFO_1012, usri1012_usr_comment);
break;
case 1013:
WCFREE(PUSER_INFO_1013, usri1013_parms);
break;
case 1014:
WCFREE(PUSER_INFO_1014, usri1014_workstations);
break;
case 1017:
break;
case 1018:
break;
case 1020:
PBFREE(PUSER_INFO_1020, usri1020_logon_hours);
break;
case 1023:
WCFREE(PUSER_INFO_1023, usri1023_logon_server);
break;
case 1024:
break;
case 1025:
break;
case 1051:
break;
case 1052:
WCFREE(PUSER_INFO_1052, usri1052_profile);
break;
case 1053:
WCFREE(PUSER_INFO_1053, usri1053_home_dir_drive);
break;
case 21:
default:
croak("unhandled level in free CODE\n");
}
}
LPBYTE *
allocGroupInfoX(int level, HV *hv)
{
LPBYTE *uiX = NULL;
SV **svPtr;
dTHX;
switch (level) {
case 2:
uiX_INIT(GROUP_INFO_2);
HV_GET_IV(PGROUP_INFO_2, grpi2_attributes, "attributes");
HV_GET_IV(PGROUP_INFO_2, grpi2_group_id, "group_id");
/* fall through to 1 */
case 1:
uiX_INIT(GROUP_INFO_1);
HV_GET_PV(PGROUP_INFO_1, grpi1_comment, "comment");
/* fall through to 0 */
case 0:
uiX_INIT(GROUP_INFO_0);
HV_GET_PV(PGROUP_INFO_0, grpi0_name, "name");
break;
case 1002:
uiX_INIT(GROUP_INFO_1002);
HV_GET_PV(PGROUP_INFO_1002, grpi1002_comment, "comment");
break;
case 1005:
uiX_INIT(GROUP_INFO_1005);
HV_GET_IV(PGROUP_INFO_1005, grpi1005_attributes, "attributes");
break;
default:
break;
}
return uiX;
}
void
freeGroupInfoX(int level, LPBYTE *uiX)
{
switch (level) {
case 2:
/* fall through to 1 */
case 1:
WCFREE(PGROUP_INFO_1, grpi1_comment);
/* fall through to 0 */
case 0:
WCFREE(PGROUP_INFO_0, grpi0_name);
break;
case 1002:
WCFREE(PGROUP_INFO_1002, grpi1002_comment);
break;
case 1005:
break;
default:
break;
}
}
int
WCTMB(LPWSTR lpwStr, LPSTR lpStr, int size)
{
*lpStr = '\0';
return WideCharToMultiByte(CP_ACP, 0, lpwStr, -1, lpStr, size,
NULL, NULL);
}
/* The following MACROs assume that the following are in scope
* hv - HV*, the hashRef into/from which information is placed/extracted
* sv - temporary SV* for intermediate SV * values
* uiX - LPBYTE alloc'ed appropriate to CAST
* tmpBuf - char * for temporary string values
*/
#define HV_STORE_PV(CAST, field, name) \
STMT_START { \
WCTMB(((CAST)uiX)->field, tmpBuf, sizeof(tmpBuf)); \
sv = newSVpv(tmpBuf, (I32)strlen(tmpBuf)); \
hv_store((HV*)hv, name, (I32)strlen(name), sv, 0); \
} STMT_END
#define HV_STORE_IV(CAST, field, name) \
STMT_START { \
sv = newSViv(((CAST)uiX)->field); \
hv_store((HV*)hv, name, (I32)strlen(name), sv, 0); \
} STMT_END
#define HV_STORE_AV(CAST, field, name, n) \
STMT_START { \
int i = 0; \
AV *av; \
av = newAV(); \
while (i < n) { \
sv = newSViv((BYTE)(((CAST)uiX)->field)[i++]); \
av_push(av, sv); \
} \
hv_store((HV*)hv, name, (I32)strlen(name), newRV_noinc((SV*)av), 0); \
} STMT_END
void
fillUserHash(HV *hv, int level, LPBYTE *uiX)
{
SV *sv;
char tmpBuf[UNLEN+1];
dTHX;
switch (level) {
case 3:
case 4:
if( 3 == level )
{