Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nfs-utils / utils / gssd / gssd.c
blobf6949db72e10333571b78309684e0b8a8ef3c649
1 /*
2 gssd.c
4 Copyright (c) 2000 The Regents of the University of Michigan.
5 All rights reserved.
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.
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
14 are met:
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.
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.
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif /* HAVE_CONFIG_H */
43 #include <sys/param.h>
44 #include <sys/socket.h>
45 #include <rpc/rpc.h>
47 #include <unistd.h>
48 #include <err.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <signal.h>
53 #include "gssd.h"
54 #include "err_util.h"
55 #include "gss_util.h"
56 #include "krb5_util.h"
58 char pipefs_dir[PATH_MAX] = GSSD_PIPEFS_DIR;
59 char pipefs_nfsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
60 char keytabfile[PATH_MAX] = GSSD_DEFAULT_KEYTAB_FILE;
61 char ccachedir[PATH_MAX] = GSSD_DEFAULT_CRED_DIR;
62 char *ccachesearch[GSSD_MAX_CCACHE_SEARCH + 1];
63 int use_memcache = 0;
64 int root_uses_machine_creds = 1;
65 unsigned int context_timeout = 0;
66 char *preferred_realm = NULL;
68 void
69 sig_die(int signal)
71 /* destroy krb5 machine creds */
72 if (root_uses_machine_creds)
73 gssd_destroy_krb5_machine_creds();
74 printerr(1, "exiting on signal %d\n", signal);
75 exit(1);
78 void
79 sig_hup(int signal)
81 /* don't exit on SIGHUP */
82 printerr(1, "Received SIGHUP... Ignoring.\n");
83 return;
86 static void
87 usage(char *progname)
89 fprintf(stderr, "usage: %s [-f] [-M] [-n] [-v] [-r] [-p pipefsdir] [-k keytab] [-d ccachedir] [-t timeout] [-R preferred realm]\n",
90 progname);
91 exit(1);
94 int
95 main(int argc, char *argv[])
97 int fg = 0;
98 int verbosity = 0;
99 int rpc_verbosity = 0;
100 int opt;
101 int i;
102 extern char *optarg;
103 char *progname;
105 memset(ccachesearch, 0, sizeof(ccachesearch));
106 while ((opt = getopt(argc, argv, "fvrmnMp:k:d:t:R:")) != -1) {
107 switch (opt) {
108 case 'f':
109 fg = 1;
110 break;
111 case 'm':
112 /* Accept but ignore this. Now the default. */
113 break;
114 case 'M':
115 use_memcache = 1;
116 break;
117 case 'n':
118 root_uses_machine_creds = 0;
119 break;
120 case 'v':
121 verbosity++;
122 break;
123 case 'r':
124 rpc_verbosity++;
125 break;
126 case 'p':
127 strncpy(pipefs_dir, optarg, sizeof(pipefs_dir));
128 if (pipefs_dir[sizeof(pipefs_dir)-1] != '\0')
129 errx(1, "pipefs path name too long");
130 break;
131 case 'k':
132 strncpy(keytabfile, optarg, sizeof(keytabfile));
133 if (keytabfile[sizeof(keytabfile)-1] != '\0')
134 errx(1, "keytab path name too long");
135 break;
136 case 'd':
137 strncpy(ccachedir, optarg, sizeof(ccachedir));
138 if (ccachedir[sizeof(ccachedir)-1] != '\0')
139 errx(1, "ccachedir path name too long");
140 break;
141 case 't':
142 context_timeout = atoi(optarg);
143 break;
144 case 'R':
145 preferred_realm = strdup(optarg);
146 break;
147 default:
148 usage(argv[0]);
149 break;
153 i = 0;
154 ccachesearch[i++] = strtok(ccachedir, ":");
155 do {
156 ccachesearch[i++] = strtok(NULL, ":");
157 } while (ccachesearch[i-1] != NULL && i < GSSD_MAX_CCACHE_SEARCH);
159 if (preferred_realm == NULL)
160 gssd_k5_get_default_realm(&preferred_realm);
162 snprintf(pipefs_nfsdir, sizeof(pipefs_nfsdir), "%s/%s",
163 pipefs_dir, GSSD_SERVICE_NAME);
164 if (pipefs_nfsdir[sizeof(pipefs_nfsdir)-1] != '\0')
165 errx(1, "pipefs_nfsdir path name too long");
167 if ((progname = strrchr(argv[0], '/')))
168 progname++;
169 else
170 progname = argv[0];
172 initerr(progname, verbosity, fg);
173 #ifdef HAVE_AUTHGSS_SET_DEBUG_LEVEL
174 authgss_set_debug_level(rpc_verbosity);
175 #else
176 if (rpc_verbosity > 0)
177 printerr(0, "Warning: rpcsec_gss library does not "
178 "support setting debug level\n");
179 #endif
181 if (gssd_check_mechs() != 0)
182 errx(1, "Problem with gssapi library");
184 if (!fg && daemon(0, 0) < 0)
185 errx(1, "fork");
187 signal(SIGINT, sig_die);
188 signal(SIGTERM, sig_die);
189 signal(SIGHUP, sig_hup);
191 gssd_run();
192 printerr(0, "gssd_run returned!\n");
193 abort();