10Sstevel@tonic-gate /* 2*2881Smp153739 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 30Sstevel@tonic-gate * Use is subject to license terms. 40Sstevel@tonic-gate */ 50Sstevel@tonic-gate 60Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 70Sstevel@tonic-gate 80Sstevel@tonic-gate 90Sstevel@tonic-gate #include <stdio.h> 100Sstevel@tonic-gate #include <stdlib.h> /* getenv, exit */ 110Sstevel@tonic-gate #include <signal.h> 120Sstevel@tonic-gate #include <sys/types.h> 130Sstevel@tonic-gate #include <memory.h> 140Sstevel@tonic-gate #include <stropts.h> 150Sstevel@tonic-gate #include <netconfig.h> 160Sstevel@tonic-gate #include <sys/resource.h> /* rlimit */ 170Sstevel@tonic-gate #include <syslog.h> 180Sstevel@tonic-gate 190Sstevel@tonic-gate #include <kadm5/admin.h> 200Sstevel@tonic-gate #include <kadm5/kadm_rpc.h> 210Sstevel@tonic-gate #include <kadm5/server_internal.h> 220Sstevel@tonic-gate #include <server_acl.h> 230Sstevel@tonic-gate #include <krb5/adm_proto.h> 240Sstevel@tonic-gate #include <string.h> 250Sstevel@tonic-gate #include <gssapi_krb5.h> 260Sstevel@tonic-gate #include <sys/socket.h> 270Sstevel@tonic-gate #include <netinet/in.h> 280Sstevel@tonic-gate #include <arpa/inet.h> 290Sstevel@tonic-gate #include <netdb.h> 300Sstevel@tonic-gate #include <libintl.h> 310Sstevel@tonic-gate #include <kdb/kdb_log.h> 320Sstevel@tonic-gate #include "misc.h" 330Sstevel@tonic-gate 340Sstevel@tonic-gate 350Sstevel@tonic-gate 360Sstevel@tonic-gate extern int setup_gss_names(struct svc_req *, char **, char **); 370Sstevel@tonic-gate extern gss_name_t get_clnt_name(struct svc_req *); 380Sstevel@tonic-gate extern char *client_addr(struct svc_req *, char *); 390Sstevel@tonic-gate extern void *global_server_handle; 400Sstevel@tonic-gate extern int nofork; 410Sstevel@tonic-gate extern short l_port; 420Sstevel@tonic-gate static char abuf[33]; 430Sstevel@tonic-gate 440Sstevel@tonic-gate static char *reply_ok_str = "UPDATE_OK"; 450Sstevel@tonic-gate static char *reply_err_str = "UPDATE_ERROR"; 460Sstevel@tonic-gate static char *reply_fr_str = "UPDATE_FULL_RESYNC_NEEDED"; 470Sstevel@tonic-gate static char *reply_busy_str = "UPDATE_BUSY"; 480Sstevel@tonic-gate static char *reply_nil_str = "UPDATE_NIL"; 490Sstevel@tonic-gate static char *reply_perm_str = "UPDATE_PERM_DENIED"; 500Sstevel@tonic-gate static char *reply_unknown_str = "<UNKNOWN_CODE>"; 510Sstevel@tonic-gate 520Sstevel@tonic-gate #define LOG_UNAUTH gettext("Unauthorized request: %s, %s, " \ 530Sstevel@tonic-gate "client=%s, service=%s, addr=%s") 540Sstevel@tonic-gate #define LOG_DONE gettext("Request: %s, %s, %s, client=%s, " \ 550Sstevel@tonic-gate "service=%s, addr=%s") 560Sstevel@tonic-gate 570Sstevel@tonic-gate #define KDB5_UTIL_DUMP_STR "/usr/sbin/kdb5_util dump -i " 580Sstevel@tonic-gate 590Sstevel@tonic-gate #ifdef DPRINT 600Sstevel@tonic-gate #undef DPRINT 610Sstevel@tonic-gate #endif 620Sstevel@tonic-gate #define DPRINT(i) if (nofork) printf i 630Sstevel@tonic-gate 640Sstevel@tonic-gate 650Sstevel@tonic-gate static void 660Sstevel@tonic-gate debprret(char *w, update_status_t ret, kdb_sno_t sno) 670Sstevel@tonic-gate { 680Sstevel@tonic-gate switch (ret) { 690Sstevel@tonic-gate case UPDATE_OK: 700Sstevel@tonic-gate printf("%s: end (OK, sno=%u)\n", 710Sstevel@tonic-gate w, sno); 720Sstevel@tonic-gate break; 730Sstevel@tonic-gate case UPDATE_ERROR: 740Sstevel@tonic-gate printf("%s: end (ERROR)\n", w); 750Sstevel@tonic-gate break; 760Sstevel@tonic-gate case UPDATE_FULL_RESYNC_NEEDED: 770Sstevel@tonic-gate printf("%s: end (FR NEEDED)\n", w); 780Sstevel@tonic-gate break; 790Sstevel@tonic-gate case UPDATE_BUSY: 800Sstevel@tonic-gate printf("%s: end (BUSY)\n", w); 810Sstevel@tonic-gate break; 820Sstevel@tonic-gate case UPDATE_NIL: 830Sstevel@tonic-gate printf("%s: end (NIL)\n", w); 840Sstevel@tonic-gate break; 850Sstevel@tonic-gate case UPDATE_PERM_DENIED: 860Sstevel@tonic-gate printf("%s: end (PERM)\n", w); 870Sstevel@tonic-gate break; 880Sstevel@tonic-gate default: 890Sstevel@tonic-gate printf("%s: end (UNKNOWN return code (%d))\n", w, ret); 900Sstevel@tonic-gate } 910Sstevel@tonic-gate } 920Sstevel@tonic-gate 930Sstevel@tonic-gate static char * 940Sstevel@tonic-gate replystr(update_status_t ret) 950Sstevel@tonic-gate { 960Sstevel@tonic-gate switch (ret) { 970Sstevel@tonic-gate case UPDATE_OK: 980Sstevel@tonic-gate return (reply_ok_str); 990Sstevel@tonic-gate case UPDATE_ERROR: 1000Sstevel@tonic-gate return (reply_err_str); 1010Sstevel@tonic-gate case UPDATE_FULL_RESYNC_NEEDED: 1020Sstevel@tonic-gate return (reply_fr_str); 1030Sstevel@tonic-gate case UPDATE_BUSY: 1040Sstevel@tonic-gate return (reply_busy_str); 1050Sstevel@tonic-gate case UPDATE_NIL: 1060Sstevel@tonic-gate return (reply_nil_str); 1070Sstevel@tonic-gate case UPDATE_PERM_DENIED: 1080Sstevel@tonic-gate return (reply_perm_str); 1090Sstevel@tonic-gate default: 1100Sstevel@tonic-gate return (reply_unknown_str); 1110Sstevel@tonic-gate } 1120Sstevel@tonic-gate } 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate kdb_incr_result_t * 1150Sstevel@tonic-gate iprop_get_updates_1(kdb_last_t *arg, struct svc_req *rqstp) 1160Sstevel@tonic-gate { 1170Sstevel@tonic-gate static kdb_incr_result_t ret; 1180Sstevel@tonic-gate char *whoami = "iprop_get_updates_1"; 1190Sstevel@tonic-gate int kret; 1200Sstevel@tonic-gate kadm5_server_handle_t handle = global_server_handle; 1210Sstevel@tonic-gate char *client_name = NULL, *service_name = NULL; 1220Sstevel@tonic-gate gss_name_t name = NULL; 1230Sstevel@tonic-gate OM_uint32 min_stat; 1240Sstevel@tonic-gate char obuf[256] = {0}; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate /* default return code */ 1270Sstevel@tonic-gate ret.ret = UPDATE_ERROR; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate DPRINT(("%s: start, last_sno=%u\n", whoami, (ulong_t)arg->last_sno)); 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate if (!handle) { 1320Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 1330Sstevel@tonic-gate gettext("%s: server handle is NULL"), 1340Sstevel@tonic-gate whoami); 1350Sstevel@tonic-gate goto out; 1360Sstevel@tonic-gate } 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate if (setup_gss_names(rqstp, &client_name, &service_name) < 0) { 1390Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 1400Sstevel@tonic-gate gettext("%s: setup_gss_names failed"), 1410Sstevel@tonic-gate whoami); 1420Sstevel@tonic-gate goto out; 1430Sstevel@tonic-gate } 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate DPRINT(("%s: clprinc=`%s'\n\tsvcprinc=`%s'\n", 1460Sstevel@tonic-gate whoami, client_name, service_name)); 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate if (!(name = get_clnt_name(rqstp))) { 1490Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 1500Sstevel@tonic-gate gettext("%s: Couldn't obtain client's name"), 1510Sstevel@tonic-gate whoami); 1520Sstevel@tonic-gate goto out; 1530Sstevel@tonic-gate } 154*2881Smp153739 if (!kadm5int_acl_check(handle->context, 1550Sstevel@tonic-gate name, 1560Sstevel@tonic-gate ACL_IPROP, 1570Sstevel@tonic-gate NULL, 1580Sstevel@tonic-gate NULL)) { 1590Sstevel@tonic-gate ret.ret = UPDATE_PERM_DENIED; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate audit_kadmind_unauth(rqstp->rq_xprt, l_port, 1620Sstevel@tonic-gate whoami, 1630Sstevel@tonic-gate "<null>", client_name); 1640Sstevel@tonic-gate krb5_klog_syslog(LOG_NOTICE, LOG_UNAUTH, whoami, 1650Sstevel@tonic-gate "<null>", client_name, service_name, 1660Sstevel@tonic-gate client_addr(rqstp, abuf)); 1670Sstevel@tonic-gate goto out; 1680Sstevel@tonic-gate } 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate kret = ulog_get_entries(handle->context, *arg, &ret); 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate if (ret.ret == UPDATE_OK) { 1730Sstevel@tonic-gate (void) snprintf(obuf, sizeof (obuf), 1740Sstevel@tonic-gate gettext("%s; Incoming SerialNo=%u; Outgoing SerialNo=%u"), 1750Sstevel@tonic-gate replystr(ret.ret), 1760Sstevel@tonic-gate (ulong_t)arg->last_sno, 1770Sstevel@tonic-gate (ulong_t)ret.lastentry.last_sno); 1780Sstevel@tonic-gate } else { 1790Sstevel@tonic-gate (void) snprintf(obuf, sizeof (obuf), 1800Sstevel@tonic-gate gettext("%s; Incoming SerialNo=%u; Outgoing SerialNo=N/A"), 1810Sstevel@tonic-gate replystr(ret.ret), 1820Sstevel@tonic-gate (ulong_t)arg->last_sno); 1830Sstevel@tonic-gate } 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate audit_kadmind_auth(rqstp->rq_xprt, l_port, 1860Sstevel@tonic-gate whoami, 1870Sstevel@tonic-gate obuf, client_name, kret); 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate krb5_klog_syslog(LOG_NOTICE, LOG_DONE, whoami, 1900Sstevel@tonic-gate obuf, 1910Sstevel@tonic-gate ((kret == 0) ? "success" : error_message(kret)), 1920Sstevel@tonic-gate client_name, service_name, 1930Sstevel@tonic-gate client_addr(rqstp, abuf)); 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate out: 1960Sstevel@tonic-gate if (nofork) 1970Sstevel@tonic-gate debprret(whoami, ret.ret, ret.lastentry.last_sno); 1980Sstevel@tonic-gate if (client_name) 1990Sstevel@tonic-gate free(client_name); 2000Sstevel@tonic-gate if (service_name) 2010Sstevel@tonic-gate free(service_name); 2020Sstevel@tonic-gate if (name) 2030Sstevel@tonic-gate gss_release_name(&min_stat, &name); 2040Sstevel@tonic-gate return (&ret); 2050Sstevel@tonic-gate } 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate /* 2090Sstevel@tonic-gate * Given a client princ (foo/fqdn@R), copy (in arg cl) the fqdn substring. 2100Sstevel@tonic-gate * Return arg cl str ptr on success, else NULL. 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate static char * 2130Sstevel@tonic-gate getclhoststr(char *clprinc, char *cl, int len) 2140Sstevel@tonic-gate { 2150Sstevel@tonic-gate char *s; 2160Sstevel@tonic-gate if (s = strchr(clprinc, '/')) { 2170Sstevel@tonic-gate if (!++s || strlcpy(cl, s, len) >= len) { 2180Sstevel@tonic-gate return (NULL); 2190Sstevel@tonic-gate } 2200Sstevel@tonic-gate if (s = strchr(cl, '@')) { 2210Sstevel@tonic-gate *s = '\0'; 2220Sstevel@tonic-gate return (cl); /* success */ 2230Sstevel@tonic-gate } 2240Sstevel@tonic-gate } 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate return (NULL); 2270Sstevel@tonic-gate } 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate kdb_fullresync_result_t * 2300Sstevel@tonic-gate iprop_full_resync_1( 2310Sstevel@tonic-gate /* LINTED */ 2320Sstevel@tonic-gate void *argp, 2330Sstevel@tonic-gate struct svc_req *rqstp) 2340Sstevel@tonic-gate { 2350Sstevel@tonic-gate static kdb_fullresync_result_t ret; 2360Sstevel@tonic-gate char tmpf[MAX_FILENAME] = {0}; 2370Sstevel@tonic-gate char ubuf[MAX_FILENAME + sizeof (KDB5_UTIL_DUMP_STR)] = {0}; 2380Sstevel@tonic-gate char clhost[MAXHOSTNAMELEN] = {0}; 2390Sstevel@tonic-gate int pret, fret; 2400Sstevel@tonic-gate kadm5_server_handle_t handle = global_server_handle; 2410Sstevel@tonic-gate OM_uint32 min_stat; 2420Sstevel@tonic-gate gss_name_t name = NULL; 2430Sstevel@tonic-gate char *client_name = NULL, *service_name = NULL; 2440Sstevel@tonic-gate char *whoami = "iprop_full_resync_1"; 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate /* default return code */ 2470Sstevel@tonic-gate ret.ret = UPDATE_ERROR; 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate if (!handle) { 2500Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 2510Sstevel@tonic-gate gettext("%s: server handle is NULL"), 2520Sstevel@tonic-gate whoami); 2530Sstevel@tonic-gate goto out; 2540Sstevel@tonic-gate } 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate DPRINT(("%s: start\n", whoami)); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate if (setup_gss_names(rqstp, &client_name, &service_name) < 0) { 2590Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 2600Sstevel@tonic-gate gettext("%s: setup_gss_names failed"), 2610Sstevel@tonic-gate whoami); 2620Sstevel@tonic-gate goto out; 2630Sstevel@tonic-gate } 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate DPRINT(("%s: clprinc=`%s'\n\tsvcprinc=`%s'\n", 2660Sstevel@tonic-gate whoami, client_name, service_name)); 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate if (!(name = get_clnt_name(rqstp))) { 2690Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 2700Sstevel@tonic-gate gettext("%s: Couldn't obtain client's name"), 2710Sstevel@tonic-gate whoami); 2720Sstevel@tonic-gate goto out; 2730Sstevel@tonic-gate } 274*2881Smp153739 if (!kadm5int_acl_check(handle->context, 2750Sstevel@tonic-gate name, 2760Sstevel@tonic-gate ACL_IPROP, 2770Sstevel@tonic-gate NULL, 2780Sstevel@tonic-gate NULL)) { 2790Sstevel@tonic-gate ret.ret = UPDATE_PERM_DENIED; 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate audit_kadmind_unauth(rqstp->rq_xprt, l_port, 2820Sstevel@tonic-gate whoami, 2830Sstevel@tonic-gate "<null>", client_name); 2840Sstevel@tonic-gate krb5_klog_syslog(LOG_NOTICE, LOG_UNAUTH, whoami, 2850Sstevel@tonic-gate "<null>", client_name, service_name, 2860Sstevel@tonic-gate client_addr(rqstp, abuf)); 2870Sstevel@tonic-gate goto out; 2880Sstevel@tonic-gate } 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate if (!getclhoststr(client_name, clhost, sizeof (clhost))) { 2910Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 2920Sstevel@tonic-gate gettext("%s: getclhoststr failed"), 2930Sstevel@tonic-gate whoami); 2940Sstevel@tonic-gate goto out; 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate /* 2980Sstevel@tonic-gate * construct db dump file name; kprop style name + clnt fqdn 2990Sstevel@tonic-gate */ 3000Sstevel@tonic-gate (void) strcpy(tmpf, "/var/krb5/slave_datatrans_"); 3010Sstevel@tonic-gate if (strlcat(tmpf, clhost, sizeof (tmpf)) >= sizeof (tmpf)) { 3020Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 3030Sstevel@tonic-gate gettext("%s: db dump file name too long; max length=%d"), 3040Sstevel@tonic-gate whoami, 3050Sstevel@tonic-gate (sizeof (tmpf) - 1)); 3060Sstevel@tonic-gate goto out; 3070Sstevel@tonic-gate } 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate /* 3100Sstevel@tonic-gate * note the -i; modified version of kdb5_util dump format 3110Sstevel@tonic-gate * to include sno (serial number) 3120Sstevel@tonic-gate */ 3130Sstevel@tonic-gate if (strlcpy(ubuf, KDB5_UTIL_DUMP_STR, sizeof (ubuf)) >= 3140Sstevel@tonic-gate sizeof (ubuf)) { 3150Sstevel@tonic-gate goto out; 3160Sstevel@tonic-gate } 3170Sstevel@tonic-gate if (strlcat(ubuf, tmpf, sizeof (ubuf)) >= sizeof (ubuf)) { 3180Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 3190Sstevel@tonic-gate gettext("%s: kdb5 util dump string too long; max length=%d"), 3200Sstevel@tonic-gate whoami, 3210Sstevel@tonic-gate (sizeof (ubuf) - 1)); 3220Sstevel@tonic-gate goto out; 3230Sstevel@tonic-gate } 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate /* 3260Sstevel@tonic-gate * Fork to dump the db and xfer it to the slave. 3270Sstevel@tonic-gate * (the fork allows parent to return quickly and the child 3280Sstevel@tonic-gate * acts like a callback to the slave). 3290Sstevel@tonic-gate */ 3300Sstevel@tonic-gate fret = fork(); 3310Sstevel@tonic-gate DPRINT(("%s: fork=%d (%d)\n", whoami, fret, getpid())); 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate switch (fret) { 3340Sstevel@tonic-gate case -1: /* error */ 3350Sstevel@tonic-gate if (nofork) { 3360Sstevel@tonic-gate perror(whoami); 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 3390Sstevel@tonic-gate gettext("%s: fork failed: %s"), 3400Sstevel@tonic-gate whoami, 3410Sstevel@tonic-gate error_message(errno)); 3420Sstevel@tonic-gate goto out; 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate case 0: /* child */ 3450Sstevel@tonic-gate DPRINT(("%s: run `%s' ...\n", whoami, ubuf)); 3460Sstevel@tonic-gate (void) signal(SIGCHLD, SIG_DFL); 3470Sstevel@tonic-gate /* run kdb5_util(1M) dump for IProp */ 3480Sstevel@tonic-gate pret = pclose(popen(ubuf, "w")); 3490Sstevel@tonic-gate DPRINT(("%s: pclose=%d\n", whoami, pret)); 3500Sstevel@tonic-gate if (pret == -1) { 3510Sstevel@tonic-gate if (nofork) { 3520Sstevel@tonic-gate perror(whoami); 3530Sstevel@tonic-gate } 3540Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 3550Sstevel@tonic-gate gettext("%s: pclose(popen) failed: %s"), 3560Sstevel@tonic-gate whoami, 3570Sstevel@tonic-gate error_message(errno)); 3580Sstevel@tonic-gate goto out; 3590Sstevel@tonic-gate } 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate DPRINT(("%s: exec `kprop -f %s %s' ...\n", 3620Sstevel@tonic-gate whoami, tmpf, clhost)); 3630Sstevel@tonic-gate pret = execl("/usr/lib/krb5/kprop", "kprop", "-f", tmpf, 3640Sstevel@tonic-gate clhost, NULL); 3650Sstevel@tonic-gate if (pret == -1) { 3660Sstevel@tonic-gate if (nofork) { 3670Sstevel@tonic-gate perror(whoami); 3680Sstevel@tonic-gate } 3690Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 3700Sstevel@tonic-gate gettext("%s: exec failed: %s"), 3710Sstevel@tonic-gate whoami, 3720Sstevel@tonic-gate error_message(errno)); 3730Sstevel@tonic-gate goto out; 3740Sstevel@tonic-gate } 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate default: /* parent */ 3770Sstevel@tonic-gate ret.ret = UPDATE_OK; 3780Sstevel@tonic-gate /* not used by slave (sno is retrieved from kdb5_util dump) */ 3790Sstevel@tonic-gate ret.lastentry.last_sno = 0; 3800Sstevel@tonic-gate ret.lastentry.last_time.seconds = 0; 3810Sstevel@tonic-gate ret.lastentry.last_time.useconds = 0; 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate audit_kadmind_auth(rqstp->rq_xprt, l_port, 3840Sstevel@tonic-gate whoami, 3850Sstevel@tonic-gate "<null>", client_name, 0); 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate krb5_klog_syslog(LOG_NOTICE, LOG_DONE, whoami, 3880Sstevel@tonic-gate "<null>", 3890Sstevel@tonic-gate "success", 3900Sstevel@tonic-gate client_name, service_name, 3910Sstevel@tonic-gate client_addr(rqstp, abuf)); 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate goto out; 3940Sstevel@tonic-gate } 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate out: 3970Sstevel@tonic-gate if (nofork) 3980Sstevel@tonic-gate debprret(whoami, ret.ret, 0); 3990Sstevel@tonic-gate if (client_name) 4000Sstevel@tonic-gate free(client_name); 4010Sstevel@tonic-gate if (service_name) 4020Sstevel@tonic-gate free(service_name); 4030Sstevel@tonic-gate if (name) 4040Sstevel@tonic-gate gss_release_name(&min_stat, &name); 4050Sstevel@tonic-gate return (&ret); 4060Sstevel@tonic-gate } 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate void 4090Sstevel@tonic-gate krb5_iprop_prog_1( 4100Sstevel@tonic-gate struct svc_req *rqstp, 4110Sstevel@tonic-gate register SVCXPRT *transp) 4120Sstevel@tonic-gate { 4130Sstevel@tonic-gate union { 4140Sstevel@tonic-gate kdb_last_t iprop_get_updates_1_arg; 4150Sstevel@tonic-gate } argument; 4160Sstevel@tonic-gate char *result; 4170Sstevel@tonic-gate bool_t (*_xdr_argument)(), (*_xdr_result)(); 4180Sstevel@tonic-gate char *(*local)(); 4190Sstevel@tonic-gate char *whoami = "krb5_iprop_prog_1"; 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate switch (rqstp->rq_proc) { 4220Sstevel@tonic-gate case NULLPROC: 4230Sstevel@tonic-gate (void) svc_sendreply(transp, xdr_void, 4240Sstevel@tonic-gate (char *)NULL); 4250Sstevel@tonic-gate return; 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate case IPROP_GET_UPDATES: 4280Sstevel@tonic-gate _xdr_argument = xdr_kdb_last_t; 4290Sstevel@tonic-gate _xdr_result = xdr_kdb_incr_result_t; 4300Sstevel@tonic-gate local = (char *(*)()) iprop_get_updates_1; 4310Sstevel@tonic-gate break; 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate case IPROP_FULL_RESYNC: 4340Sstevel@tonic-gate _xdr_argument = xdr_void; 4350Sstevel@tonic-gate _xdr_result = xdr_kdb_fullresync_result_t; 4360Sstevel@tonic-gate local = (char *(*)()) iprop_full_resync_1; 4370Sstevel@tonic-gate break; 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate default: 4400Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 4410Sstevel@tonic-gate gettext("RPC unknown request: %d (%s)"), 4420Sstevel@tonic-gate rqstp->rq_proc, whoami); 4430Sstevel@tonic-gate svcerr_noproc(transp); 4440Sstevel@tonic-gate return; 4450Sstevel@tonic-gate } 4460Sstevel@tonic-gate (void) memset((char *)&argument, 0, sizeof (argument)); 4470Sstevel@tonic-gate if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) { 4480Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 4490Sstevel@tonic-gate gettext("RPC svc_getargs failed (%s)"), 4500Sstevel@tonic-gate whoami); 4510Sstevel@tonic-gate svcerr_decode(transp); 4520Sstevel@tonic-gate return; 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate result = (*local)(&argument, rqstp); 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate if (_xdr_result && result != NULL && 4570Sstevel@tonic-gate !svc_sendreply(transp, _xdr_result, result)) { 4580Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 4590Sstevel@tonic-gate gettext("RPC svc_sendreply failed (%s)"), 4600Sstevel@tonic-gate whoami); 4610Sstevel@tonic-gate svcerr_systemerr(transp); 4620Sstevel@tonic-gate } 4630Sstevel@tonic-gate if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) { 4640Sstevel@tonic-gate krb5_klog_syslog(LOG_ERR, 4650Sstevel@tonic-gate gettext("RPC svc_freeargs failed (%s)"), 4660Sstevel@tonic-gate whoami); 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate exit(1); 4690Sstevel@tonic-gate } 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate if (rqstp->rq_proc == IPROP_GET_UPDATES) { 4720Sstevel@tonic-gate /* LINTED */ 4730Sstevel@tonic-gate kdb_incr_result_t *r = (kdb_incr_result_t *)result; 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate if (r->ret == UPDATE_OK) { 4760Sstevel@tonic-gate ulog_free_entries(r->updates.kdb_ulog_t_val, 4770Sstevel@tonic-gate r->updates.kdb_ulog_t_len); 4780Sstevel@tonic-gate r->updates.kdb_ulog_t_val = NULL; 4790Sstevel@tonic-gate r->updates.kdb_ulog_t_len = 0; 4800Sstevel@tonic-gate } 4810Sstevel@tonic-gate } 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate } 4840Sstevel@tonic-gate 4850Sstevel@tonic-gate /* 4860Sstevel@tonic-gate * Get the host base service name for the kiprop principal. Returns 4870Sstevel@tonic-gate * KADM5_OK on success. Caller must free the storage allocated for 4880Sstevel@tonic-gate * host_service_name. 4890Sstevel@tonic-gate */ 4900Sstevel@tonic-gate kadm5_ret_t 4910Sstevel@tonic-gate kiprop_get_adm_host_srv_name( 4920Sstevel@tonic-gate krb5_context context, 4930Sstevel@tonic-gate const char *realm, 4940Sstevel@tonic-gate char **host_service_name) 4950Sstevel@tonic-gate { 4960Sstevel@tonic-gate kadm5_ret_t ret; 4970Sstevel@tonic-gate char *name; 4980Sstevel@tonic-gate char *host; 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate if (ret = kadm5_get_master(context, realm, &host)) 5010Sstevel@tonic-gate return (ret); 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate name = malloc(strlen(KIPROP_SVC_NAME)+ strlen(host) + 2); 5040Sstevel@tonic-gate if (name == NULL) { 5050Sstevel@tonic-gate free(host); 5060Sstevel@tonic-gate return (ENOMEM); 5070Sstevel@tonic-gate } 5080Sstevel@tonic-gate (void) sprintf(name, "%s@%s", KIPROP_SVC_NAME, host); 5090Sstevel@tonic-gate free(host); 5100Sstevel@tonic-gate *host_service_name = name; 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate return (KADM5_OK); 5130Sstevel@tonic-gate } 514