]> andersk Git - moira.git/blob - incremental/ksrvtgt.c
Command line printer manipulation client, and build goo.
[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 <stdlib.h>
18 #include <string.h>
19 #include <sys/param.h>
20 #include <krb.h>
21 /*#include <conf.h>*/
22
23 char rcsid[] =
24     "$Header$";
25
26 void usage(char **argv);
27
28 int main(int argc, char **argv)
29 {
30   char realm[REALM_SZ + 1];
31   int code;
32   int i, lifetime = 1;
33   char srvtab[MAXPATHLEN + 1];
34
35   memset(realm, 0, sizeof(realm));
36   memset(srvtab, 0, sizeof(srvtab));
37
38   if (argc < 3)
39     usage(argv);
40
41   for (i = 3; i < argc; i++)
42     {
43       if (argv[i][0] != '-')
44         usage(argv);
45       switch (argv[i][1])
46         {
47         case 'r':
48           if (i + 1 >= argc)
49             usage(argv);
50           strncpy(realm, argv[i++ + 1], sizeof(realm) - 1);
51           break;
52         case 's':
53           if (i + 1 >= argc)
54             usage(argv);
55           strncpy(srvtab, argv[i++ + 1], sizeof(srvtab) - 1);
56           break;
57         case 'l':
58           if (i + 1 >= argc)
59             usage(argv);
60           lifetime = atoi(argv[i++ + 1]);
61           if (lifetime < 5)
62             lifetime = 1;
63           else
64             lifetime /= 5;
65           if (lifetime > 255)
66             lifetime = 255;
67           break;
68         default:
69           usage(argv);
70         }
71     }
72
73   if (!*srvtab)
74     strcpy(srvtab, KEYFILE);
75
76   if (!*realm)
77     {
78       if (krb_get_lrealm(realm, 1) != KSUCCESS)
79         strcpy(realm, KRB_REALM);
80     }
81
82   code = krb_get_svc_in_tkt(argv[1], argv[2], realm,
83                             "krbtgt", realm, lifetime, srvtab);
84   if (code)
85     fprintf(stderr, "%s\n", krb_err_txt[code]);
86   exit(code);
87 }
88
89 void usage(char **argv)
90 {
91   fprintf(stderr,
92           "Usage: %s name instance [-r realm] [-s srvtab] [-l lifetime]\n",
93           argv[0]);
94   exit(1);
95 }
This page took 0.097393 seconds and 5 git commands to generate.