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
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
|
/*
* 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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Net DFS server side RPC service for managing DFS namespaces.
*
* For more details refer to following Microsoft specification:
* [MS-DFSNM]
* Distributed File System (DFS): Namespace Management Protocol Specification
*/
#include <unistd.h>
#include <libgen.h>
#include <strings.h>
#include <sys/sysmacros.h>
#include <smbsrv/libmlsvc.h>
#include <smbsrv/nmpipes.h>
#include <smbsrv/ndl/netdfs.ndl>
#include <dfs.h>
/*
* Depends on the information level requested around 4000 or more links
* can be provided with this buffer size. The limitation here is due
* to some problem in NDR and/or opipe layer so:
*
* - Do NOT increase the buffer size until that problem is fixed
* - The buffer size should be increased when the problem is fixed
* so the 4000 link limitation is removed.
*/
#define NETDFS_MAXBUFLEN (800 * 1024)
#define NETDFS_MAXPREFLEN ((uint32_t)(-1))
typedef struct netdfs_enumhandle_t {
uint32_t de_level; /* level of detail being requested */
uint32_t de_prefmaxlen; /* client MAX size buffer preference */
uint32_t de_resume; /* client resume handle */
uint32_t de_bavail; /* remaining buffer space in bytes */
uint32_t de_ntotal; /* total number of objects */
uint32_t de_nmax; /* MAX number of objects to return */
uint32_t de_nitems; /* number of objects in buf */
uint32_t de_nskip; /* number of objects to skip */
void *de_entries; /* ndr buffer */
} netdfs_enumhandle_t;
static int netdfs_s_getver(void *, ndr_xa_t *);
static int netdfs_s_add(void *, ndr_xa_t *);
static int netdfs_s_remove(void *, ndr_xa_t *);
static int netdfs_s_setinfo(void *, ndr_xa_t *);
static int netdfs_s_getinfo(void *, ndr_xa_t *);
static int netdfs_s_enum(void *, ndr_xa_t *);
static int netdfs_s_move(void *, ndr_xa_t *);
static int netdfs_s_rename(void *, ndr_xa_t *);
static int netdfs_s_addstdroot(void *, ndr_xa_t *);
static int netdfs_s_remstdroot(void *, ndr_xa_t *);
static int netdfs_s_enumex(void *, ndr_xa_t *);
static uint32_t netdfs_setinfo_100(dfs_path_t *, netdfs_info100_t *);
static uint32_t netdfs_setinfo_101(dfs_path_t *, netdfs_info101_t *,
const char *, const char *);
static uint32_t netdfs_setinfo_102(dfs_path_t *, netdfs_info102_t *);
static uint32_t netdfs_setinfo_103(dfs_path_t *, netdfs_info103_t *);
static uint32_t netdfs_setinfo_104(dfs_path_t *, netdfs_info104_t *,
const char *, const char *);
static uint32_t netdfs_setinfo_105(dfs_path_t *, netdfs_info105_t *);
static uint32_t netdfs_info_1(netdfs_info1_t *, dfs_info_t *, ndr_xa_t *,
uint32_t *);
static uint32_t netdfs_info_2(netdfs_info2_t *, dfs_info_t *, ndr_xa_t *,
uint32_t *);
static uint32_t netdfs_info_3(netdfs_info3_t *, dfs_info_t *, ndr_xa_t *,
uint32_t *);
static uint32_t netdfs_info_4(netdfs_info4_t *, dfs_info_t *, ndr_xa_t *,
uint32_t *);
static uint32_t netdfs_info_5(netdfs_info5_t *, dfs_info_t *, ndr_xa_t *,
uint32_t *);
static uint32_t netdfs_info_6(netdfs_info6_t *, dfs_info_t *, ndr_xa_t *,
uint32_t *);
static uint32_t netdfs_info_100(netdfs_info100_t *, dfs_info_t *, ndr_xa_t *,
uint32_t *);
static uint32_t netdfs_info_300(netdfs_info300_t *, dfs_info_t *, ndr_xa_t *,
uint32_t *);
static uint32_t netdfs_enum_common(netdfs_enumhandle_t *, ndr_xa_t *);
static void netdfs_path_create(const char *);
static void netdfs_path_remove(smb_unc_t *);
static boolean_t netdfs_guid_fromstr(char *, netdfs_uuid_t *);
static ndr_stub_table_t netdfs_stub_table[] = {
{ netdfs_s_getver, NETDFS_OPNUM_GETVER },
{ netdfs_s_add, NETDFS_OPNUM_ADD },
{ netdfs_s_remove, NETDFS_OPNUM_REMOVE },
{ netdfs_s_setinfo, NETDFS_OPNUM_SETINFO },
{ netdfs_s_getinfo, NETDFS_OPNUM_GETINFO },
{ netdfs_s_enum, NETDFS_OPNUM_ENUM },
{ netdfs_s_rename, NETDFS_OPNUM_RENAME },
{ netdfs_s_move, NETDFS_OPNUM_MOVE },
{ netdfs_s_addstdroot, NETDFS_OPNUM_ADDSTDROOT },
{ netdfs_s_remstdroot, NETDFS_OPNUM_REMSTDROOT },
{ netdfs_s_enumex, NETDFS_OPNUM_ENUMEX },
{0}
};
static ndr_service_t netdfs_service = {
"NETDFS", /* name */
"DFS", /* desc */
"\\netdfs", /* endpoint */
PIPE_NETDFS, /* sec_addr_port */
NETDFS_ABSTRACT_UUID, NETDFS_ABSTRACT_VERS,
NETDFS_TRANSFER_UUID, NETDFS_TRANSFER_VERS,
0, /* no bind_instance_size */
0, /* no bind_req() */
0, /* no unbind_and_close() */
0, /* use generic_call_stub() */
&TYPEINFO(netdfs_interface), /* interface ti */
netdfs_stub_table /* stub_table */
};
/*
* Register the NETDFS RPC interface with the RPC runtime library.
* The service must be registered in order to use either the client
* side or the server side functions.
*/
void
netdfs_initialize(void)
{
(void) ndr_svc_register(&netdfs_service);
dfs_init();
}
void
netdfs_finalize(void)
{
dfs_fini();
}
/*
* Returns the version number of the DFS server in use on the server.
*
* [MS-DFSNM]: NetrDfsManagerGetVersion (Opnum 0)
*/
/*ARGSUSED*/
static int
netdfs_s_getver(void *arg, ndr_xa_t *mxa)
{
struct netdfs_getver *param = arg;
param->version = DFS_MANAGER_VERSION_NT4;
return (NDR_DRC_OK);
}
/*
* Creates a new DFS link or adds a new target to an existing link of a
* DFS namespace.
*
* [MS-DFSNM]: NetrDfsAdd (Opnum 1)
*/
static int
netdfs_s_add(void *arg, ndr_xa_t *mxa)
{
netdfs_add_t *param = arg;
dfs_path_t path;
uint32_t status;
const char *uncpath = (const char *)param->dfs_path;
const char *fspath = (const char *)path.p_fspath;
boolean_t newlink;
if (!ndr_is_admin(mxa)) {
param->status = ERROR_ACCESS_DENIED;
return (NDR_DRC_OK);
}
if (param->server == NULL || param->share == NULL) {
param->status = ERROR_INVALID_PARAMETER;
return (NDR_DRC_OK);
}
switch (param->flags) {
case DFS_CREATE_VOLUME:
case DFS_ADD_VOLUME:
case DFS_RESTORE_VOLUME:
case (DFS_ADD_VOLUME | DFS_RESTORE_VOLUME):
break;
default:
param->status = ERROR_INVALID_PARAMETER;
return (NDR_DRC_OK);
}
status = dfs_path_parse(&path, uncpath, DFS_OBJECT_LINK);
if (status != ERROR_SUCCESS) {
param->status = status;
return (NDR_DRC_OK);
}
status = smb_name_validate_rpath(path.p_unc.unc_path);
if (status != ERROR_SUCCESS) {
dfs_path_free(&path);
param->status = status;
return (NDR_DRC_OK);
}
dfs_setpriv(PRIV_ON);
netdfs_path_create(fspath);
status = dfs_link_add(fspath, (const char *)param->server,
(const char *)param->share, (const char *)param->comment,
param->flags, &newlink);
if (newlink)
(void) dfs_cache_add_byname(path.p_unc.unc_share,
path.p_unc.unc_path, DFS_OBJECT_LINK);
if (status != ERROR_SUCCESS)
netdfs_path_remove(&path.p_unc);
dfs_setpriv(PRIV_OFF);
dfs_path_free(&path);
param->status = status;
return (NDR_DRC_OK);
}
/*
* Removes a link or a link target from a DFS namespace. A link can be
* removed regardless of the number of targets associated with it.
*
* [MS-DFSNM]: NetrDfsRemove (Opnum 2)
*/
static int
netdfs_s_remove(void *arg, ndr_xa_t *mxa)
{
struct netdfs_remove *param = arg;
dfs_path_t path;
uint32_t status, stat;
const char *uncpath = (const char *)param->dfs_path;
const char *fspath = (const char *)path.p_fspath;
if (!ndr_is_admin(mxa)) {
param->status = ERROR_ACCESS_DENIED;
return (NDR_DRC_OK);
}
/* both server and share must be NULL or non-NULL */
if ((param->server == NULL && param->share != NULL) ||
(param->server != NULL && param->share == NULL)) {
param->status = ERROR_INVALID_PARAMETER;
return (NDR_DRC_OK);
}
status = dfs_path_parse(&path, uncpath, DFS_OBJECT_LINK);
if (status != ERROR_SUCCESS) {
param->status = status;
return (NDR_DRC_OK);
}
dfs_setpriv(PRIV_ON);
status = dfs_link_remove(fspath, (const char *)param->server,
(const char *)param->share);
if (status == ERROR_SUCCESS) {
if (dfs_link_stat(fspath, &stat) == ERROR_SUCCESS) {
if (stat != DFS_STAT_ISDFS)
dfs_cache_remove(path.p_unc.unc_share,
path.p_unc.unc_path);
/*
* if link is removed then try to remove its
* empty parent directories if any
*/
if (stat == DFS_STAT_NOTFOUND)
netdfs_path_remove(&path.p_unc);
}
}
dfs_setpriv(PRIV_OFF);
dfs_path_free(&path);
param->status = status;
return (NDR_DRC_OK);
}
/*
* Sets or modifies information relevant to a specific DFS root, DFS root
* target, DFS link, or DFS link target
*
* [MS-DFSNM]: NetrDfsSetInfo (Opnum 3)
*/
/*ARGSUSED*/
static int
netdfs_s_setinfo(void *arg, ndr_xa_t *mxa)
{
netdfs_setinfo_t *param = arg;
dfs_path_t path;
uint32_t status, stat;
/* both server and share must be NULL or non-NULL */
if ((param->server == NULL && param->share != NULL) ||
(param->server != NULL && param->share == NULL)) {
param->status = ERROR_INVALID_PARAMETER;
return (NDR_DRC_OK);
}
status = dfs_path_parse(&path, (const char *)param->dfs_path,
DFS_OBJECT_ANY);
if (status != ERROR_SUCCESS) {
param->status = status;
return (NDR_DRC_OK);
}
dfs_setpriv(PRIV_ON);
status = dfs_link_stat((const char *)path.p_fspath, &stat);
if ((path.p_type == DFS_OBJECT_LINK) && (stat != DFS_STAT_ISDFS)) {
dfs_setpriv(PRIV_OFF);
dfs_path_free(&path);
param->status = ERROR_NOT_FOUND;
return (NDR_DRC_OK);
}
switch (param->info.level) {
case 100:
status = netdfs_setinfo_100(&path, param->info.iu.info100);
break;
case 101:
status = netdfs_setinfo_101(&path, param->info.iu.info101,
(const char *)param->server, (const char *)param->share);
break;
case 102:
status = netdfs_setinfo_102(&path, param->info.iu.info102);
break;
case 103:
status = netdfs_setinfo_103(&path, param->info.iu.info103);
break;
case 104:
status = netdfs_setinfo_104(&path, param->info.iu.info104,
(const char *)param->server, (const char *)param->share);
break;
case 105:
status = netdfs_setinfo_105(&path, param->info.iu.info105);
break;
default:
status = ERROR_INVALID_LEVEL;
break;
}
dfs_setpriv(PRIV_OFF);
dfs_path_free(&path);
param->status = status;
return (NDR_DRC_OK);
}
/*
* Returns information about a DFS root or a DFS link of the specified
* DFS namespace.
*
* [MS-DFSNM]: NetrDfsGetInfo (Opnum 4)
*/
static int
netdfs_s_getinfo(void *arg, ndr_xa_t *mxa)
{
netdfs_getinfo_t *param = arg;
netdfs_info1_t *info1;
netdfs_info2_t *info2;
netdfs_info3_t *info3;
netdfs_info4_t *info4;
netdfs_info5_t *info5;
netdfs_info6_t *info6;
netdfs_info100_t *info100;
dfs_info_t info;
dfs_path_t path;
uint32_t status, stat;
const char *fspath;
uint32_t level = param->level;
status = dfs_path_parse(&path, (const char *)param->dfs_path,
DFS_OBJECT_ANY);
if (status != ERROR_SUCCESS)
goto getinfo_error;
dfs_setpriv(PRIV_ON);
fspath = path.p_fspath;
if (path.p_type == DFS_OBJECT_LINK) {
status = dfs_link_stat(fspath, &stat);
if ((status != ERROR_SUCCESS) || (stat != DFS_STAT_ISDFS)) {
status = ERROR_NOT_FOUND;
goto getinfo_error;
}
status = dfs_link_getinfo(fspath, &info, param->level);
} else {
status = dfs_root_getinfo(fspath, &info, param->level);
}
if (status != ERROR_SUCCESS)
goto getinfo_error;
(void) strlcpy(info.i_uncpath, (char *)param->dfs_path,
sizeof (info.i_uncpath));
dfs_info_trace("netdfs_s_getinfo", &info);
status = ERROR_NOT_ENOUGH_MEMORY;
switch (level) {
case 1:
if ((info1 = NDR_NEW(mxa, netdfs_info1_t)) != NULL) {
param->info.iu.info1 = info1;
status = netdfs_info_1(info1, &info, mxa, NULL);
}
break;
case 2:
if ((info2 = NDR_NEW(mxa, netdfs_info2_t)) != NULL) {
param->info.iu.info2 = info2;
status = netdfs_info_2(info2, &info, mxa, NULL);
}
break;
case 3:
if ((info3 = NDR_NEW(mxa, netdfs_info3_t)) != NULL) {
param->info.iu.info3 = info3;
status = netdfs_info_3(info3, &info, mxa, NULL);
}
break;
case 4:
if ((info4 = NDR_NEW(mxa, netdfs_info4_t)) != NULL) {
param->info.iu.info4 = info4;
status = netdfs_info_4(info4, &info, mxa, NULL);
}
break;
case 5:
if ((info5 = NDR_NEW(mxa, netdfs_info5_t)) != NULL) {
param->info.iu.info5 = info5;
status = netdfs_info_5(info5, &info, mxa, NULL);
}
break;
case 6:
if ((info6 = NDR_NEW(mxa, netdfs_info6_t)) != NULL) {
param->info.iu.info6 = info6;
status = netdfs_info_6(info6, &info, mxa, NULL);
}
break;
case 100:
if ((info100 = NDR_NEW(mxa, netdfs_info100_t)) != NULL) {
param->info.iu.info100 = info100;
status = netdfs_info_100(info100, &info, mxa, NULL);
}
break;
default:
status = ERROR_INVALID_LEVEL;
break;
}
dfs_info_free(&info);
getinfo_error:
dfs_setpriv(PRIV_OFF);
dfs_path_free(&path);
if (status != ERROR_SUCCESS)
bzero(param, sizeof (netdfs_getinfo_t));
param->info.level = level;
param->status = status;
return (NDR_DRC_OK);
}
/*
* Enumerates the DFS root hosted on a server or the DFS links of the
* namespace hosted by a server. Depending on the information level,
* the targets of the root and links are also displayed.
*
* For unsupported levels, it should return ERROR_INVALID_LEVEL as
* Microsoft does for DFS server on Win2000 and NT.
*
* [MS-DFSNM]: NetrDfsEnum (Opnum 5)
*/
/*ARGSUSED*/
static int
netdfs_s_enum(void *arg, ndr_xa_t *mxa)
{
netdfs_enum_t *param = arg;
netdfs_enumhandle_t de;
uint32_t level = param->level;
uint32_t status = ERROR_SUCCESS;
uint32_t nroot;
size_t entsize;
if (param->info == NULL) {
status = ERROR_INVALID_PARAMETER;
goto enum_error;
}
if ((nroot = dfs_namespace_count()) == 0)
status = ERROR_NOT_FOUND;
else if (nroot > 1)
status = ERROR_DEVICE_NOT_AVAILABLE;
if (status != ERROR_SUCCESS)
goto enum_error;
bzero(&de, sizeof (netdfs_enumhandle_t));
de.de_level = level;
de.de_ntotal = dfs_cache_num();
if (param->pref_max_len == NETDFS_MAXPREFLEN ||
param->pref_max_len > NETDFS_MAXBUFLEN)
de.de_prefmaxlen = NETDFS_MAXBUFLEN;
else
de.de_prefmaxlen = param->pref_max_len;
de.de_bavail = de.de_prefmaxlen;
if (param->resume_handle != NULL) {
if (*param->resume_handle >= de.de_ntotal) {
status = ERROR_NO_MORE_ITEMS;
goto enum_error;
}
de.de_resume = *param->resume_handle;
de.de_nskip = de.de_resume;
*param->resume_handle = 0;
}
dfs_setpriv(PRIV_ON);
status = ERROR_NOT_ENOUGH_MEMORY;
switch (level) {
case 1:
entsize = sizeof (netdfs_info1_t);
de.de_nmax = MAX((de.de_prefmaxlen / entsize), 1);
de.de_entries = NDR_NEWN(mxa, netdfs_info1_t, de.de_nmax);
if (de.de_entries == NULL)
goto enum_error;
if ((status = netdfs_enum_common(&de, mxa)) == ERROR_SUCCESS) {
param->info->iu.info1->info1 = de.de_entries;
param->info->iu.info1->count = de.de_nitems;
}
break;
case 2:
entsize = sizeof (netdfs_info2_t);
de.de_nmax = MAX((de.de_prefmaxlen / entsize), 1);
de.de_entries = NDR_NEWN(mxa, netdfs_info2_t, de.de_nmax);
if (de.de_entries == NULL)
goto enum_error;
if ((status = netdfs_enum_common(&de, mxa)) == ERROR_SUCCESS) {
param->info->iu.info2->info2 = de.de_entries;
param->info->iu.info2->count = de.de_nitems;
}
break;
case 3:
entsize = sizeof (netdfs_info3_t) +
sizeof (netdfs_storage_info_t);
de.de_nmax = MAX((de.de_prefmaxlen / entsize), 1);
de.de_entries = NDR_NEWN(mxa, netdfs_info3_t, de.de_nmax);
if (de.de_entries == NULL)
goto enum_error;
if ((status = netdfs_enum_common(&de, mxa)) == ERROR_SUCCESS) {
param->info->iu.info3->info3 = de.de_entries;
param->info->iu.info3->count = de.de_nitems;
}
break;
case 4:
entsize = sizeof (netdfs_info4_t) +
sizeof (netdfs_storage_info_t);
de.de_nmax = MAX((de.de_prefmaxlen / entsize), 1);
de.de_entries = NDR_NEWN(mxa, netdfs_info4_t, de.de_nmax);
if (de.de_entries == NULL)
goto enum_error;
if ((status = netdfs_enum_common(&de, mxa)) == ERROR_SUCCESS) {
param->info->iu.info4->info4 = de.de_entries;
param->info->iu.info4->count = de.de_nitems;
}
break;
case 5:
entsize = sizeof (netdfs_info5_t);
de.de_nmax = MAX((de.de_prefmaxlen / entsize), 1);
de.de_entries = NDR_NEWN(mxa, netdfs_info5_t, de.de_nmax);
if (de.de_entries == NULL)
goto enum_error;
if ((status = netdfs_enum_common(&de, mxa)) == ERROR_SUCCESS) {
param->info->iu.info5->info5 = de.de_entries;
param->info->iu.info5->count = de.de_nitems;
}
break;
case 6:
entsize = sizeof (netdfs_info6_t) +
sizeof (netdfs_storage_info1_t);
de.de_nmax = MAX((de.de_prefmaxlen / entsize), 1);
de.de_entries = NDR_NEWN(mxa, netdfs_info6_t, de.de_nmax);
if (de.de_entries == NULL)
goto enum_error;
if ((status = netdfs_enum_common(&de, mxa)) == ERROR_SUCCESS) {
param->info->iu.info6->info6 = de.de_entries;
param->info->iu.info6->count = de.de_nitems;
}
break;
case 300:
entsize = sizeof (netdfs_info300_t);
de.de_nmax = MAX((de.de_prefmaxlen / entsize), 1);
de.de_entries = NDR_NEWN(mxa, netdfs_info300_t, de.de_nmax);
if (de.de_entries == NULL)
goto enum_error;
if ((status = netdfs_enum_common(&de, mxa)) == ERROR_SUCCESS) {
param->info->iu.info300->info300 = de.de_entries;
param->info->iu.info300->count = de.de_nitems;
}
break;
default:
status = ERROR_INVALID_PARAMETER;
break;
}
if ((status == ERROR_SUCCESS) && (param->resume_handle != NULL))
*param->resume_handle = de.de_resume;
enum_error:
dfs_setpriv(PRIV_OFF);
param->status = status;
return (NDR_DRC_OK);
}
/*
* Renames or moves a DFS link
*
* Does not need to be supported for DFS version 1
*
* [MS-DFSNM]: NetrDfsMove (Opnum 6)
*/
/*ARGSUSED*/
static int
netdfs_s_move(void *arg, ndr_xa_t *mxa)
{
struct netdfs_move *param = arg;
param->status = ERROR_NOT_SUPPORTED;
return (NDR_DRC_OK);
}
/*
* According to [MS-DFSNM] spec this operation (opnum 7) is not
* used over the wire.
*/
/*ARGSUSED*/
static int
netdfs_s_rename(void *arg, ndr_xa_t *mxa)
{
struct netdfs_rename *param = arg;
param->status = ERROR_NOT_SUPPORTED;
return (NDR_DRC_OK);
}
/*
* Creates a new standalone DFS namespace
*
* [MS-DFSNM]: NetrDfsAddStdRoot (Opnum 12)
*/
/*ARGSUSED*/
static int
netdfs_s_addstdroot(void *arg, ndr_xa_t *mxa)
{
struct netdfs_addstdroot *param = arg;
const char *share = (const char *)param->share;
const char *comment = (const char *)param->comment;
if (!ndr_is_admin(mxa)) {
param->status = ERROR_ACCESS_DENIED;
return (NDR_DRC_OK);
}
dfs_setpriv(PRIV_ON);
/* For now only allow a single standalone namespace */
if (dfs_namespace_count() == 0)
param->status = dfs_namespace_add(share, comment);
else
param->status = ERROR_NOT_SUPPORTED;
dfs_setpriv(PRIV_OFF);
return (NDR_DRC_OK);
}
/*
* Deletes the specified stand-alone DFS namespace. The DFS namespace can be
* removed without first removing all of the links in it.
*
* [MS-DFSNM]: NetrDfsRemoveStdRoot (Opnum 13)
*/
/*ARGSUSED*/
static int
netdfs_s_remstdroot(void *arg, ndr_xa_t *mxa)
{
struct netdfs_remstdroot *param = arg;
const char *share = (const char *)param->share;
dfs_setpriv(PRIV_ON);
if (ndr_is_admin(mxa))
param->status = dfs_namespace_remove(share);
else
param->status = ERROR_ACCESS_DENIED;
dfs_setpriv(PRIV_OFF);
return (NDR_DRC_OK);
}
/*
* Enumerates the DFS roots hosted on a server, or DFS links of a namespace
* hosted by the server. Depending on the information level, the targets
* associated with the roots and links are also displayed
*
* Does not need to be supported for DFS version 1
*
* [MS-DFSNM] NetrDfsEnumEx (Opnum 21)
*/
/*ARGSUSED*/
static int
netdfs_s_enumex(void *arg, ndr_xa_t *mxa)
{
struct netdfs_enumex *param = arg;
bzero(param->info, sizeof (struct netdfs_enumex));
param->status = ERROR_NOT_SUPPORTED;
return (NDR_DRC_OK);
}
/*
* Sets the comment for the DFS link/root.
*/
static uint32_t
netdfs_setinfo_100(dfs_path_t *path, netdfs_info100_t *netinfo)
{
dfs_info_t info;
uint32_t status;
char *cmnt = (char *)netinfo->comment;
bzero(&info, sizeof (dfs_info_t));
if (cmnt != NULL)
(void) strlcpy(info.i_comment, cmnt, sizeof (info.i_comment));
if (path->p_type == DFS_OBJECT_LINK)
status = dfs_link_setinfo(path->p_fspath, &info, 100);
else
status = dfs_root_setinfo(path->p_fspath, &info, 100);
return (status);
}
/*
* Sets the state for the DFS root/link or its target.
*/
static uint32_t
netdfs_setinfo_101(dfs_path_t *path, netdfs_info101_t *netinfo,
const char *t_server, const char *t_share)
{
dfs_info_t info;
dfs_target_t target;
uint32_t status;
bzero(&info, sizeof (dfs_info_t));
bzero(&target, sizeof (dfs_target_t));
if (t_server == NULL && t_share == NULL) {
info.i_state = netinfo->state;
} else {
target.t_state = netinfo->state;
(void) strlcpy(target.t_server, t_server,
sizeof (target.t_server));
(void) strlcpy(target.t_share, t_share,
sizeof (target.t_share));
info.i_targets = ⌖
}
if (path->p_type == DFS_OBJECT_LINK)
status = dfs_link_setinfo(path->p_fspath, &info, 101);
else
status = dfs_root_setinfo(path->p_fspath, &info, 101);
return (status);
}
/*
* Sets the timeout value of the DFS link/root.
*/
static uint32_t
netdfs_setinfo_102(dfs_path_t *path, netdfs_info102_t *netinfo)
{
dfs_info_t info;
uint32_t status;
bzero(&info, sizeof (dfs_info_t));
info.i_timeout = netinfo->timeout;
if (path->p_type == DFS_OBJECT_LINK)
status = dfs_link_setinfo(path->p_fspath, &info, 102);
else
status = dfs_root_setinfo(path->p_fspath, &info, 102);
return (status);
}
/*
* Sets the property flags for the root or link.
*/
static uint32_t
netdfs_setinfo_103(dfs_path_t *path, netdfs_info103_t *netinfo)
{
dfs_info_t info;
uint32_t status;
bzero(&info, sizeof (dfs_info_t));
info.i_propflags =
netinfo->property_flags & netinfo->property_flag_mask;
if (path->p_type == DFS_OBJECT_LINK)
status = dfs_link_setinfo(path->p_fspath, &info, 103);
else
status = dfs_root_setinfo(path->p_fspath, &info, 103);
return (status);
}
/*
* Sets the target priority rank and class for the root target or link target
*/
static uint32_t
netdfs_setinfo_104(dfs_path_t *path, netdfs_info104_t *netinfo,
const char *t_server, const char *t_share)
{
dfs_info_t info;
dfs_target_t target;
uint32_t status;
if ((t_server == NULL) || (t_share == NULL))
return (ERROR_INVALID_PARAMETER);
if (netinfo->priority_class > DfsGlobalLowPriorityClass)
return (ERROR_INVALID_PARAMETER);
if (netinfo->priority_rank > DFS_PRIORITY_RANK_MAX)
return (ERROR_INVALID_PARAMETER);
bzero(&info, sizeof (dfs_info_t));
bzero(&target, sizeof (dfs_target_t));
target.t_priority.p_class = netinfo->priority_class;
target.t_priority.p_rank = netinfo->priority_rank;
(void) strlcpy(target.t_server, t_server, sizeof (target.t_server));
(void) strlcpy(target.t_share, t_share, sizeof (target.t_share));
info.i_targets = ⌖
if (path->p_type == DFS_OBJECT_LINK)
status = dfs_link_setinfo(path->p_fspath, &info, 104);
else
status = dfs_root_setinfo(path->p_fspath, &info, 104);
return (status);
}
/*
* Sets the comment, state, time-out information, and property flags for the
* namespace root or link specified in DfsInfo. Does not apply to a root target
* or link target.
*/
static uint32_t
netdfs_setinfo_105(dfs_path_t *path, netdfs_info105_t *netinfo)
{
dfs_info_t info;
uint32_t status, flavor;
char *cmnt = (char *)netinfo->comment;
bzero(&info, sizeof (dfs_info_t));
flavor = dfs_namespace_getflavor(path->p_unc.unc_share);
if (flavor == 0)
return (ERROR_INTERNAL_ERROR);
info.i_flavor = flavor;
if (cmnt != NULL)
(void) strlcpy(info.i_comment, cmnt, sizeof (info.i_comment));
info.i_state = netinfo->state;
info.i_timeout = netinfo->timeout;
info.i_propflag_mask = netinfo->property_flag_mask;
info.i_propflags =
netinfo->property_flags & netinfo->property_flag_mask;
if (path->p_type == DFS_OBJECT_LINK)
status = dfs_link_setinfo(path->p_fspath, &info, 105);
else
status = dfs_root_setinfo(path->p_fspath, &info, 105);
return (status);
}
/*
* DFS_STORAGE_INFO: target information
*/
static uint32_t
netdfs_info_storage(netdfs_storage_info_t **sinfo, dfs_info_t *info,
ndr_xa_t *mxa, uint32_t *size)
{
netdfs_storage_info_t *storage;
dfs_target_t *target;
int i;
*sinfo = NULL;
if (info->i_ntargets == 0)
return (ERROR_SUCCESS);
*sinfo = NDR_NEWN(mxa, netdfs_storage_info_t, info->i_ntargets);
if (*sinfo == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
if (size != NULL)
*size += info->i_ntargets * sizeof (netdfs_storage_info_t);
target = info->i_targets;
storage = *sinfo;
for (i = 0; i < info->i_ntargets; i++, target++, storage++) {
storage->state = target->t_state;
storage->server = NDR_STRDUP(mxa, target->t_server);
storage->share = NDR_STRDUP(mxa, target->t_share);
if (storage->server == NULL || storage->share == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
if (size != NULL)
*size += smb_wcequiv_strlen(target->t_server) +
smb_wcequiv_strlen(target->t_share);
}
return (ERROR_SUCCESS);
}
/*
* DFS_STORAGE_INFO_1: target information
*/
static uint32_t
netdfs_info_storage1(netdfs_storage_info1_t **sinfo, dfs_info_t *info,
ndr_xa_t *mxa, uint32_t *size)
{
netdfs_storage_info1_t *storage;
dfs_target_t *target;
int i;
*sinfo = NULL;
if (info->i_ntargets == 0)
return (ERROR_SUCCESS);
*sinfo = NDR_NEWN(mxa, netdfs_storage_info1_t, info->i_ntargets);
if (*sinfo == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
if (size != NULL)
*size += info->i_ntargets * sizeof (netdfs_storage_info1_t);
target = info->i_targets;
storage = *sinfo;
for (i = 0; i < info->i_ntargets; i++, target++, storage++) {
storage->state = target->t_state;
storage->server = NDR_STRDUP(mxa, target->t_server);
storage->share = NDR_STRDUP(mxa, target->t_share);
storage->p_class = target->t_priority.p_class;
storage->p_rank = target->t_priority.p_rank;
storage->p_reserved = 0;
if (storage->server == NULL || storage->share == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
if (size != NULL)
*size += smb_wcequiv_strlen(target->t_server) +
smb_wcequiv_strlen(target->t_share);
}
return (ERROR_SUCCESS);
}
/*
* Sets a DFS_INFO_1 for get/enum response
*/
static uint32_t
netdfs_info_1(netdfs_info1_t *info1, dfs_info_t *info, ndr_xa_t *mxa,
uint32_t *size)
{
info1->entry_path = NDR_STRDUP(mxa, info->i_uncpath);
if (info1->entry_path == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
if (size != NULL)
*size = sizeof (netdfs_info1_t) +
smb_wcequiv_strlen(info->i_uncpath);
return (ERROR_SUCCESS);
}
/*
* Sets a DFS_INFO_2 for get/enum response
*/
static uint32_t
netdfs_info_2(netdfs_info2_t *info2, dfs_info_t *info, ndr_xa_t *mxa,
uint32_t *size)
{
void *entry_path;
void *comment;
entry_path = NDR_STRDUP(mxa, info->i_uncpath);
comment = NDR_STRDUP(mxa, info->i_comment);
if (entry_path == NULL || comment == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
info2->entry_path = entry_path;
info2->comment = comment;
info2->state = info->i_state;
info2->n_store = info->i_ntargets;
if (size != NULL)
*size = sizeof (netdfs_info2_t) +
smb_wcequiv_strlen(info->i_uncpath) +
smb_wcequiv_strlen(info->i_comment);
return (ERROR_SUCCESS);
}
/*
* Sets a DFS_INFO_3 for get/enum response
*/
static uint32_t
netdfs_info_3(netdfs_info3_t *info3, dfs_info_t *info, ndr_xa_t *mxa,
uint32_t *size)
{
void *entry_path;
void *comment;
entry_path = NDR_STRDUP(mxa, info->i_uncpath);
comment = NDR_STRDUP(mxa, info->i_comment);
if (entry_path == NULL || comment == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
info3->entry_path = entry_path;
info3->comment = comment;
info3->state = info->i_state;
info3->n_store = info->i_ntargets;
if (size != NULL)
*size = sizeof (netdfs_info3_t) +
smb_wcequiv_strlen(info->i_uncpath) +
smb_wcequiv_strlen(info->i_comment);
return (netdfs_info_storage(&info3->si, info, mxa, size));
}
/*
* Sets a DFS_INFO_4 for get/enum response
*/
static uint32_t
netdfs_info_4(netdfs_info4_t *info4, dfs_info_t *info, ndr_xa_t *mxa,
uint32_t *size)
{
void *entry_path;
void *comment;
entry_path = NDR_STRDUP(mxa, info->i_uncpath);
comment = NDR_STRDUP(mxa, info->i_comment);
if (entry_path == NULL || comment == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
if (!netdfs_guid_fromstr(info->i_guid, &info4->guid))
return (ERROR_INVALID_DATA);
info4->entry_path = entry_path;
info4->comment = comment;
info4->state = info->i_state;
info4->timeout = info->i_timeout;
info4->n_store = info->i_ntargets;
if (size != NULL)
*size = sizeof (netdfs_info4_t) +
smb_wcequiv_strlen(info->i_uncpath) +
smb_wcequiv_strlen(info->i_comment);
return (netdfs_info_storage(&info4->si, info, mxa, size));
}
/*
* Sets a DFS_INFO_5 for get/enum response
*/
static uint32_t
netdfs_info_5(netdfs_info5_t *info5, dfs_info_t *info, ndr_xa_t *mxa,
uint32_t *size)
{
void *entry_path;
void *comment;
entry_path = NDR_STRDUP(mxa, info->i_uncpath);
comment = NDR_STRDUP(mxa, info->i_comment);
if (entry_path == NULL || comment == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
if (!netdfs_guid_fromstr(info->i_guid, &info5->guid))
return (ERROR_INVALID_DATA);
info5->entry_path = entry_path;
info5->comment = comment;
info5->state = info->i_state;
info5->timeout = info->i_timeout;
info5->flags = info->i_propflags;
info5->metadata_sz = 0;
info5->n_store = info->i_ntargets;
if (size != NULL)
*size = sizeof (netdfs_info5_t) +
smb_wcequiv_strlen(info->i_uncpath) +
smb_wcequiv_strlen(info->i_comment);
return (ERROR_SUCCESS);
}
/*
* Sets a DFS_INFO_6 for get/enum response
*/
static uint32_t
netdfs_info_6(netdfs_info6_t *info6, dfs_info_t *info, ndr_xa_t *mxa,
uint32_t *size)
{
void *entry_path;
void *comment;
entry_path = NDR_STRDUP(mxa, info->i_uncpath);
comment = NDR_STRDUP(mxa, info->i_comment);
if (entry_path == NULL || comment == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
if (!netdfs_guid_fromstr(info->i_guid, &info6->guid))
return (ERROR_INVALID_DATA);
info6->entry_path = entry_path;
info6->comment = comment;
info6->state = info->i_state;
info6->timeout = info->i_timeout;
info6->flags = info->i_propflags;
info6->metadata_sz = 0;
info6->n_store = info->i_ntargets;
if (size != NULL)
*size = sizeof (netdfs_info6_t) +
smb_wcequiv_strlen(info->i_uncpath) +
smb_wcequiv_strlen(info->i_comment);
return (netdfs_info_storage1(&info6->si, info, mxa, size));
}
/*
* Sets a DFS_INFO_100 for Get response
*/
static uint32_t
netdfs_info_100(netdfs_info100_t *info100, dfs_info_t *info, ndr_xa_t *mxa,
uint32_t *size)
{
info100->comment = NDR_STRDUP(mxa, info->i_comment);
if (info100->comment == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
if (size != NULL)
*size = sizeof (netdfs_info100_t) +
smb_wcequiv_strlen(info->i_comment);
return (ERROR_SUCCESS);
}
/*
* Sets a DFS_INFO_300 for Enum response
*/
static uint32_t
netdfs_info_300(netdfs_info300_t *info300, dfs_info_t *info, ndr_xa_t *mxa,
uint32_t *size)
{
info300->dfsname = NDR_STRDUP(mxa, info->i_uncpath);
if (info300->dfsname == NULL)
return (ERROR_NOT_ENOUGH_MEMORY);
info300->flavor = DFS_VOLUME_FLAVOR_STANDALONE;
if (size != NULL)
*size = sizeof (netdfs_info300_t) +
smb_wcequiv_strlen(info->i_uncpath);
return (ERROR_SUCCESS);
}
/*
* Common enumeration function
*/
static uint32_t
netdfs_enum_common(netdfs_enumhandle_t *de, ndr_xa_t *mxa)
{
netdfs_info1_t *info1 = de->de_entries;
netdfs_info2_t *info2 = de->de_entries;
netdfs_info3_t *info3 = de->de_entries;
netdfs_info4_t *info4 = de->de_entries;
netdfs_info5_t *info5 = de->de_entries;
netdfs_info6_t *info6 = de->de_entries;
netdfs_info300_t *info300 = de->de_entries;
dfs_info_t dfsinfo;
smb_cache_cursor_t cursor;
dfs_nscnode_t nscnode;
uint32_t status;
uint32_t itemsz;
dfs_cache_iterinit(&cursor);
de->de_nitems = 0;
while (dfs_cache_iterate(&cursor, &nscnode)) {
if (de->de_nskip > 0) {
de->de_nskip--;
continue;
}
if (de->de_nitems == de->de_nmax)
break;
status = dfs_cache_getinfo(&nscnode, &dfsinfo, de->de_level);
if (status != ERROR_SUCCESS)
continue;
switch (de->de_level) {
case 1:
status = netdfs_info_1(info1, &dfsinfo, mxa, &itemsz);
info1++;
break;
case 2:
status = netdfs_info_2(info2, &dfsinfo, mxa, &itemsz);
info2++;
break;
case 3:
status = netdfs_info_3(info3, &dfsinfo, mxa, &itemsz);
info3++;
break;
case 4:
status = netdfs_info_4(info4, &dfsinfo, mxa, &itemsz);
info4++;
break;
case 5:
status = netdfs_info_5(info5, &dfsinfo, mxa, &itemsz);
info5++;
break;
case 6:
status = netdfs_info_6(info6, &dfsinfo, mxa, &itemsz);
info6++;
break;
case 300:
status = netdfs_info_300(info300, &dfsinfo, mxa,
&itemsz);
info300++;
break;
default:
status = ERROR_INVALID_LEVEL;
}
dfs_info_free(&dfsinfo);
if (status != ERROR_SUCCESS)
return (status);
if (de->de_nmax == 1) {
de->de_nitems = 1;
break;
}
if (itemsz > de->de_bavail)
break;
de->de_bavail -= itemsz;
de->de_nitems++;
}
de->de_resume += de->de_nitems;
return (ERROR_SUCCESS);
}
/*
* Creates intermediate directories of a link from the root share path.
*
* TODO: directories should be created by smbsrv to get Windows compatible
* ACL inheritance.
*/
static void
netdfs_path_create(const char *path)
{
char dirpath[DFS_PATH_MAX];
mode_t mode;
char *p;
(void) strlcpy(dirpath, path, DFS_PATH_MAX);
/* drop the link itself from the path */
if ((p = strrchr(dirpath, '/')) != NULL) {
*p = '\0';
mode = umask(0);
(void) mkdirp(dirpath, 0777);
(void) umask(mode);
}
}
/*
* Removes empty directories
*/
static void
netdfs_path_remove(smb_unc_t *unc)
{
char rootdir[DFS_PATH_MAX];
char relpath[DFS_PATH_MAX];
char dir[DFS_PATH_MAX];
uint32_t status;
char *p;
status = dfs_namespace_path(unc->unc_share, rootdir, DFS_PATH_MAX);
if ((status == ERROR_SUCCESS) && (chdir(rootdir) == 0)) {
(void) strlcpy(relpath, unc->unc_path, DFS_PATH_MAX);
/* drop the link itself from the path */
if ((p = strrchr(relpath, '/')) != NULL) {
*p = '\0';
(void) rmdirp(relpath, dir);
}
}
}
/*
* Converts the guid string into binary format in network byte order.
*/
static boolean_t
netdfs_guid_fromstr(char *guid_str, netdfs_uuid_t *guid)
{
uuid_t uuid;
if (uuid_parse(guid_str, uuid) != 0)
return (B_FALSE);
bcopy(&uuid, guid, sizeof (uuid_t));
guid->data1 = htonl(guid->data1);
guid->data2 = htons(guid->data2);
guid->data3 = htons(guid->data3);
return (B_TRUE);
}
|