load_lib lib.t
api_exit
api_start

#test "create-principal 1"
#
#proc test1 {} {
#	global test
#	begin_dump
#	one_line_fail_test [format {
#	    kadm5_create_principal $server_handle \
#		    [simple_principal "%s/a"] {KADM5_PRINCIPAL} "%s/a"
#	} $test $test] "NOT_INIT"
#	end_dump_compare "no-diffs"
#}
#test1

# v2 create-principal 3 test, to avoid name conflict
test "create-principal 1"
proc test1 {} {
    global test
#    set prms_id 777
#    setup_xfail {*-*-*} $prms_id
    begin_dump
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_succeed_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} null
    } $test]
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"    
}
test1

test "create-principal 2"

proc test2 {} {
    global test
    begin_dump
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test {
	kadm5_create_principal $server_handle null \
		{KADM5_PRINCIPAL} testpass
    } "EINVAL"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"
}
test2

test "create-principal 4"
proc test4 {} {
    global test

    begin_dump    
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} ""
    } $test] "_Q_TOOSHORT"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"     
}
test4

test "create-principal 5"
proc test5 {} {
    global test
    begin_dump    
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle \
		[simple_principal "%s/a"] {0x100001} "%s/a"
    } $test $test] "BAD_MASK"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"    
}
test5

test "create-principal 6"
proc test6 {} {
    global test
    begin_dump        
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_LAST_PWD_CHANGE} "%s/a"
    } $test $test] "BAD_MASK"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
test6

test "create-principal 7"
proc test7 {} {
    global test
    begin_dump        
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_MOD_TIME} "%s/a"
    } $test $test] "BAD_MASK"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
test7

test "create-principal 8"
proc test8 {} {
    global test
    begin_dump        
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_MOD_NAME} "%s/a"
    } $test $test] "BAD_MASK"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
test8

test "create-principal 9"
proc test9 {} {
    global test
    begin_dump        
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_MKVNO} "%s/a"
    } $test $test] "BAD_MASK"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
test9

test "create-principal 10"
proc test10 {} {
    global test
    begin_dump        
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_AUX_ATTRIBUTES} "%s/a"
    } $test $test] "BAD_MASK"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
test10

test "create-principal 11"
proc test11 {} {
    global test
    begin_dump        
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_POLICY_CLR} "%s/a"
    } $test $test] "BAD_MASK"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
test11

test "create-principal 12"
proc test12 {} {
    global test
    begin_dump        
    if {! [cmd {
	kadm5_init admin/none admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} testpass
    } $test] "AUTH_ADD"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        

}
if {$RPC} { test12 }

test "create-principal 13"
proc test13 {} {
    global test
    begin_dump        
    if {! (( ! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin/get admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} testpass
    } $test] "AUTH_ADD"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"    
}
if {$RPC} { test13 }

test "create-principal 14"
proc test14 {} {
    global test
    begin_dump        
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin/modify admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} testpass
    } $test] "AUTH_ADD"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"    
}
if {$RPC} { test14 }

test "create-principal 15"
proc test15 {} {
    global test
    begin_dump    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin/delete admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} testpass
    } $test] "AUTH_ADD"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"    
}
if {$RPC} { test15 }

test "create-principal 16"
proc test16 {} {
    global test
    begin_dump        
    if {! [cmd {
	kadm5_init admin admin $KADM5_CHANGEPW_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} testpass
    } $test] "AUTH_ADD"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
if {$RPC} { test16 }

test "create-principal 17"
proc test17 {} {
    global test

    begin_dump    
    if {! (( [principal_exists "$test/a"]) || [create_principal "$test/a"])} {
		error_and_restart "$test: couldn't create principal \"$test/a\""
		return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} testpass
    } $test] "DUP"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
test17

test "create-principal 18"
proc test18 {} {
    global test

    begin_dump    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin/add admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle \
		[princ_w_pol "%s/a" test-pol] \
		{KADM5_PRINCIPAL KADM5_POLICY} tP
    } $test] "_Q_TOOSHORT"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"    
}
test18

test "create-principal 19"
proc test19 {} {
    global test

    begin_dump    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle \
		[princ_w_pol "%s/a" test-pol] \
		{KADM5_PRINCIPAL KADM5_POLICY} testpassword
    } $test] "_Q_CLASS"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
test19

test "create-principal 20"
proc test20 {} {
    global test

    begin_dump    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_create_principal $server_handle \
		[princ_w_pol "%s/a" test-pol] \
		{KADM5_PRINCIPAL KADM5_POLICY} Abyssinia
    } $test] "_Q_DICT"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
test20

test "create-principal 21"
proc test21 {} {
    global test

    begin_dump    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_succeed_test [format {
	kadm5_create_principal $server_handle \
		[princ_w_pol "%s/a" non-existant-pol] \
		{KADM5_PRINCIPAL KADM5_POLICY} NotinTheDictionary
    } $test]
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    end_dump_compare "no-diffs"        
}
test21

test "create-principal 23"
proc test23 {} {
    global test

    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    one_line_succeed_test \
	    [format {kadm5_get_principal $server_handle "%s/a" p KADM5_PRINCIPAL_NORMAL_MASK} $test]
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test23

test "create-principal 24"
proc test24 {} {
    global test
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin/rename admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    one_line_succeed_test \
	    [format {kadm5_get_principal $server_handle "%s/a" p KADM5_PRINCIPAL_NORMAL_MASK} $test]
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test24 }


test "create-principal 28"
proc test28 {} {
    global test
    global prompt

    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    
    if {! [cmd [format {
	kadm5_create_principal $server_handle \
		[princ_w_pol "%s/a" test-pol] \
		{KADM5_PRINCIPAL KADM5_POLICY} NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return
    }
    send "lindex \$principal 10\n"
    expect {
	-re "test-pol.*$prompt$"   { pass "$test" }
	timeout			    { fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test28

test "create-principal 29"
proc test29 {} {
    global test
    global prompt

    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL KADM5_PRINC_EXPIRE_TIME} \
		inTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    send "lindex \$principal 1\n"
    expect {
	-re "0.*$prompt$"   { pass "$test" }
	timeout			    { fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test29

test "create-principal 30"
proc test30 {} {
    global test
    global prompt

    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL KADM5_PW_EXPIRATION} \
		NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    send "lindex \$principal 3\n"
    expect {
	-re "0.*$prompt$"	    { pass "$test" }
	timeout			    { fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test30

test "create-principal 31"
proc test31 {} {
    global test
    global prompt
    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle \
		[princ_w_pol "%s/a" test-pol-nopw] \
		{KADM5_PRINCIPAL KADM5_POLICY \
		KADM5_PW_EXPIRATION} NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    send "lindex \$principal 3\n"
    expect {
	-re "0.*$prompt$"	    { pass "$test" }
	timeout			    { fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test31

test "create-principal 32"
proc test32 {} {
    global test
    global prompt
    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle \
		[princ_w_pol "%s/a" test-pol] \
		{KADM5_PRINCIPAL KADM5_POLICY \
		KADM5_PW_EXPIRATION} NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    if { ! [cmd {kadm5_get_policy $server_handle test-pol policy}]} {
	error_and_restart "$test: cannot retrieve policy"
	return
    }

    send "lindex \$principal 6\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" {set mod_date $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting mod_date"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting mod_date"
	    return
	}
    }

    send "lindex \$principal 3\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" {set pw_expire $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting pw_expire"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting pw_expire"
	    return
	}
    }

    send "lindex \$policy 2\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" {set pw_max_life $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting pw_max_life"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting pw_max_life"
	    return
	}
    }
    if { $pw_expire != 0 } {
	fail "$test: pw_expire $pw_expire should be 0"
	return
    } else {
	pass "$test"
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test32

test "create-principal 33"
proc test33 {} {
    global test
    global prompt

    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle \
		{"%s/a" 0 0 1234 0 null 0 0 0 0 null 0} \
		{KADM5_PRINCIPAL KADM5_PW_EXPIRATION} \
		NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    send "lindex \$principal 3\n"
    expect {
	-re "1234.*$prompt$"	    { pass "$test" }
	timeout			    { fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test33

test "create-principal 34"
proc test34 {} {
    global test
    global prompt

    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle \
		{ "%s/a" 0 0 1234 0 null 0 0 0 0 test-pol-nopw 0} \
		{KADM5_PRINCIPAL KADM5_POLICY \
		KADM5_PW_EXPIRATION} NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    send "lindex \$principal 3\n"
    expect {
	-re "1234.*$prompt$"	    { pass "$test" }
	timeout			    { fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test34

test "create-principal 35"
proc test35 {} {
    global test
    global prompt

    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle \
		{"%s/a" 0 0 1234 0 null 0 0 0 0 test-pol 0} \
		{KADM5_PRINCIPAL KADM5_POLICY \
		KADM5_PW_EXPIRATION} NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    send "lindex \$principal 3\n"
    expect {
	-re "1234.*$prompt$"	    { pass "$test" }
	timeout			    { fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test35

test "create-principal 36"
proc test36 {} {
    global test
    global prompt
    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle \
		{"%s/a" 0 0 999999999 0 null 0 0 0 0 test-pol 0} \
		{KADM5_PRINCIPAL KADM5_POLICY \
		KADM5_PW_EXPIRATION} NotinTheDictionary
    } $test]]} {    
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    if { ! [cmd {kadm5_get_policy $server_handle test-pol policy} ]} {
	error_and_restart "$test: cannot retrieve policy"
	return
    }

    send "lindex \$principal 6\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" {set mod_date $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting mod_date"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting mod_date"
	    return
	}
    }

    send "lindex \$principal 3\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" {set pw_expire $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting pw_expire"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting pw_expire"
	    return
	}
    }

    send "lindex \$policy 2\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" {set pw_max_life $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting pw_max_life"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting pw_max_life"
	    return
	}
    }
    if { $pw_expire != 999999999 } {
	fail "$test: pw_expire is wrong"
	return
    } else {
	pass "$test"
    }

    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test36

test "create-principal 37"
proc test37 {} {
    global test
    global prompt

    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL} NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    send "lindex \$principal 3\n"
    expect {
	-re "0.*$prompt$"	    { pass "$test" }
	timeout			    { fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test37

test "create-principal 38"
proc test38 {} {
    global test
    global prompt
    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle [princ_w_pol "%s/a" \
		test-pol-nopw] {KADM5_PRINCIPAL KADM5_POLICY} \
		NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    send "lindex \$principal 3\n"
    expect {
	-re "0.*$prompt$"	    { pass "$test" }
	timeout			    { fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test38

test "create-principal 39"
proc test39 {} {
    global test
    global prompt
    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle [princ_w_pol "%s/a" \
		test-pol] {KADM5_PRINCIPAL KADM5_POLICY} \
		NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if { ! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	error_and_restart "$test: cannot not retrieve principal"
	return
    }
    if { ! [cmd {kadm5_get_policy $server_handle test-pol policy}]} {
	error_and_restart "$test: cannot retrieve policy"
	return
    }
    send "lindex \$principal 6\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" {set mod_date $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting mod_date"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting mod_date"
	    return
	}
    }

    send "lindex \$principal 3\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" {set pw_expire $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting pw_expire"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting pw_expire"
	    return
	}
    }

    send "lindex \$policy 2\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" {set pw_max_life $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting pw_max_life"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting pw_max_life"
	    return
	}
    }
    if { [expr "$mod_date + $pw_max_life - $pw_expire"] > 5 } {
	fail "$test: pw_expire is wrong"
	return
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test39

test "create-principal 40"
proc test40 {} {
    global test
    global prompt
    
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle [simple_principal "%s/a"] \
		{KADM5_PRINCIPAL KADM5_PW_EXPIRATION} \
		NotinTheDictionary
    } $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if {! [cmd [format {
	kadm5_get_principal $server_handle "%s/a" principal KADM5_PRINCIPAL_NORMAL_MASK
    } $test]]} {
	fail "$test: can not retreive principal"
	return;
    }
    send "lindex \$principal 4\n"
    expect {
	-re "0.*$prompt$"	    { pass "$test" }
	timeout			    { fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test40

test "create-principal 43"
proc test43 {} {
    global test
    one_line_fail_test [format {
	kadm5_create_principal null \
		    [simple_principal "%s/a"] {KADM5_PRINCIPAL} "%s/a"
    } $test $test] "BAD_SERVER_HANDLE"
}
test43

return ""
