1 /* $OpenBSD: lockd.c,v 1.7 2003/07/06 21:26:14 deraadt Exp $ */
2
3 /*
4 * Copyright (c) 1995
5 * A.R. Gordon (andrew.gordon@net-tel.co.uk). All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the FreeBSD project
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY ANDREW GORDON AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 */
35
36 #include <sys/param.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <rpc/rpc.h>
40 #include <rpc/pmap_clnt.h>
41 #include <rpcsvc/sm_inter.h>
42 #include "nlm_prot.h"
43 #include <arpa/inet.h>
44 #include <stdio.h>
45 #include <syslog.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <netdb.h>
49
50 #include "lockd.h"
51
52 extern void nlm_prog_1(struct svc_req *, SVCXPRT *);
53 extern void nlm_prog_3(struct svc_req *, SVCXPRT *);
54
55 int debug_level = 0; /* Zero means no debugging syslog() calls */
56
57 int _rpcsvcdirty;
58
59 int
main(int argc,char * argv[])60 main(int argc, char *argv[])
61 {
62 SVCXPRT *transp;
63
64 if (argc > 1) {
65 if (strncmp(argv[1], "-d", 2)) {
66 fprintf(stderr, "Usage: rpc.lockd [-d debuglevel]\n");
67 exit(1);
68 }
69 if (argc > 2)
70 debug_level = atoi(argv[2]);
71 else
72 debug_level = atoi(argv[1] + 2);
73 if (!debug_level)
74 debug_level = 1;
75 }
76 (void) pmap_unset(NLM_PROG, NLM_VERS);
77 (void) pmap_unset(NLM_PROG, NLM_VERSX);
78
79 transp = svcudp_create(RPC_ANYSOCK);
80 if (transp == NULL) {
81 fprintf(stderr, "cannot create udp service.\n");
82 exit(1);
83 }
84 if (!svc_register(transp, NLM_PROG, NLM_VERS,
85 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_1, IPPROTO_UDP)) {
86 fprintf(stderr, "unable to register (NLM_PROG, NLM_VERS, udp).\n");
87 exit(1);
88 }
89 if (!svc_register(transp, NLM_PROG, NLM_VERSX,
90 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_3, IPPROTO_UDP)) {
91 fprintf(stderr, "unable to register (NLM_PROG, NLM_VERSX, udp).\n");
92 exit(1);
93 }
94 transp = svctcp_create(RPC_ANYSOCK, 0, 0);
95 if (transp == NULL) {
96 fprintf(stderr, "cannot create tcp service.\n");
97 exit(1);
98 }
99 if (!svc_register(transp, NLM_PROG, NLM_VERS,
100 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_1, IPPROTO_TCP)) {
101 fprintf(stderr, "unable to register (NLM_PROG, NLM_VERS, tcp).\n");
102 exit(1);
103 }
104 if (!svc_register(transp, NLM_PROG, NLM_VERSX,
105 (void (*) (struct svc_req *, SVCXPRT *)) nlm_prog_3, IPPROTO_TCP)) {
106 fprintf(stderr, "unable to register (NLM_PROG, NLM_VERSX, tcp).\n");
107 exit(1);
108 }
109
110 if (daemon(0, 0)) {
111 perror("cannot fork");
112 exit(1);
113 }
114 openlog("rpc.lockd", 0, LOG_DAEMON);
115 if (debug_level)
116 syslog(LOG_INFO, "Starting, debug level %d", debug_level);
117 else
118 syslog(LOG_INFO, "Starting");
119
120 svc_run();
121 exit(1);
122 }
123