1 /* 2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 #pragma ident "%Z%%M% %I% %E% SMI" 7 8 /* 9 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 10 * 11 * Openvision retains the copyright to derivative works of 12 * this source code. Do *NOT* create a derivative of this 13 * source code before consulting with your legal department. 14 * Do *NOT* integrate *ANY* of this source code into another 15 * product before consulting with your legal department. 16 * 17 * For further information, read the top-level Openvision 18 * copyright which is contained in the top-level MIT Kerberos 19 * copyright. 20 * 21 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 22 * 23 */ 24 25 26 /* 27 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved. 28 * 29 * $Id: kadm_rpc_svc.c,v 1.16 2000/02/19 02:05:52 tlyu Exp $ 30 * 31 */ 32 33 #if !defined(lint) && !defined(__CODECENTER__) 34 static char *rcsid = "$Header: /cvs/krbdev/krb5/src/kadmin/server/kadm_rpc_svc.c,v 1.16 2000/02/19 02:05:52 tlyu Exp $"; 35 #endif 36 37 #include <stdio.h> 38 #include <rpc/rpc.h> /* SUNWresync 121 XXX */ 39 #include <gssapi_krb5.h> /* for gss_nt_krb5_name */ 40 #include <syslog.h> 41 #ifdef HAVE_MEMORY_H 42 #include <memory.h> 43 #endif 44 #include <rpc/rpcsec_gss.h> 45 #include <kadm5/kadm_rpc.h> 46 #include <krb5.h> 47 #include <kadm5/admin.h> 48 #include <libintl.h> 49 #include <krb5/adm_proto.h> 50 #ifdef HAVE_ARPA_INET_H 51 #include <arpa/inet.h> 52 #endif 53 #include "misc.h" 54 #include "kadm5/server_internal.h" 55 56 extern void *global_server_handle; 57 58 void log_badauth(OM_uint32 major, OM_uint32 minor, 59 struct sockaddr_in *addr, char *data); 60 /* 61 * Function: kadm_1 62 * 63 * Purpose: RPC proccessing procedure. 64 * originally generated from rpcgen 65 * 66 * Arguments: 67 * rqstp (input) rpc request structure 68 * transp (input) rpc transport structure 69 * (input/output) 70 * <return value> 71 * 72 * Requires: 73 * Effects: 74 * Modifies: 75 */ 76 77 void kadm_1(rqstp, transp) 78 struct svc_req *rqstp; 79 register SVCXPRT *transp; 80 { 81 union { 82 cprinc_arg create_principal_1_arg; 83 dprinc_arg delete_principal_1_arg; 84 mprinc_arg modify_principal_1_arg; 85 rprinc_arg rename_principal_1_arg; 86 gprinc_arg get_principal_1_arg; 87 chpass_arg chpass_principal_1_arg; 88 chrand_arg chrand_principal_1_arg; 89 cpol_arg create_policy_1_arg; 90 dpol_arg delete_policy_1_arg; 91 mpol_arg modify_policy_1_arg; 92 gpol_arg get_policy_1_arg; 93 setkey_arg setkey_principal_1_arg; 94 setv4key_arg setv4key_principal_1_arg; 95 cprinc3_arg create_principal3_1_arg; 96 chpass3_arg chpass_principal3_1_arg; 97 chrand3_arg chrand_principal3_1_arg; 98 setkey3_arg setkey_principal3_1_arg; 99 } argument; 100 char *result; 101 bool_t (*xdr_argument)(), (*xdr_result)(); 102 char *(*local)(); 103 104 if (rqstp->rq_cred.oa_flavor != RPCSEC_GSS) { 105 krb5_klog_syslog(LOG_ERR, 106 gettext("Authentication attempt failed: invalid " 107 "RPC authentication flavor %d"), 108 rqstp->rq_cred.oa_flavor); 109 svcerr_weakauth(transp); 110 return; 111 } 112 113 switch (rqstp->rq_proc) { 114 case NULLPROC: 115 (void) svc_sendreply(transp, xdr_void, (char *)NULL); 116 return; 117 118 case CREATE_PRINCIPAL: 119 xdr_argument = xdr_cprinc_arg; 120 xdr_result = xdr_generic_ret; 121 local = (char *(*)()) create_principal_1_svc; 122 break; 123 124 case DELETE_PRINCIPAL: 125 xdr_argument = xdr_dprinc_arg; 126 xdr_result = xdr_generic_ret; 127 local = (char *(*)()) delete_principal_1_svc; 128 break; 129 130 case MODIFY_PRINCIPAL: 131 xdr_argument = xdr_mprinc_arg; 132 xdr_result = xdr_generic_ret; 133 local = (char *(*)()) modify_principal_1_svc; 134 break; 135 136 case RENAME_PRINCIPAL: 137 xdr_argument = xdr_rprinc_arg; 138 xdr_result = xdr_generic_ret; 139 local = (char *(*)()) rename_principal_1_svc; 140 break; 141 142 case GET_PRINCIPAL: 143 xdr_argument = xdr_gprinc_arg; 144 xdr_result = xdr_gprinc_ret; 145 local = (char *(*)()) get_principal_1_svc; 146 break; 147 148 case GET_PRINCS: 149 xdr_argument = xdr_gprincs_arg; 150 xdr_result = xdr_gprincs_ret; 151 local = (char *(*)()) get_princs_1_svc; 152 break; 153 154 case CHPASS_PRINCIPAL: 155 xdr_argument = xdr_chpass_arg; 156 xdr_result = xdr_generic_ret; 157 local = (char *(*)()) chpass_principal_1_svc; 158 break; 159 160 #ifdef SUNWOFF 161 case SETV4KEY_PRINCIPAL: 162 xdr_argument = xdr_setv4key_arg; 163 xdr_result = xdr_generic_ret; 164 local = (char *(*)()) setv4key_principal_1_svc; 165 break; 166 #endif 167 168 case SETKEY_PRINCIPAL: 169 xdr_argument = xdr_setkey_arg; 170 xdr_result = xdr_generic_ret; 171 local = (char *(*)()) setkey_principal_1_svc; 172 break; 173 174 case CHRAND_PRINCIPAL: 175 xdr_argument = xdr_chrand_arg; 176 xdr_result = xdr_chrand_ret; 177 local = (char *(*)()) chrand_principal_1_svc; 178 break; 179 180 case CREATE_POLICY: 181 xdr_argument = xdr_cpol_arg; 182 xdr_result = xdr_generic_ret; 183 local = (char *(*)()) create_policy_1_svc; 184 break; 185 186 case DELETE_POLICY: 187 xdr_argument = xdr_dpol_arg; 188 xdr_result = xdr_generic_ret; 189 local = (char *(*)()) delete_policy_1_svc; 190 break; 191 192 case MODIFY_POLICY: 193 xdr_argument = xdr_mpol_arg; 194 xdr_result = xdr_generic_ret; 195 local = (char *(*)()) modify_policy_1_svc; 196 break; 197 198 case GET_POLICY: 199 xdr_argument = xdr_gpol_arg; 200 xdr_result = xdr_gpol_ret; 201 local = (char *(*)()) get_policy_1_svc; 202 break; 203 204 case GET_POLS: 205 xdr_argument = xdr_gpols_arg; 206 xdr_result = xdr_gpols_ret; 207 local = (char *(*)()) get_pols_1_svc; 208 break; 209 210 case GET_PRIVS: 211 xdr_argument = xdr_u_int; 212 xdr_result = xdr_getprivs_ret; 213 local = (char *(*)()) get_privs_1_svc; 214 break; 215 216 case INIT: 217 xdr_argument = xdr_u_int; 218 xdr_result = xdr_generic_ret; 219 local = (char *(*)()) init_1_svc; 220 break; 221 222 case CREATE_PRINCIPAL3: 223 xdr_argument = xdr_cprinc3_arg; 224 xdr_result = xdr_generic_ret; 225 local = (char *(*)()) create_principal3_1_svc; 226 break; 227 228 case CHPASS_PRINCIPAL3: 229 xdr_argument = xdr_chpass3_arg; 230 xdr_result = xdr_generic_ret; 231 local = (char *(*)()) chpass_principal3_1_svc; 232 break; 233 234 case CHRAND_PRINCIPAL3: 235 xdr_argument = xdr_chrand3_arg; 236 xdr_result = xdr_chrand_ret; 237 local = (char *(*)()) chrand_principal3_1_svc; 238 break; 239 240 case SETKEY_PRINCIPAL3: 241 xdr_argument = xdr_setkey3_arg; 242 xdr_result = xdr_generic_ret; 243 local = (char *(*)()) setkey_principal3_1_svc; 244 break; 245 246 default: 247 krb5_klog_syslog(LOG_ERR, 248 gettext("Invalid KADM5 procedure number: %d"), 249 rqstp->rq_proc); 250 svcerr_noproc(transp); 251 return; 252 } 253 memset((char *)&argument, 0, sizeof(argument)); 254 if (!svc_getargs(transp, xdr_argument, (char *) &argument)) { 255 svcerr_decode(transp); 256 return; 257 } 258 result = (*local)(&argument, rqstp); 259 if (result != NULL && !svc_sendreply(transp, xdr_result, (char *) result)) { 260 krb5_klog_syslog(LOG_ERR, 261 gettext("WARNING! Unable to send function results, " 262 "continuing.")); 263 svcerr_systemerr(transp); 264 } 265 if (!svc_freeargs(transp, xdr_argument, (char *) &argument)) { 266 krb5_klog_syslog(LOG_ERR, 267 gettext("WARNING! Unable to free arguments, " 268 "continuing.")); 269 } 270 return; 271 } 272