]> andersk Git - moira.git/blob - incremental/ksrvtgt.c
Code style cleanup. (No functional changes)
[moira.git] / incremental / ksrvtgt.c
1 /*
2  * $Source$
3  * $Author$
4  *
5  * Copyright 1988 by the Massachusetts Institute of Technology.
6  *
7  * For copying and distribution information, please see the file
8  * <mit-copyright.h>.
9  *
10  * Get a ticket-granting-ticket given a service key file (srvtab)
11  * Modifed from the regular kerberos distribution in that it accepts
12  * the lifetime of the ticket as an command-line argument.
13  *
14  */
15
16 #include <stdio.h>
17 #include <sys/param.h>
18 #include <krb.h>
19 /*#include <conf.h>*/
20
21 char rcsid[] =
22     "$Header$";
23
24
25 void usage(char **argv)
26 {
27   fprintf(stderr,
28           "Usage: %s name instance [-r realm] [-s srvtab] [-l lifetime]\n",
29           argv[0]);
30   exit(1);
31 }
32
33
34 int main(int argc, char **argv)
35 {
36   char realm[REALM_SZ + 1];
37   register int code;
38   int i, lifetime = 1;
39   char srvtab[MAXPATHLEN + 1];
40
41   memset(realm, 0, sizeof(realm));
42   memset(srvtab, 0, sizeof(srvtab));
43
44   if (argc < 3)
45     usage(argv);
46
47   for (i = 3; i < argc; i++)
48     {
49       if (argv[i][0] != '-')
50         usage(argv);
51       switch (argv[i][1])
52         {
53         case 'r':
54           if (i + 1 >= argc)
55             usage(argv);
56           strncpy(realm, argv[i++ + 1], sizeof(realm) - 1);
57           break;
58         case 's':
59           if (i + 1 >= argc)
60             usage(argv);
61           strncpy(srvtab, argv[i++ + 1], sizeof(srvtab) - 1);
62           break;
63         case 'l':
64           if (i + 1 >= argc)
65             usage(argv);
66           lifetime = atoi(argv[i++ + 1]);
67           if (lifetime < 5)
68             lifetime = 1;
69           else
70             lifetime /= 5;
71           if (lifetime > 255)
72             lifetime = 255;
73           break;
74         default:
75           usage(argv);
76         }
77     }
78
79   if (!*srvtab)
80     strcpy(srvtab, KEYFILE);
81
82   if (!*realm)
83     {
84       if (krb_get_lrealm(realm, 1) != KSUCCESS)
85         strcpy(realm, KRB_REALM);
86     }
87
88   code = krb_get_svc_in_tkt(argv[1], argv[2], realm,
89                             "krbtgt", realm, lifetime, srvtab);
90   if (code)
91     fprintf(stderr, "%s\n", krb_err_txt[code]);
92   exit(code);
93 }
94
This page took 0.040014 seconds and 5 git commands to generate.