]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/gssd/gssd.c
Add gss support from citi @ umich
[nfs-utils.git] / utils / gssd / gssd.c
1 /*
2   gssd.c
3
4   Copyright (c) 2000 The Regents of the University of Michigan.
5   All rights reserved.
6
7   Copyright (c) 2000 Dug Song <dugsong@UMICH.EDU>.
8   Copyright (c) 2002 Andy Adamson <andros@UMICH.EDU>.
9   Copyright (c) 2002 Marius Aamodt Eriksen <marius@UMICH.EDU>.
10   All rights reserved, all wrongs reversed.
11
12   Redistribution and use in source and binary forms, with or without
13   modification, are permitted provided that the following conditions
14   are met:
15
16   1. Redistributions of source code must retain the above copyright
17      notice, this list of conditions and the following disclaimer.
18   2. Redistributions in binary form must reproduce the above copyright
19      notice, this list of conditions and the following disclaimer in the
20      documentation and/or other materials provided with the distribution.
21   3. Neither the name of the University nor the names of its
22      contributors may be used to endorse or promote products derived
23      from this software without specific prior written permission.
24
25   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28   DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32   BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
37 */
38
39 #include <sys/param.h>
40 #include <sys/socket.h>
41 #include <rpc/rpc.h>
42
43 #include <unistd.h>
44 #include <err.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <signal.h>
49 #include "gssd.h"
50 #include "err_util.h"
51 #include "gss_util.h"
52 #include "krb5_util.h"
53
54 char pipefsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
55 char keytabfile[PATH_MAX] = GSSD_DEFAULT_KEYTAB_FILE;
56
57 void
58 sig_die(int signal)
59 {
60         /* destroy krb5 machine creds */
61         gssd_destroy_krb5_machine_creds();
62         printerr(1, "exiting on signal %d\n", signal);
63         exit(1);
64 }
65
66 static void
67 usage(char *progname)
68 {
69         fprintf(stderr, "usage: %s [-f] [-v] [-p pipefsdir] [-k keytab]\n",
70                 progname);
71         exit(1);
72 }
73
74 int
75 main(int argc, char *argv[])
76 {
77         int fg = 0;
78         int verbosity = 0;
79         int opt;
80         extern char *optarg;
81         char *progname;
82
83         while ((opt = getopt(argc, argv, "fvmp:k:")) != -1) {
84                 switch (opt) {
85                         case 'f':
86                                 fg = 1;
87                                 break;
88                         case 'm':
89                                 /* Accept but ignore this. Now the default. */
90                                 break;
91                         case 'v':
92                                 verbosity++;
93                                 break;
94                         case 'p':
95                                 strncpy(pipefsdir, optarg, sizeof(pipefsdir));
96                                 if (pipefsdir[sizeof(pipefsdir)-1] != '\0')
97                                         errx(1, "pipefs path name too long");
98                                 break;
99                         case 'k':
100                                 strncpy(keytabfile, optarg, sizeof(keytabfile));
101                                 if (keytabfile[sizeof(keytabfile)-1] != '\0')
102                                         errx(1, "keytab path name too long");
103                                 break;
104                         default:
105                                 usage(argv[0]);
106                                 break;
107                 }
108         }
109         strncat(pipefsdir + strlen(pipefsdir), "/" GSSD_SERVICE_NAME,
110                 sizeof(pipefsdir)-strlen(pipefsdir));
111         if (pipefsdir[sizeof(pipefsdir)-1] != '\0')
112                 errx(1, "pipefs path name too long");
113
114         if ((progname = strrchr(argv[0], '/')))
115                 progname++;
116         else
117                 progname = argv[0];
118
119         initerr(progname, verbosity, fg);
120
121         if (!fg && daemon(0, 0) < 0)
122                 errx(1, "fork");
123
124         signal(SIGINT, sig_die);
125         signal(SIGTERM, sig_die);
126         signal(SIGHUP, sig_die);
127
128         /* Process keytab file and get machine credentials */
129         gssd_refresh_krb5_machine_creds();
130
131         gssd_run();
132         printerr(0, "gssd_run returned!\n");
133         abort();
134 }