summaryrefslogtreecommitdiff
path: root/source3/script/tests/test_net_conf.sh
blob: 6d3d2a1eecde0eb6656680f358aeb74f1ddbac21 (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
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
#!/bin/sh
#
# Blackbox test for net [rpc] conf.
#
# Copyright (C) 2011 Vicentiu Ciorbaru <cvicentiu@gmail.com>

if [ $# -lt 3 ]; then
cat <<EOF
Usage: test_net_conf.sh SCRIPTDIR SERVERCONFFILE NET CONFIGURATION [rpc]
EOF
exit 1;
fi

SCRIPTDIR="$1"
SERVERCONFFILE="$2"
NET="$3"
CONFIGURATION="$4"
RPC="$5"

LOGDIR_PREFIX="conf_test"

# remove old logs:
for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
	echo "removing old directory ${OLDDIR}"
	rm -rf ${OLDDIR}
done


NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
DIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX)
LOG=$DIR/log


if test "x${RPC}" = "xrpc" ; then
	NETCMD="${NET} -U${USERNAME}%${PASSWORD} -I ${SERVER_IP} rpc"
else
	NETCMD="${NET}"
fi

incdir=`dirname $0`/../../../testprogs/blackbox
. $incdir/subunit.sh

failed=0

SED_INVALID_PARAMS="{
s/lock directory/;&/g
s/lock dir/;&/g
s/modules dir/;&/g
s/logging/;&/g
s/status/;&/g
s/logdir/;&/g
s/read prediction/;&/g
s/mkprofile/;&/g
s/valid chars/;&/g
s/timesync/;&/g
s/sambaconf/;&/g
s/logtype/;&/g
s/servername/;&/g
s/postscript/;&/g
}"

REGPATH="HKLM\Software\Samba"

log_print() {
    RC=$?
    echo "CMD: $*" >>$LOG
    echo "RC: $RC" >> $LOG
    return $RC
#    echo -n .
}

test_conf_addshare()
{
    echo '\nTesting conf addshare' >> $LOG
    echo ------------------------- >> $LOG
    echo '\nDropping existing configuration' >> $LOG

    $NETCMD conf drop
    log_print $NETCMD conf drop
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

#create a lot of shares
    for i in $(seq 1 100); do
	if [ $(($i % 2)) -eq 0 ]; then
		$NETCMD conf addshare share$i /tmp "writeable=y" "guest_ok=n" \
					   "test comment" >>$DIR/addshare_exp \
							  2>>$DIR/addshare_exp
		log_print $NETCMD conf addshare share$i /tmp "writeable=y" "guest_ok=n" \
					   "test comment"
	else
		$NETCMD conf addshare share$i /tmp "writeable=n" "guest_ok=y" \
					   "test comment" >>$DIR/addshare_exp \
							  2>>$DIR/addshare_exp
		log_print $NETCMD conf addshare share$i /tmp "writeable=n" "guest_ok=y" \
					   "test comment"
	fi
	test "x$?" = "x0" || {
		echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
		return 1
	}
    done

    $NETCMD conf listshares > $DIR/listshares_out
    log_print $NETCMD conf listshares
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    for i in $(seq 1 100); do
	grep "share$i" $DIR/listshares_out >/dev/null 2>>$LOG
	if [ "$?" = "1" ]; then
		echo "ERROR: share not found" | tee -a $LOG
		return 1
	fi
    done

#check the integrity of the shares
#if it fails, it can also point to an error in showshare
    for i in $(seq 1 100); do
	$NETCMD conf showshare share$i > $DIR/showshare_out
	test "x$?" = "x0" || {
		echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
		return 1
	}

	grep "path" $DIR/showshare_out >/dev/null 2>>$LOG
	if [ "$?" = "1" ]; then
		echo "ERROR: share not found" | tee -a $LOG
		return 1
	fi

	if [ $(($i % 2)) -eq 0 ]; then
		grep "read only *= *no" $DIR/showshare_out >/dev/null 2>>$LOG
		if [ "$?" = "1" ]; then
			echo "ERROR: share not set correctly" | tee -a $LOG
			return 1
		fi
	else
		grep "read only *= *yes" $DIR/showshare_out >/dev/null 2>>$LOG
		if [ "$?" = "1" ]; then
			echo "ERROR: share not set correctly" | tee -a $LOG
			return 1
		fi
	fi

	if [ $(($i % 2)) -eq 0 ]; then
		grep "guest ok *= *no" $DIR/showshare_out >/dev/null 2>>$LOG
		if [ "$?" = "1" ]; then
			echo "ERROR: share not set correctly" | tee -a $LOG
			return 1
		fi
	else
		grep "guest ok *= *yes" $DIR/showshare_out >/dev/null 2>>$LOG
		if [ "$?" = "1" ]; then
			echo "ERROR: share not set correctly" | tee -a $LOG
			return 1
		fi
	fi

	grep "comment *= *test comment" $DIR/showshare_out >/dev/null 2>>$LOG
	if [ "$?" = "1" ]; then
		echo "ERROR: share not set correctly" | tee -a $LOG
		return 1
	fi
    done

    echo '\nTaking a conf snapshot for later use' >> $LOG
    $NETCMD conf list > $DIR/conf_import_in
    log_print $NETCMD conf list
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }
}

test_conf_addshare_existing()
{
#try adding an already existing share
    echo '\nAdding an already existing share' >>$LOG
    $NETCMD conf addshare share1 /tmp "writeable=n" "guest_ok=y" \
			      "test comment" >>$DIR/addshare_exp \
					    2>>$DIR/addshare_exp
    log_print $NETCMD conf addshare share1 /tmp "writeable=n" "guest_ok=y" \
			      "test comment"
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    test -z `cat $DIR/addshare_exp` && {
	echo "ERROR: addshare output does not match" >> $LOG
	return 1
    }

    return 0
}

test_conf_addshare_usage()
{
#check to see if command prints usage
    echo '\nChecking usage' >>$LOG
    $NETCMD conf addshare > $DIR/addshare_usage_exp
    log_print $NETCMD conf addshare
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }

    grep "$RPC *conf addshare" $DIR/addshare_usage_exp >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: no/wrong usage message printed" | tee -a $LOG
	return 1
    fi
}

test_conf_delshare()
{
    echo '\nTesting conf delshare' >>$LOG
    echo ------------------------- >> $LOG
    echo -n '\n' >> $LOG

    $NETCMD conf delshare share1
    log_print $NETCMD conf delshare share1
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf listshares > $DIR/listshares_out
    log_print $NETCMD conf listshares
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    grep "share1$" $DIR/listshares_out >/dev/null 2>>$LOG
    if [ "$?" = "0" ]; then
	echo "ERROR: delshare did not delete 'share1'" | tee -a $LOG
	return 1
    fi
}

test_conf_delshare_empty()
{
    echo '\nAttempting to delete non_existing share'
    $NETCMD conf delshare share1
    log_print $NETCMD conf delshare share1
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }

}

test_conf_delshare_usage()
{
    echo '\nChecking usage' >>$LOG
    $NETCMD conf delshare > $DIR/delshare_usage_exp
    log_print $NETCMD conf delshare
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }

    grep "$RPC *conf delshare" $DIR/delshare_usage_exp >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: no/wrong usage message printed" | tee -a $LOG
	return 1
    fi
}

test_conf_drop()
{

    echo '\nTesting conf drop' >> $LOG
    echo ------------------------- >> $LOG
    echo '\nDropping existing configuration' >> $LOG

    $NETCMD conf drop
    log_print $NETCMD conf drop
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

#check to see if listing the configuration yields a blank file
    $NETCMD conf list 1>>$DIR/list_out
    log_print $NETCMD conf list
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    test -z "`cat $DIR/list_out`" || {
	echo "ERROR: Expected list output did not match" | tee -a $LOG
	return 1
    }
}

test_conf_drop_empty()
{
#Drop an empty config, see if conf drop fails
    echo '\nAttempting to drop an empty configuration' >>$LOG

    $NETCMD conf drop
    log_print $NETCMD conf drop
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

#check to see if listing the configuration yields a blank file
    $NETCMD conf list 1>>$DIR/list_out
    log_print $NETCMD conf list
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    test -z "`cat $DIR/list_out`" || {
	echo ERROR:Expected list output did not match >> $LOG
	return 1
    }
}

test_conf_drop_usage()
{
#check to see if command prints usage
    echo '\nChecking usage' >>$LOG
    $NETCMD conf drop extra_arg > $DIR/drop_usage_exp
    log_print $NETCMD conf drop extra_arg
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

   grep "$RPC *conf drop" $DIR/drop_usage_exp >/dev/null 2>>$LOG
   if [ "$?" = "1" ]; then
	echo "ERROR: no/wrong usage message printed" | tee -a $LOG
	return 1
   fi
}

test_conf_setparm()
{
    echo '\nTesting conf setparm' >> $LOG
    echo ------------------------- >> $LOG

    echo '\nDropping existing configuration' >> $LOG
    $NETCMD conf drop
    log_print $NETCMD conf drop
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf setparm share1 "read only" yes
    log_print $NETCMD conf setparm share1 "read only" yes
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf setparm share1 "path" /tmp/test_path
    log_print $NETCMD conf setparm share1 "path" /tmp/test_path
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf showshare share1 > $DIR/setparm_showshare_out
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    grep "read only *= *yes" $DIR/setparm_showshare_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: setparm did not set correctly" | tee -a $LOG
	return 1
    fi

    grep "path *= */tmp/test_path" $DIR/setparm_showshare_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: setparm did not set correctly" | tee -a $LOG
	return 1
    fi
}

test_conf_setparm_existing()
{

    echo '\nSetting already existing param with the same value'
    $NETCMD conf setparm share1 "read only" yes
    log_print $NETCMD conf setparm share1 "read only" yes
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf setparm share1 "read only" yes
    log_print $NETCMD conf setparm share1 "read only" yes
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf showshare share1 > $DIR/setparm_existing_showshare_out
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    grep "read only *= *yes" $DIR/setparm_existing_showshare_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: setparm did not set correctly" | tee -a $LOG
	return 1
    fi

    $NETCMD conf setparm share1 "read only" no
    log_print $NETCMD conf setparm share1 "read only" no
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf showshare share1 > $DIR/setparm_existing_showshare_out
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    grep "read only *= *no" $DIR/setparm_existing_showshare_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: setparm did not set correctly" | tee -a $LOG
	return 1
    fi
}

test_conf_setparm_usage()
{
    echo '\nChecking usage' >>$LOG
    $NETCMD conf setparm > $DIR/setparm_usage_exp
    log_print $NETCMD conf setparm
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    grep "$RPC *conf setparm" $DIR/setparm_usage_exp >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: setparm no/wrong usage message printed" | tee -a $LOG
	return 1
    fi
}

test_conf_delparm_delete_existing()
{
    echo '\nTesting conf delparm' >> $LOG
    echo ------------------------- >> $LOG
    echo -n '\n' >>$LOG

    $NETCMD conf drop
    log_print $NETCMD conf drop
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf addshare share1 /tmp "writeable=y" "guest_ok=n" \
				       "test comment"
    log_print $NETCMD conf addshare share$i /tmp "writeable=y" "guest_ok=n" \
				       "test comment"

    $NETCMD conf delparm share1 "path"
    log_print $NETCMD conf delparm share1 "path"
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf showshare share1 > $DIR/delparm_showshare_out
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

#test to see what delparm did delete and how
    grep "read only *= *no" $DIR/delparm_showshare_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: delparm did not delete correctly" | tee -a $LOG
	return 1
    fi

    grep "path *= */tmp" $DIR/delparm_showshare_out >/dev/null 2>>$LOG
    if [ "$?" = "0" ]; then
	echo "ERROR: delparm did not delete correctly" | tee -a $LOG
	return 1
    fi
}

test_conf_delparm_delete_non_existing()
{
    echo '\nDelete non existing share' >> $LOG

    $NETCMD conf drop
    log_print $NETCMD conf drop
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf delparm share1 "path"
    log_print $NETCMD conf delparm share1 "path"
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }
}

test_conf_delparm_usage()
{

    echo '\nChecking usage' >>$LOG
    $NETCMD conf delparm > $DIR/delparm_usage_exp
    log_print $NETCMD conf delparm
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }

    grep "$RPC *conf delparm" $DIR/delparm_usage_exp >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: delparm no/wrong usage message printed" | tee -a $LOG
	return 1
    fi

}

test_conf_getparm()
{

    echo '\nTesting conf getparm' >> $LOG
    echo ------------------------- >> $LOG
    echo -n '\n' >>$LOG

    $NETCMD conf drop
    log_print $NETCMD conf drop
    test "x$?" = "x0" || {
	return 1
    }

    $NETCMD conf addshare share1 /tmp/path_test "writeable=n" "guest_ok=n" \
				       "test comment"
    log_print $NETCMD conf addshare share$i /tmp/path_test "writeable=n" "guest_ok=n" \
				       "test comment"
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf getparm share1 "read only" >$DIR/getparm_out
    log_print $NETCMD conf getparm share1 "read only"
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf getparm share1 "read only" >$DIR/getparm_out
    log_print $NETCMD conf getparm share1 "read only"
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    echo yes >$DIR/getparm_exp
    diff -q $DIR/getparm_out $DIR/getparm_exp  >> $LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: getparm did not print correctly" | tee -a $LOG
	return 1
    fi

    $NETCMD conf getparm share1 "path" >$DIR/getparm_out
    log_print $NETCMD conf getparm share1 "path"
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    echo /tmp/path_test >$DIR/getparm_exp
    diff -q $DIR/getparm_out $DIR/getparm_exp  >> $LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: getparm did not print correctly" | tee -a $LOG
	return 1
    fi
}

test_conf_getparm_usage()
{
    echo '\nChecking usage' >>$LOG
    $NETCMD conf getparm > $DIR/getparm_usage_exp
    log_print $NETCMD conf getparm
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }

    grep "$RPC *conf getparm" $DIR/getparm_usage_exp >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: getparm no/wrong usage message printed" | tee -a $LOG
	return 1
    fi

}

test_conf_getparm_non_existing()
{
    echo '\nTesting getparm non existing' >>$LOG
    $NETCMD conf getparm fictional_share fictional_param
    log_print $NETCMD conf getparm fictional_share fictional_param
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }

    $NETCMD conf getparm share1 fictional_param
    log_print $NETCMD conf getparm share1 fictional_param
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }
}

test_conf_setincludes()
{
    echo '\nTesting conf setincludes' >> $LOG
    echo ------------------------- >> $LOG
    echo '\nDropping existing configuration' >> $LOG

    $NETCMD conf drop
    log_print $NETCMD conf drop
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf addshare tmp_share /tmp
    log_print $NETCMD conf addshare tmp_share /tmp
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf setincludes tmp_share /tmp/include1 /tmp/include2 /tmp/include3
    log_print $NETCMD conf setincludes tmp_share /tmp/include1 /tmp/include2 /tmp/include3
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf list > $DIR/setincludes_list_out
    log_print $NETCMD conf list
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    grep "include *= */tmp/include1$" $DIR/setincludes_list_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: setincludes did not set correctly" | tee -a $LOG
	return 1
    fi

    grep "include *= */tmp/include2$" $DIR/setincludes_list_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: setincludes did not set correctly" | tee -a $LOG
	return 1
    fi

    grep "include *= */tmp/include3$" $DIR/setincludes_list_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: setincludes did not set correctly" | tee -a $LOG
	return 1
    fi

}

test_conf_setincludes_usage()
{
    echo '\nChecking usage' >>$LOG
    $NETCMD conf setincludes > $DIR/setincludes_usage_exp
    log_print $NETCMD conf setincludes
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }

    grep "$RPC *conf setincludes" $DIR/setincludes_usage_exp >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: no/wrong usage message printed" | tee -a $LOG
	return 1
    fi
}

test_conf_getincludes()
{
    $NETCMD conf getincludes tmp_share > $DIR/getincludes_out
    log_print $NETCMD conf getincludes tmp_share
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    grep "include *= */tmp/include1$" $DIR/getincludes_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: getincludes did not print correctly" | tee -a $LOG
	return 1
    fi

    grep "include *= */tmp/include2$" $DIR/getincludes_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: getincludes did not print correctly" | tee -a $LOG
	return 1
    fi
    grep "include *= */tmp/include3$" $DIR/getincludes_out >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: getincludes did not print correctly" | tee -a $LOG
	return 1
    fi
}

test_conf_getincludes_usage()
{
    $NETCMD conf getincludes > $DIR/getincludes_usage_exp
    log_print $NETCMD conf getincludes

    grep "$RPC *conf getincludes" $DIR/getincludes_usage_exp >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: no/wrong usage message printed" | tee -a $LOG
	return 1
    fi
}

test_conf_delincludes()
{
    echo '\nTesting conf delincludes' >> $LOG
    echo ------------------------- >> $LOG

    $NETCMD conf delincludes tmp_share
    log_print $NETCMD conf delincludes tmp_share
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf list > $DIR/delincludes_list_out
    log_print $NETCMD conf list
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    grep "include" $DIR/delincludes_list_out >/dev/null 2>>$LOG
    if [ "$?" = "0" ]; then
	echo "ERROR: delincludes did not delete correctly" | tee -a $LOG
	return 1
    fi
}

test_conf_delincludes_empty()
{
    $NETCMD conf delincludes tmp_share
    log_print $NETCMD conf delincludes tmp_share
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf delincludes fictional_share
    log_print $NETCMD conf delincludes fictional_share
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }
    return 0
}

test_conf_delincludes_usage()
{
    echo '\nChecking usage' >>$LOG
    $NETCMD conf delincludes > $DIR/delincludes_usage_exp
    log_print $NETCMD conf delincludes
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }

    grep "$RPC *conf delincludes" $DIR/delincludes_usage_exp >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: no/wrong usage message printed" | tee -a $LOG
	return 1
    fi
}

test_conf_import()
{
    echo '\nTesting conf import' >> $LOG
    echo ------------------------- >> $LOG
    echo '\nDropping existing configuration' >> $LOG

    $NETCMD conf drop
    log_print $NETCMD conf drop
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf import $DIR/conf_import_in
    log_print $NETCMD conf drop
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    $NETCMD conf list > $DIR/conf_import_out
    log_print $NETCMD conf list
    test "x$?" = "x0" || {
	echo 'ERROR: RC does not match, expected: 0' | tee -a $LOG
	return 1
    }

    diff -q $DIR/conf_import_in $DIR/conf_import_out  >> $LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: import failed"  | tee -a $LOG
	return 1
    fi
}

test_conf_import_usage()
{
    echo '\nChecking usage' >>$LOG
    $NETCMD conf import > $DIR/import_usage_exp
    log_print $NETCMD conf import
    test "x$?" = "x255" || {
	echo 'ERROR: RC does not match, expected: 255' | tee -a $LOG
	return 1
    }

    grep "$RPC *conf import" $DIR/import_usage_exp >/dev/null 2>>$LOG
    if [ "$?" = "1" ]; then
	echo "ERROR: conf import no/wrong usage message printed" | tee -a $LOG
	return 1
    fi
}

CONF_FILES=$SERVERCONFFILE

    testit "conf_drop" \
	test_conf_drop \
	|| failed=`expr $failed + 1`

    testit "conf_drop_empty" \
	test_conf_drop_empty \
	|| failed=`expr $failed + 1`

    testit "conf_drop_usage" \
	test_conf_drop_usage \
	|| failed=`expr $failed + 1`

    testit "conf_addshare" \
	test_conf_addshare \
	|| failed=`expr $failed + 1`

    testit "conf_addshare_existing" \
	test_conf_addshare_existing \
	|| failed=`expr $failed + 1`

    testit "conf_addshare_usage" \
	test_conf_addshare_usage \
	|| failed=`expr $failed + 1`

    testit "conf_delshare" \
	test_conf_delshare \
	|| failed=`expr $failed + 1`

    testit "conf_delshare_empty" \
	test_conf_delshare_empty \
	|| failed=`expr $failed + 1`

    testit "conf_delshare_usage" \
	test_conf_delshare_usage \
	|| failed=`expr $failed + 1`

    testit "conf_setparm" \
	test_conf_setparm \
	|| failed=`expr $failed + 1`

    testit "conf_setparm_existing" \
	test_conf_setparm_existing \
	|| failed=`expr $failed + 1`

    testit "conf_setparm_usage" \
	test_conf_setparm_usage \
	|| failed=`expr $failed + 1`

    testit "conf_delparm_delete_existing" \
	test_conf_delparm_delete_existing \
	|| failed=`expr $failed + 1`

    testit "conf_delparm_delete_non_existing" \
	test_conf_delparm_delete_non_existing \
	|| failed=`expr $failed + 1`

    testit "conf_delparm_delete_usage" \
	test_conf_delparm_usage \
	|| failed=`expr $failed + 1`

    testit "conf_getparm" \
	test_conf_getparm \
	|| failed=`expr $failed + 1`

    testit "conf_getparm_usage" \
	test_conf_getparm_usage \
	|| failed=`expr $failed + 1`

    testit "conf_setincludes" \
	test_conf_setincludes \
	|| failed=`expr $failed + 1`

    testit "conf_setincludes_usage" \
	test_conf_setincludes_usage \
	|| failed=`expr $failed + 1`

    testit "conf_getincludes" \
	test_conf_getincludes \
	|| failed=`expr $failed + 1`

    testit "conf_getincludes_usage" \
	test_conf_getincludes_usage \
	|| failed=`expr $failed + 1`

    testit "conf_delincludes" \
	test_conf_delincludes \
	|| failed=`expr $failed + 1`

    testit "conf_delincludes_empty" \
	test_conf_delincludes_usage \
	|| failed=`expr $failed + 1`

    testit "conf_delincludes_usage" \
	test_conf_delincludes_empty \
	|| failed=`expr $failed + 1`

    testit "conf_import" \
	test_conf_import \
	|| failed=`expr $failed + 1`

    testit "conf_import_usage" \
	test_conf_import_usage \
	|| failed=`expr $failed + 1`

    if [ $failed -eq 0 ]; then
	rm -r $DIR
    fi

testok $0 $failed