fd8ec1d8aba9257000c4b5d5188d7c3f096b363b
[openafs.git] / src / sia / test-reauth.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /* test-reauth.c - test SIA reauthorization code. */
11
12 #include <afsconfig.h>
13 #include <afs/param.h>
14
15 RCSID
16     ("$Header$");
17
18 #include <afs/stds.h>
19 #include <stdio.h>
20 #include <sgtty.h>
21 #include <utmp.h>
22 #include <signal.h>
23 #include <errno.h>
24 #include <ttyent.h>
25 #include <syslog.h>
26 #include <grp.h>
27 #include <pwd.h>
28 #include <setjmp.h>
29 #include <stdio.h>
30 #include <strings.h>
31 #include <lastlog.h>
32 #include <paths.h>
33
34 #include <sia.h>
35 #include <siad.h>
36
37
38 char *
39 sia_code_string(int code)
40 {
41     static char err_string[64];
42
43     switch (code) {
44     case SIADSUCCESS:
45         return "SIADSUCCESS";
46     case SIAFAIL:
47         return "SIAFAIL";
48     case SIASTOP:
49         return "SIASTOP";
50     default:
51         (void)sprintf(err_string, "Unknown error %d\n", code);
52         return err_string;
53     }
54 }
55
56 main(int ac, char **av)
57 {
58     char *username;
59     SIAENTITY *entity = NULL;
60     int (*sia_collect) () = sia_collect_trm;
61     int code;
62
63
64     if (ac != 2) {
65         printf("Usage: test-reauth user-name\n");
66         exit(1);
67     }
68     username = av[1];
69
70     code = sia_ses_init(&entity, ac, av, NULL, username, NULL, 1, NULL);
71     if (code != SIASUCCESS) {
72         printf("sia_ses_init failed with code %s\n", sia_code_string(code));
73         sia_ses_release(&entity);
74         exit(1);
75     }
76
77     code = sia_ses_reauthent(sia_collect, entity);
78     if (code != SIASUCCESS) {
79         printf("sia_ses_reauthent failed with code %s\n",
80                sia_code_string(code));
81         sia_ses_release(&entity);
82         exit(1);
83     }
84
85     code = sia_ses_release(&entity);
86     if (code != SIASUCCESS) {
87         printf("sia_ses_release failed with code %s\n",
88                sia_code_string(code));
89         exit(1);
90     }
91
92     printf("Password verified.\n");
93
94     exit(0);
95
96 }