Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.sbin / rpc.ypupdated / ypupdated_server.c
1 /*
2  * Copyright (c) 1995, 1996
3  *      Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Bill Paul.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * ypupdate server implementation
33  *
34  * Written by Bill Paul <wpaul@ctr.columbia.edu>
35  * Center for Telecommunications Research
36  * Columbia University, New York City
37  *
38  * $FreeBSD: src/usr.sbin/rpc.ypupdated/ypupdated_server.c,v 1.3.2.1 2002/02/15 00:46:58 des Exp $
39  * $DragonFly: src/usr.sbin/rpc.ypupdated/ypupdated_server.c,v 1.2 2003/06/17 04:30:02 dillon Exp $
40  */
41
42 #include <stdio.h>
43 #include <rpc/rpc.h>
44 #include <rpc/auth_des.h>
45 #include <rpc/key_prot.h>
46 #include <sys/param.h>
47 #include <sys/cdefs.h>
48 #include <rpcsvc/yp.h>
49 #include "ypupdate_prot.h"
50 #include "ypupdated_extern.h"
51 #include "yp_extern.h"
52 #include "ypxfr_extern.h"
53
54 int children = 0;
55 int forked = 0;
56
57 /*
58  * Try to avoid spoofing: if a client chooses to use a very large
59  * window and then tries a bunch of randomly chosen encrypted timestamps,
60  * there's a chance he might stumble onto a valid combination.
61  * We therefore reject any RPCs with a window size larger than a preset
62  * value.
63  */
64 #ifndef WINDOW
65 #define WINDOW (60*60)
66 #endif
67
68 static enum auth_stat yp_checkauth(svcreq)
69         struct svc_req *svcreq;
70 {
71         struct authdes_cred *des_cred;
72
73         switch (svcreq->rq_cred.oa_flavor) {
74         case AUTH_DES:
75                 des_cred = (struct authdes_cred *) svcreq->rq_clntcred;
76                 if (des_cred->adc_fullname.window > WINDOW) {
77                         yp_error("warning: client-specified window size \
78 was too large -- possible spoof attempt");
79                         return(AUTH_BADCRED);
80                 }
81                 return(AUTH_OK);
82                 break;
83         case AUTH_UNIX:
84         case AUTH_NONE:
85                 yp_error("warning: client didn't use DES authentication");
86                 return(AUTH_TOOWEAK);
87                 break;
88         default:
89                 yp_error("client used unknown auth flavor");
90                 return(AUTH_REJECTEDCRED);
91                 break;
92         }
93 }
94
95 unsigned int *ypu_change_1_svc(args, svcreq)
96         struct ypupdate_args *args;
97         struct svc_req *svcreq;
98 {
99         struct authdes_cred *des_cred;
100         static int res;
101         char *netname;
102         enum auth_stat astat;
103
104         res = 0;
105
106         astat = yp_checkauth(svcreq);
107
108         if (astat != AUTH_OK) {
109                 svcerr_auth(svcreq->rq_xprt, astat);
110                 return(&res);
111         }
112
113         des_cred = (struct authdes_cred *) svcreq->rq_clntcred;
114         netname = des_cred->adc_fullname.name;
115
116         res = localupdate(netname, "/etc/publickey", YPOP_CHANGE,
117                 args->key.yp_buf_len, args->key.yp_buf_val,
118                 args->datum.yp_buf_len, args->datum.yp_buf_val);
119
120         if (res)
121                 return (&res);
122
123         res = ypmap_update(netname, args->mapname, YPOP_CHANGE,
124                 args->key.yp_buf_len, args->key.yp_buf_val,
125                 args->datum.yp_buf_len, args->datum.yp_buf_val);
126
127         return (&res);
128 }
129
130 unsigned int *ypu_insert_1_svc(args, svcreq)
131         struct ypupdate_args *args;
132         struct svc_req *svcreq;
133 {
134         struct authdes_cred *des_cred;
135         static int res;
136         char *netname;
137         enum auth_stat astat;
138
139         res = 0;
140
141         astat = yp_checkauth(svcreq);
142
143         if (astat != AUTH_OK) {
144                 svcerr_auth(svcreq->rq_xprt, astat);
145                 return(&res);
146         }
147
148         des_cred = (struct authdes_cred *) svcreq->rq_clntcred;
149         netname = des_cred->adc_fullname.name;
150
151         res = localupdate(netname, "/etc/publickey", YPOP_INSERT,
152                 args->key.yp_buf_len, args->key.yp_buf_val,
153                 args->datum.yp_buf_len, args->datum.yp_buf_val);
154
155         if (res)
156                 return (&res);
157
158         res = ypmap_update(netname, args->mapname, YPOP_INSERT,
159                 args->key.yp_buf_len, args->key.yp_buf_val,
160                 args->datum.yp_buf_len, args->datum.yp_buf_val);
161
162         return (&res);
163 }
164
165 unsigned int *ypu_delete_1_svc(args, svcreq)
166         struct ypdelete_args *args;
167         struct svc_req *svcreq;
168 {
169         struct authdes_cred *des_cred;
170         static int res;
171         char *netname;
172         enum auth_stat astat;
173
174         res = 0;
175
176         astat = yp_checkauth(svcreq);
177
178         if (astat != AUTH_OK) {
179                 svcerr_auth(svcreq->rq_xprt, astat);
180                 return(&res);
181         }
182
183         des_cred = (struct authdes_cred *) svcreq->rq_clntcred;
184         netname = des_cred->adc_fullname.name;
185
186         res = localupdate(netname, "/etc/publickey", YPOP_DELETE,
187                 args->key.yp_buf_len, args->key.yp_buf_val,
188                 0,                      NULL);
189
190         if (res)
191                 return (&res);
192
193         res = ypmap_update(netname, args->mapname, YPOP_DELETE,
194                 args->key.yp_buf_len, args->key.yp_buf_val,
195                 0,                      NULL);
196
197         return (&res);
198 }
199
200 unsigned int *ypu_store_1_svc(args, svcreq)
201         struct ypupdate_args *args;
202         struct svc_req *svcreq;
203 {
204         struct authdes_cred *des_cred;
205         static int res;
206         char *netname;
207         enum auth_stat astat;
208
209         res = 0;
210
211         astat = yp_checkauth(svcreq);
212
213         if (astat != AUTH_OK) {
214                 svcerr_auth(svcreq->rq_xprt, astat);
215                 return(&res);
216         }
217
218         des_cred = (struct authdes_cred *) svcreq->rq_clntcred;
219         netname = des_cred->adc_fullname.name;
220
221         res = localupdate(netname, "/etc/publickey", YPOP_STORE,
222                 args->key.yp_buf_len, args->key.yp_buf_val,
223                 args->datum.yp_buf_len, args->datum.yp_buf_val);
224
225         if (res)
226                 return (&res);
227
228         res = ypmap_update(netname, args->mapname, YPOP_STORE,
229                 args->key.yp_buf_len, args->key.yp_buf_val,
230                 args->datum.yp_buf_len, args->datum.yp_buf_val);
231
232         return (&res);
233 }