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 39 #ifndef lint 40 static const char rcsid[] = 41 "$FreeBSD$"; 42 #endif /* not lint */ 43 44 #include <stdio.h> 45 #include <rpc/rpc.h> 46 #include <rpc/key_prot.h> 47 #include <sys/param.h> 48 #include <sys/cdefs.h> 49 #include <rpcsvc/yp.h> 50 #include "ypupdate_prot.h" 51 #include "ypupdated_extern.h" 52 #include "yp_extern.h" 53 #include "ypxfr_extern.h" 54 55 int children = 0; 56 int forked = 0; 57 58 /* 59 * Try to avoid spoofing: if a client chooses to use a very large 60 * window and then tries a bunch of randomly chosen encrypted timestamps, 61 * there's a chance he might stumble onto a valid combination. 62 * We therefore reject any RPCs with a window size larger than a preset 63 * value. 64 */ 65 #ifndef WINDOW 66 #define WINDOW (60*60) 67 #endif 68 69 static enum auth_stat 70 yp_checkauth(struct svc_req *svcreq) 71 { 72 struct authdes_cred *des_cred; 73 74 switch (svcreq->rq_cred.oa_flavor) { 75 case AUTH_DES: 76 des_cred = (struct authdes_cred *) svcreq->rq_clntcred; 77 if (des_cred->adc_fullname.window > WINDOW) { 78 yp_error("warning: client-specified window size \ 79 was too large -- possible spoof attempt"); 80 return(AUTH_BADCRED); 81 } 82 return(AUTH_OK); 83 break; 84 case AUTH_UNIX: 85 case AUTH_NONE: 86 yp_error("warning: client didn't use DES authentication"); 87 return(AUTH_TOOWEAK); 88 break; 89 default: 90 yp_error("client used unknown auth flavor"); 91 return(AUTH_REJECTEDCRED); 92 break; 93 } 94 } 95 96 unsigned int * 97 ypu_change_1_svc(struct ypupdate_args *args, 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 * 131 ypu_insert_1_svc(struct ypupdate_args *args, struct svc_req *svcreq) 132 { 133 struct authdes_cred *des_cred; 134 static int res; 135 char *netname; 136 enum auth_stat astat; 137 138 res = 0; 139 140 astat = yp_checkauth(svcreq); 141 142 if (astat != AUTH_OK) { 143 svcerr_auth(svcreq->rq_xprt, astat); 144 return(&res); 145 } 146 147 des_cred = (struct authdes_cred *) svcreq->rq_clntcred; 148 netname = des_cred->adc_fullname.name; 149 150 res = localupdate(netname, "/etc/publickey", YPOP_INSERT, 151 args->key.yp_buf_len, args->key.yp_buf_val, 152 args->datum.yp_buf_len, args->datum.yp_buf_val); 153 154 if (res) 155 return (&res); 156 157 res = ypmap_update(netname, args->mapname, YPOP_INSERT, 158 args->key.yp_buf_len, args->key.yp_buf_val, 159 args->datum.yp_buf_len, args->datum.yp_buf_val); 160 161 return (&res); 162 } 163 164 unsigned int * 165 ypu_delete_1_svc(struct ypdelete_args *args, struct svc_req *svcreq) 166 { 167 struct authdes_cred *des_cred; 168 static int res; 169 char *netname; 170 enum auth_stat astat; 171 172 res = 0; 173 174 astat = yp_checkauth(svcreq); 175 176 if (astat != AUTH_OK) { 177 svcerr_auth(svcreq->rq_xprt, astat); 178 return(&res); 179 } 180 181 des_cred = (struct authdes_cred *) svcreq->rq_clntcred; 182 netname = des_cred->adc_fullname.name; 183 184 res = localupdate(netname, "/etc/publickey", YPOP_DELETE, 185 args->key.yp_buf_len, args->key.yp_buf_val, 186 0, NULL); 187 188 if (res) 189 return (&res); 190 191 res = ypmap_update(netname, args->mapname, YPOP_DELETE, 192 args->key.yp_buf_len, args->key.yp_buf_val, 193 0, NULL); 194 195 return (&res); 196 } 197 198 unsigned int * 199 ypu_store_1_svc(struct ypupdate_args *args, struct svc_req *svcreq) 200 { 201 struct authdes_cred *des_cred; 202 static int res; 203 char *netname; 204 enum auth_stat astat; 205 206 res = 0; 207 208 astat = yp_checkauth(svcreq); 209 210 if (astat != AUTH_OK) { 211 svcerr_auth(svcreq->rq_xprt, astat); 212 return(&res); 213 } 214 215 des_cred = (struct authdes_cred *) svcreq->rq_clntcred; 216 netname = des_cred->adc_fullname.name; 217 218 res = localupdate(netname, "/etc/publickey", YPOP_STORE, 219 args->key.yp_buf_len, args->key.yp_buf_val, 220 args->datum.yp_buf_len, args->datum.yp_buf_val); 221 222 if (res) 223 return (&res); 224 225 res = ypmap_update(netname, args->mapname, YPOP_STORE, 226 args->key.yp_buf_len, args->key.yp_buf_val, 227 args->datum.yp_buf_len, args->datum.yp_buf_val); 228 229 return (&res); 230 } 231