8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / krb5 / kadmin / server / server_stubs.c
blob76eef7227a28c3ed114596826e3e11d51e511ab8
1 /*
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
3 */
6 /*
7 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
9 * Openvision retains the copyright to derivative works of
10 * this source code. Do *NOT* create a derivative of this
11 * source code before consulting with your legal department.
12 * Do *NOT* integrate *ANY* of this source code into another
13 * product before consulting with your legal department.
15 * For further information, read the top-level Openvision
16 * copyright which is contained in the top-level MIT Kerberos
17 * copyright.
19 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
25 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
29 #include <kadm5/admin.h>
30 #include <gssapi/gssapi.h>
31 #include <gssapi_krb5.h> /* for gss_nt_krb5_name */
32 #include <kadm5/kadm_rpc.h>
33 #include <kadm5/server_internal.h>
34 #include <kadm5/srv/server_acl.h>
35 #include <security/pam_appl.h>
37 #include <syslog.h>
38 #include <arpa/inet.h> /* inet_ntoa */
39 #include <krb5/adm_proto.h> /* krb5_klog_syslog */
40 #include <libintl.h>
41 #include <krb5.h>
42 #include "misc.h"
44 #define LOG_UNAUTH gettext("Unauthorized request: %s, %s, " \
45 "client=%s, service=%s, addr=%s")
46 #define LOG_DONE gettext("Request: %s, %s, %s, client=%s, " \
47 "service=%s, addr=%s")
49 extern gss_name_t gss_changepw_name;
50 extern gss_name_t gss_oldchangepw_name;
51 extern void * global_server_handle;
52 extern short l_port;
54 char buf[33];
56 #define CHANGEPW_SERVICE(rqstp) \
57 (cmp_gss_names_rel_1(acceptor_name(rqstp), gss_changepw_name) |\
58 (gss_oldchangepw_name && \
59 cmp_gss_names_rel_1(acceptor_name(rqstp), \
60 gss_oldchangepw_name)))
63 static int gss_to_krb5_name(kadm5_server_handle_t handle,
64 gss_name_t gss_name, krb5_principal *princ);
66 static int gss_name_to_string(gss_name_t gss_name, gss_buffer_desc *str);
68 static gss_name_t acceptor_name(struct svc_req * rqstp);
70 kadm5_ret_t
71 kadm5_get_priv(void *server_handle,
72 long *privs, gss_name_t clnt);
74 gss_name_t
75 get_clnt_name(struct svc_req * rqstp)
77 OM_uint32 maj_stat, min_stat;
78 gss_name_t name;
79 rpc_gss_rawcred_t *raw_cred;
80 void *cookie;
81 gss_buffer_desc name_buff;
83 rpc_gss_getcred(rqstp, &raw_cred, NULL, &cookie);
84 name_buff.value = raw_cred->client_principal->name;
85 name_buff.length = raw_cred->client_principal->len;
86 maj_stat = gss_import_name(&min_stat, &name_buff,
87 (gss_OID) GSS_C_NT_EXPORT_NAME, &name);
88 if (maj_stat != GSS_S_COMPLETE) {
89 return (NULL);
91 return (name);
94 char *
95 client_addr(struct svc_req * req, char *buf)
97 struct sockaddr *ca;
98 u_char *b;
99 char *frontspace = " ";
102 * Convert the caller's IP address to a dotted string
104 ca = (struct sockaddr *)
105 svc_getrpccaller(req->rq_xprt)->buf;
107 if (ca->sa_family == AF_INET) {
108 b = (u_char *) & ((struct sockaddr_in *) ca)->sin_addr;
109 (void) sprintf(buf, "%s(%d.%d.%d.%d) ", frontspace,
110 b[0] & 0xFF, b[1] & 0xFF, b[2] & 0xFF, b[3] & 0xFF);
111 } else {
113 * No IP address to print. If there was a host name
114 * printed, then we print a space.
116 (void) sprintf(buf, frontspace);
119 return (buf);
122 static int cmp_gss_names(gss_name_t n1, gss_name_t n2)
124 OM_uint32 emaj, emin;
125 int equal;
127 if (GSS_ERROR(emaj = gss_compare_name(&emin, n1, n2, &equal)))
128 return(0);
130 return(equal);
133 /* Does a comparison of the names and then releases the first entity */
134 /* For use above in CHANGEPW_SERVICE */
135 static int cmp_gss_names_rel_1(gss_name_t n1, gss_name_t n2)
137 OM_uint32 min_stat;
138 int ret;
140 ret = cmp_gss_names(n1, n2);
141 if (n1) (void) gss_release_name(&min_stat, &n1);
142 return ret;
146 * Function check_handle
148 * Purpose: Check a server handle and return a com_err code if it is
149 * invalid or 0 if it is valid.
151 * Arguments:
153 * handle The server handle.
156 static int check_handle(void *handle)
158 CHECK_HANDLE(handle);
159 return 0;
163 * Function: new_server_handle
165 * Purpose: Constructs a server handle suitable for passing into the
166 * server library API functions, by folding the client's API version
167 * and calling principal into the server handle returned by
168 * kadm5_init.
170 * Arguments:
171 * api_version (input) The API version specified by the client
172 * rqstp (input) The RPC request
173 * handle (output) The returned handle
174 * <return value> (output) An error code, or 0 if no error occurred
176 * Effects:
177 * Returns a pointer to allocated storage containing the server
178 * handle. If an error occurs, then no allocated storage is
179 * returned, and the return value of the function will be a
180 * non-zero com_err code.
182 * The allocated storage for the handle should be freed with
183 * free_server_handle (see below) when it is no longer needed.
186 static kadm5_ret_t new_server_handle(krb5_ui_4 api_version,
187 struct svc_req *rqstp,
188 kadm5_server_handle_t
189 *out_handle)
191 kadm5_server_handle_t handle;
192 gss_name_t name;
193 OM_uint32 min_stat;
195 if (! (handle = (kadm5_server_handle_t)
196 malloc(sizeof(*handle))))
197 return ENOMEM;
199 *handle = *(kadm5_server_handle_t)global_server_handle;
200 handle->api_version = api_version;
202 if (!(name = get_clnt_name(rqstp))) {
203 free(handle);
204 return KADM5_FAILURE;
206 if (! gss_to_krb5_name(handle, name, &handle->current_caller)) {
207 free(handle);
208 gss_release_name(&min_stat, &name);
209 return KADM5_FAILURE;
211 gss_release_name(&min_stat, &name);
213 *out_handle = handle;
214 return 0;
218 * Function: free_server_handle
220 * Purpose: Free handle memory allocated by new_server_handle
222 * Arguments:
223 * handle (input/output) The handle to free
225 static void free_server_handle(kadm5_server_handle_t handle)
227 krb5_free_principal(handle->context, handle->current_caller);
228 free(handle);
232 * Function: setup_gss_names
234 * Purpose: Create printable representations of the client and server
235 * names.
237 * Arguments:
238 * rqstp (r) the RPC request
239 * client_name (w) pointer to client_name string
240 * server_name (w) pointer to server_name string
242 * Effects:
244 * Unparses the client and server names into client_name and
245 * server_name, both of which must be freed by the caller. Returns 0
246 * on success and -1 on failure. On failure client_name and server_name
247 * will point to null.
249 /* SUNW14resync */
250 int setup_gss_names(struct svc_req *rqstp,
251 char **client_name, char **server_name)
253 OM_uint32 maj_stat, min_stat;
254 rpc_gss_rawcred_t *raw_cred;
255 gss_buffer_desc name_buf;
256 char *tmp, *val;
257 size_t len;
258 gss_name_t name;
260 *client_name = NULL;
262 rpc_gss_getcred(rqstp, &raw_cred, NULL, NULL);
264 /* Return a copy of the service principal from the raw_cred */
265 *server_name = strdup(raw_cred->svc_principal);
267 if (*server_name == NULL)
268 return (-1);
270 if (!(name = get_clnt_name(rqstp))) {
271 free(*server_name);
272 *server_name = NULL;
273 return (-1);
275 maj_stat = gss_display_name(&min_stat, name, &name_buf, NULL);
276 if (maj_stat != GSS_S_COMPLETE) {
277 free(*server_name);
278 gss_release_name(&min_stat, &name);
279 *server_name = NULL;
280 return (-1);
282 gss_release_name(&min_stat, &name);
285 * Allocate space to copy the client principal. We allocate an
286 * extra byte to make the string null terminated if we need to.
289 val = name_buf.value;
290 len = name_buf.length + (val[name_buf.length - 1] != '\0');
292 /* len is the length including the null terminating byte. */
294 tmp = malloc(len);
295 if (tmp) {
296 memcpy(tmp, val, len - 1);
297 tmp[len - 1] = '\0';
298 } else {
299 free(*server_name);
300 *server_name = NULL;
303 /* Were done with the GSS buffer */
304 (void) gss_release_buffer(&min_stat, &name_buf);
306 *client_name = tmp;
308 return (tmp ? 0 : -1);
311 static gss_name_t acceptor_name(struct svc_req * rqstp)
313 OM_uint32 maj_stat, min_stat;
314 gss_name_t name;
315 rpc_gss_rawcred_t *raw_cred;
316 void *cookie;
317 gss_buffer_desc name_buff;
319 rpc_gss_getcred(rqstp, &raw_cred, NULL, &cookie);
320 name_buff.value = raw_cred->svc_principal;
321 name_buff.length = strlen(raw_cred->svc_principal);
322 maj_stat = gss_import_name(&min_stat, &name_buff,
323 (gss_OID) gss_nt_krb5_name, &name);
324 if (maj_stat != GSS_S_COMPLETE) {
325 gss_release_buffer(&min_stat, &name_buff);
326 return (NULL);
328 maj_stat = gss_display_name(&min_stat, name, &name_buff, NULL);
329 if (maj_stat != GSS_S_COMPLETE) {
330 gss_release_buffer(&min_stat, &name_buff);
331 return (NULL);
333 gss_release_buffer(&min_stat, &name_buff);
335 return name;
338 static int cmp_gss_krb5_name(kadm5_server_handle_t handle,
339 gss_name_t gss_name, krb5_principal princ)
341 krb5_principal princ2;
342 int status;
344 if (! gss_to_krb5_name(handle, gss_name, &princ2))
345 return 0;
346 status = krb5_principal_compare(handle->context, princ, princ2);
347 krb5_free_principal(handle->context, princ2);
348 return status;
353 * This routine primarily validates the username and password
354 * of the principal to be created, if a prior acl check for
355 * the 'u' privilege succeeds. Validation is done using
356 * the PAM `k5migrate' service. k5migrate normally stacks
357 * pam_unix_auth.so and pam_unix_account.so in its auth and
358 * account stacks respectively.
360 * Returns 1 (true), if validation is successful,
361 * else returns 0 (false).
363 int verify_pam_pw(char *userdata, char *pwd) {
364 pam_handle_t *pamh;
365 int err = 0;
366 int result = 1;
367 char *user = NULL;
368 char *ptr = NULL;
370 ptr = strchr(userdata, '@');
371 if (ptr != NULL) {
372 user = (char *)malloc(ptr - userdata + 1);
373 (void) strlcpy(user, userdata, (ptr - userdata) + 1);
374 } else {
375 user = (char *)strdup(userdata);
378 err = pam_start("k5migrate", user, NULL, &pamh);
379 if (err != PAM_SUCCESS) {
380 syslog(LOG_ERR, "verify_pam_pw: pam_start() failed, %s\n",
381 pam_strerror(pamh, err));
382 if (user)
383 free(user);
384 return (0);
386 if (user)
387 free(user);
389 err = pam_set_item(pamh, PAM_AUTHTOK, (void *)pwd);
390 if (err != PAM_SUCCESS) {
391 syslog(LOG_ERR, "verify_pam_pw: pam_set_item() failed, %s\n",
392 pam_strerror(pamh, err));
393 (void) pam_end(pamh, err);
394 return (0);
397 err = pam_authenticate(pamh, PAM_SILENT);
398 if (err != PAM_SUCCESS) {
399 syslog(LOG_ERR, "verify_pam_pw: pam_authenticate() "
400 "failed, %s\n", pam_strerror(pamh, err));
401 (void) pam_end(pamh, err);
402 return (0);
405 err = pam_acct_mgmt(pamh, PAM_SILENT);
406 if (err != PAM_SUCCESS) {
407 syslog(LOG_ERR, "verify_pam_pw: pam_acct_mgmt() failed, %s\n",
408 pam_strerror(pamh, err));
409 (void) pam_end(pamh, err);
410 return (0);
413 (void) pam_end(pamh, PAM_SUCCESS);
414 return (result);
417 static int gss_to_krb5_name(kadm5_server_handle_t handle,
418 gss_name_t gss_name, krb5_principal *princ)
420 OM_uint32 status, minor_stat;
421 gss_buffer_desc gss_str;
422 gss_OID gss_type;
423 int success;
425 status = gss_display_name(&minor_stat, gss_name, &gss_str, &gss_type);
426 if ((status != GSS_S_COMPLETE) || (!g_OID_equal(gss_type, gss_nt_krb5_name)))
427 return 0;
428 success = (krb5_parse_name(handle->context, gss_str.value, princ) == 0);
429 gss_release_buffer(&minor_stat, &gss_str);
430 return success;
433 static int
434 gss_name_to_string(gss_name_t gss_name, gss_buffer_desc *str)
436 OM_uint32 status, minor_stat;
437 gss_OID gss_type;
439 status = gss_display_name(&minor_stat, gss_name, str, &gss_type);
440 if ((status != GSS_S_COMPLETE) || (gss_type != gss_nt_krb5_name))
441 return 1;
442 return 0;
445 static int
446 log_unauth(
447 char *op,
448 char *target,
449 char *client,
450 char *server,
451 char *addr)
453 size_t tlen, clen, slen;
454 char *tdots, *cdots, *sdots;
456 tlen = strlen(target);
457 trunc_name(&tlen, &tdots);
458 clen = strlen(client);
459 trunc_name(&clen, &cdots);
460 slen = strlen(server);
461 trunc_name(&slen, &sdots);
463 return krb5_klog_syslog(LOG_NOTICE,
464 "Unauthorized request: %s, %.*s%s, "
465 "client=%.*s%s, service=%.*s%s, addr=%s",
466 op, tlen, target, tdots,
467 clen, client, cdots,
468 slen, server, sdots,
469 addr);
472 static int
473 log_done(
474 char *op,
475 char *target,
476 const char *errmsg,
477 char *client,
478 char *server,
479 char *addr)
481 size_t tlen, clen, slen;
482 char *tdots, *cdots, *sdots;
484 tlen = strlen(target);
485 trunc_name(&tlen, &tdots);
486 clen = strlen(client);
487 trunc_name(&clen, &cdots);
488 slen = strlen(server);
489 trunc_name(&slen, &sdots);
491 return krb5_klog_syslog(LOG_NOTICE,
492 "Request: %s, %.*s%s, %s, "
493 "client=%.*s%s, service=%.*s%s, addr=%s",
494 op, tlen, target, tdots, errmsg,
495 clen, client, cdots,
496 slen, server, sdots,
497 addr);
500 generic_ret *
501 create_principal_2_svc(cprinc_arg *arg, struct svc_req *rqstp)
503 static generic_ret ret;
504 char *prime_arg = NULL;
505 char *client_name = NULL, *service_name = NULL;
506 int policy_migrate = 0;
508 OM_uint32 minor_stat;
509 kadm5_server_handle_t handle;
510 kadm5_ret_t retval;
511 restriction_t *rp;
512 const char *errmsg = NULL;
513 gss_name_t name = NULL;
515 xdr_free(xdr_generic_ret, (char *) &ret);
517 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
518 return &ret;
520 if ((ret.code = check_handle((void *)handle)))
521 goto error;
522 ret.api_version = handle->api_version;
524 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
525 ret.code = KADM5_FAILURE;
526 goto error;
528 if (krb5_unparse_name(handle->context, arg->rec.principal, &prime_arg)) {
529 ret.code = KADM5_BAD_PRINCIPAL;
530 goto error;
532 if (!(name = get_clnt_name(rqstp))) {
533 ret.code = KADM5_FAILURE;
534 goto error;
537 if (kadm5int_acl_check(handle->context, name, ACL_MIGRATE,
538 arg->rec.principal, &rp) &&
539 verify_pam_pw(prime_arg, arg->passwd)) {
540 policy_migrate = 1;
543 if (CHANGEPW_SERVICE(rqstp)
544 || (!kadm5int_acl_check(handle->context, name, ACL_ADD,
545 arg->rec.principal, &rp) &&
546 !(policy_migrate))
547 || kadm5int_acl_impose_restrictions(handle->context,
548 &arg->rec, &arg->mask, rp)) {
549 ret.code = KADM5_AUTH_ADD;
551 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
552 "kadm5_create_principal",
553 prime_arg, client_name);
554 log_unauth("kadm5_create_principal", prime_arg,
555 client_name, service_name, client_addr(rqstp, buf));
556 } else {
557 ret.code = kadm5_create_principal((void *)handle,
558 &arg->rec, arg->mask,
559 arg->passwd);
560 /* Solaris Kerberos */
561 if( ret.code != 0 )
562 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
564 audit_kadmind_auth(rqstp->rq_xprt, l_port,
565 "kadm5_create_principal",
566 prime_arg, client_name, ret.code);
567 log_done("kadm5_create_principal", prime_arg,
568 errmsg ? errmsg : "success",
569 client_name, service_name, client_addr(rqstp, buf));
571 if (errmsg != NULL)
572 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
574 if (policy_migrate && (ret.code == 0)) {
575 arg->rec.policy = strdup("default");
576 if ((arg->mask & KADM5_PW_EXPIRATION)) {
577 arg->mask = 0;
578 arg->mask |= KADM5_POLICY;
579 arg->mask |= KADM5_PW_EXPIRATION;
580 } else {
581 arg->mask = 0;
582 arg->mask |= KADM5_POLICY;
585 retval = kadm5_modify_principal((void *)handle,
586 &arg->rec, arg->mask);
587 log_done("kadm5_modify_principal",
588 prime_arg, ((retval == 0) ? "success" :
589 error_message(retval)), client_name,
590 service_name, client_addr(rqstp, buf));
594 error:
595 if (name)
596 gss_release_name(&minor_stat, &name);
597 free_server_handle(handle);
598 if (prime_arg)
599 free(prime_arg);
600 if (client_name)
601 free(client_name);
602 if (service_name)
603 free(service_name);
604 return (&ret);
607 generic_ret *
608 create_principal3_2_svc(cprinc3_arg *arg, struct svc_req *rqstp)
610 static generic_ret ret;
611 char *prime_arg = NULL;
612 char *client_name = NULL, *service_name = NULL;
613 int policy_migrate = 0;
615 OM_uint32 minor_stat;
616 kadm5_server_handle_t handle;
617 kadm5_ret_t retval;
618 restriction_t *rp;
619 const char *errmsg = NULL;
620 gss_name_t name = NULL;
622 xdr_free(xdr_generic_ret, (char *) &ret);
624 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
625 return &ret;
627 if ((ret.code = check_handle((void *)handle)))
628 goto error;
629 ret.api_version = handle->api_version;
631 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
632 ret.code = KADM5_FAILURE;
633 goto error;
635 if (krb5_unparse_name(handle->context, arg->rec.principal, &prime_arg)) {
636 ret.code = KADM5_BAD_PRINCIPAL;
637 goto error;
639 if (!(name = get_clnt_name(rqstp))) {
640 ret.code = KADM5_FAILURE;
641 goto error;
644 if (kadm5int_acl_check(handle->context, name, ACL_MIGRATE,
645 arg->rec.principal, &rp) &&
646 verify_pam_pw(prime_arg, arg->passwd)) {
647 policy_migrate = 1;
650 if (CHANGEPW_SERVICE(rqstp)
651 || (!kadm5int_acl_check(handle->context, name, ACL_ADD,
652 arg->rec.principal, &rp) &&
653 !(policy_migrate))
654 || kadm5int_acl_impose_restrictions(handle->context,
655 &arg->rec, &arg->mask, rp)) {
656 ret.code = KADM5_AUTH_ADD;
657 log_unauth("kadm5_create_principal", prime_arg,
658 client_name, service_name, client_addr(rqstp, buf));
659 } else {
660 ret.code = kadm5_create_principal_3((void *)handle,
661 &arg->rec, arg->mask,
662 arg->n_ks_tuple,
663 arg->ks_tuple,
664 arg->passwd);
665 /* Solaris Kerberos */
666 if( ret.code != 0 )
667 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
669 log_done("kadm5_create_principal", prime_arg,
670 errmsg ? errmsg : "success",
671 client_name, service_name, client_addr(rqstp, buf));
673 if (errmsg != NULL)
674 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
676 if (policy_migrate && (ret.code == 0)) {
677 arg->rec.policy = strdup("default");
678 if ((arg->mask & KADM5_PW_EXPIRATION)) {
679 arg->mask = 0;
680 arg->mask |= KADM5_POLICY;
681 arg->mask |= KADM5_PW_EXPIRATION;
682 } else {
683 arg->mask = 0;
684 arg->mask |= KADM5_POLICY;
687 retval = kadm5_modify_principal((void *)handle,
688 &arg->rec, arg->mask);
689 log_done("kadm5_modify_principal", prime_arg,
690 ((retval == 0) ? "success" : error_message(retval)),
691 client_name, service_name, client_addr(rqstp, buf));
695 error:
696 if (name)
697 gss_release_name(&minor_stat, &name);
698 free_server_handle(handle);
699 if (client_name)
700 free(client_name);
701 if (service_name)
702 free(service_name);
703 if (prime_arg)
704 free(prime_arg);
705 return &ret;
708 generic_ret *
709 delete_principal_2_svc(dprinc_arg *arg, struct svc_req *rqstp)
711 static generic_ret ret;
712 char *prime_arg = NULL;
713 char *client_name = NULL, *service_name = NULL;
714 OM_uint32 min_stat;
715 kadm5_server_handle_t handle;
716 const char *errmsg = NULL;
718 gss_name_t name = NULL;
721 xdr_free(xdr_generic_ret, (char *) &ret);
723 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
724 return &ret;
726 if ((ret.code = check_handle((void *)handle)))
727 goto error;
728 ret.api_version = handle->api_version;
730 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
731 ret.code = KADM5_FAILURE;
732 goto error;
734 if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) {
735 ret.code = KADM5_BAD_PRINCIPAL;
736 goto error;
738 if (!(name = get_clnt_name(rqstp))) {
739 ret.code = KADM5_FAILURE;
740 goto error;
743 if (CHANGEPW_SERVICE(rqstp)
744 || !kadm5int_acl_check(handle->context, name, ACL_DELETE,
745 arg->princ, NULL)) {
746 ret.code = KADM5_AUTH_DELETE;
748 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
749 "kadm5_delete_principal",
750 prime_arg, client_name);
751 log_unauth("kadm5_delete_principal", prime_arg, client_name,
752 service_name, client_addr(rqstp, buf));
753 } else {
754 ret.code = kadm5_delete_principal((void *)handle, arg->princ);
755 /* Solaris Kerberos */
756 if( ret.code != 0 )
757 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
759 audit_kadmind_auth(rqstp->rq_xprt, l_port,
760 "kadm5_delete_principal",
761 prime_arg, client_name, ret.code);
762 log_done("kadm5_delete_principal", prime_arg,
763 errmsg ? errmsg : "success",
764 client_name, service_name, client_addr(rqstp, buf));
766 if (errmsg != NULL)
767 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
771 error:
772 if (name)
773 gss_release_name(&min_stat, &name);
774 if (prime_arg)
775 free(prime_arg);
776 free_server_handle(handle);
777 if (client_name)
778 free(client_name);
779 if (service_name)
780 free(service_name);
781 return &ret;
784 generic_ret *
785 modify_principal_2_svc(mprinc_arg *arg, struct svc_req *rqstp)
787 static generic_ret ret;
788 char *prime_arg = NULL;
789 char *client_name = NULL, *service_name = NULL;
790 OM_uint32 min_stat;
791 kadm5_server_handle_t handle;
792 restriction_t *rp;
793 gss_name_t name = NULL;
794 const char *errmsg = NULL;
796 xdr_free(xdr_generic_ret, (char *) &ret);
798 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
799 return &ret;
801 if ((ret.code = check_handle((void *)handle)))
802 goto error;
803 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
804 ret.code = KADM5_FAILURE;
805 goto error;
807 if (krb5_unparse_name(handle->context, arg->rec.principal, &prime_arg)) {
808 ret.code = KADM5_BAD_PRINCIPAL;
809 goto error;
811 if (!(name = get_clnt_name(rqstp))) {
812 ret.code = KADM5_FAILURE;
813 goto error;
816 if (CHANGEPW_SERVICE(rqstp)
817 || !kadm5int_acl_check(handle->context, name, ACL_MODIFY,
818 arg->rec.principal, &rp)
819 || kadm5int_acl_impose_restrictions(handle->context,
820 &arg->rec, &arg->mask, rp)) {
821 ret.code = KADM5_AUTH_MODIFY;
823 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
824 "kadm5_modify_principal",
825 prime_arg, client_name);
826 log_unauth("kadm5_modify_principal", prime_arg, client_name,
827 service_name, client_addr(rqstp, buf));
828 } else {
829 ret.code = kadm5_modify_principal((void *)handle, &arg->rec,
830 arg->mask);
831 /* Solaris Kerberos */
832 if( ret.code != 0 )
833 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
835 audit_kadmind_auth(rqstp->rq_xprt, l_port,
836 "kadm5_modify_principal",
837 prime_arg, client_name, ret.code);
838 log_done("kadm5_modify_principal", prime_arg,
839 errmsg ? errmsg : "success",
840 client_name, service_name, client_addr(rqstp, buf));
842 if (errmsg != NULL)
843 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
846 error:
847 if (name)
848 gss_release_name(&min_stat, &name);
849 free_server_handle(handle);
850 if (prime_arg)
851 free(prime_arg);
852 if (client_name)
853 free(client_name);
854 if (service_name)
855 free(service_name);
856 return &ret;
859 generic_ret *
860 rename_principal_2_svc(rprinc_arg *arg, struct svc_req *rqstp)
862 static generic_ret ret;
863 char *prime_arg1 = NULL, *prime_arg2 = NULL;
864 char prime_arg[BUFSIZ];
865 char *client_name = NULL, *service_name = NULL;
866 OM_uint32 min_stat;
867 kadm5_server_handle_t handle;
868 restriction_t *rp;
869 const char *errmsg = NULL;
870 gss_name_t name = NULL;
871 size_t tlen1, tlen2, clen, slen;
872 char *tdots1, *tdots2, *cdots, *sdots;
874 xdr_free(xdr_generic_ret, (char *) &ret);
876 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
877 return &ret;
879 if ((ret.code = check_handle((void *)handle)))
880 goto error;
881 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
882 ret.code = KADM5_FAILURE;
883 goto error;
885 if (krb5_unparse_name(handle->context, arg->src, &prime_arg1) ||
886 krb5_unparse_name(handle->context, arg->dest, &prime_arg2)) {
887 ret.code = KADM5_BAD_PRINCIPAL;
888 goto error;
890 tlen1 = strlen(prime_arg1);
891 trunc_name(&tlen1, &tdots1);
892 tlen2 = strlen(prime_arg2);
893 trunc_name(&tlen2, &tdots2);
894 clen = strlen(client_name);
895 trunc_name(&clen, &cdots);
896 slen = strlen(service_name);
897 trunc_name(&slen, &sdots);
899 (void) snprintf(prime_arg, sizeof (prime_arg), "%.*s%s to %.*s*s",
900 tlen1, prime_arg1, tdots1,
901 tlen2, prime_arg2, tdots2);
902 ret.code = KADM5_OK;
904 if (!(name = get_clnt_name(rqstp))) {
905 ret.code = KADM5_FAILURE;
906 goto error;
909 if (! CHANGEPW_SERVICE(rqstp)) {
910 if (!kadm5int_acl_check(handle->context, name,
911 ACL_DELETE, arg->src, NULL))
912 ret.code = KADM5_AUTH_DELETE;
913 /* any restrictions at all on the ADD kills the RENAME */
914 if (!kadm5int_acl_check(handle->context, name,
915 ACL_ADD, arg->dest, &rp)) {
916 if (ret.code == KADM5_AUTH_DELETE)
917 ret.code = KADM5_AUTH_INSUFFICIENT;
918 else
919 ret.code = KADM5_AUTH_ADD;
921 } else
922 ret.code = KADM5_AUTH_INSUFFICIENT;
923 if (ret.code != KADM5_OK) {
925 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
926 "kadm5_rename_principal",
927 prime_arg, client_name);
928 krb5_klog_syslog(LOG_NOTICE,
929 "Unauthorized request: kadm5_rename_principal, "
930 "%.*s%s to %.*s%s, "
931 "client=%.*s%s, service=%.*s%s, addr=%s",
932 tlen1, prime_arg1, tdots1,
933 tlen2, prime_arg2, tdots2,
934 clen, client_name, cdots,
935 slen, service_name, sdots,
936 client_addr(rqstp, buf));
937 } else {
938 ret.code = kadm5_rename_principal((void *)handle, arg->src,
939 arg->dest);
940 /* Solaris Kerberos */
941 if( ret.code != 0 )
942 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
944 audit_kadmind_auth(rqstp->rq_xprt, l_port,
945 "kadm5_rename_principal",
946 prime_arg, client_name, ret.code);
947 krb5_klog_syslog(LOG_NOTICE,
948 "Request: kadm5_rename_principal, "
949 "%.*s%s to %.*s%s, %s, "
950 "client=%.*s%s, service=%.*s%s, addr=%s",
951 tlen1, prime_arg1, tdots1,
952 tlen2, prime_arg2, tdots2,
953 errmsg ? errmsg : "success",
954 clen, client_name, cdots,
955 slen, service_name, sdots,
956 client_addr(rqstp, buf));
958 if (errmsg != NULL)
959 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
962 error:
963 if (name)
964 gss_release_name(&min_stat, &name);
965 free_server_handle(handle);
966 if (prime_arg1)
967 free(prime_arg1);
968 if (prime_arg2)
969 free(prime_arg2);
970 if (client_name)
971 free(client_name);
972 if (service_name)
973 free(service_name);
974 return &ret;
977 gprinc_ret *
978 get_principal_2_svc(gprinc_arg *arg, struct svc_req *rqstp)
980 static gprinc_ret ret;
981 kadm5_principal_ent_t_v1 e;
982 char *prime_arg = NULL, *funcname;
983 char *client_name = NULL, *service_name = NULL;
984 OM_uint32 min_stat;
985 kadm5_server_handle_t handle;
986 const char *errmsg = NULL;
987 gss_name_t name = NULL;
989 xdr_free(xdr_gprinc_ret, (char *) &ret);
991 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
992 return &ret;
994 if ((ret.code = check_handle((void *)handle)))
995 goto error;
996 ret.api_version = handle->api_version;
998 funcname = handle->api_version == KADM5_API_VERSION_1 ?
999 "kadm5_get_principal (V1)" : "kadm5_get_principal";
1001 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1002 ret.code = KADM5_FAILURE;
1003 goto error;
1005 if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) {
1006 ret.code = KADM5_BAD_PRINCIPAL;
1007 goto error;
1009 if (!(name = get_clnt_name(rqstp))) {
1010 ret.code = KADM5_FAILURE;
1011 goto error;
1014 if (! cmp_gss_krb5_name(handle, name, arg->princ) &&
1015 (CHANGEPW_SERVICE(rqstp) || !kadm5int_acl_check(handle->context,
1016 name,
1017 ACL_INQUIRE,
1018 arg->princ,
1019 NULL))) {
1020 ret.code = KADM5_AUTH_GET;
1022 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
1023 funcname,
1024 prime_arg, client_name);
1025 log_unauth(funcname, prime_arg, client_name, service_name,
1026 client_addr(rqstp, buf));
1027 } else {
1028 if (handle->api_version == KADM5_API_VERSION_1) {
1029 ret.code = kadm5_get_principal_v1((void *)handle,
1030 arg->princ, &e);
1031 if(ret.code == KADM5_OK) {
1032 memcpy(&ret.rec, e, sizeof(kadm5_principal_ent_rec_v1));
1033 free(e);
1035 } else {
1036 ret.code = kadm5_get_principal((void *)handle,
1037 arg->princ, &ret.rec,
1038 arg->mask);
1041 /* Solaris Kerberos */
1042 if( ret.code != 0 )
1043 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1045 audit_kadmind_auth(rqstp->rq_xprt, l_port,
1046 funcname,
1047 prime_arg, client_name, ret.code);
1048 log_done(funcname, prime_arg, errmsg ? errmsg : "success",
1049 client_name, service_name, client_addr(rqstp, buf));
1051 if (errmsg != NULL)
1052 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1055 error:
1056 if (name)
1057 gss_release_name(&min_stat, &name);
1058 free_server_handle(handle);
1059 if (prime_arg)
1060 free(prime_arg);
1061 if (client_name)
1062 free(client_name);
1063 if (service_name)
1064 free(service_name);
1065 return &ret;
1068 gprincs_ret *
1069 get_princs_2_svc(gprincs_arg *arg, struct svc_req *rqstp)
1071 static gprincs_ret ret;
1072 char *prime_arg = NULL;
1073 char *client_name = NULL, *service_name = NULL;
1074 OM_uint32 min_stat;
1075 kadm5_server_handle_t handle;
1076 gss_name_t name = NULL;
1077 const char *errmsg = NULL;
1079 xdr_free(xdr_gprincs_ret, (char *) &ret);
1081 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1082 return &ret;
1084 if ((ret.code = check_handle((void *)handle)))
1085 goto error;
1086 ret.api_version = handle->api_version;
1088 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1089 ret.code = KADM5_FAILURE;
1090 goto error;
1092 prime_arg = arg->exp;
1093 if (prime_arg == NULL)
1094 prime_arg = "*";
1096 if (!(name = get_clnt_name(rqstp))) {
1097 ret.code = KADM5_FAILURE;
1098 goto error;
1101 if (CHANGEPW_SERVICE(rqstp) || !kadm5int_acl_check(handle->context,
1102 name,
1103 ACL_LIST,
1104 NULL,
1105 NULL)) {
1106 ret.code = KADM5_AUTH_LIST;
1108 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
1109 "kadm5_get_principals",
1110 prime_arg, client_name);
1111 log_unauth("kadm5_get_principals", prime_arg, client_name,
1112 service_name, client_addr(rqstp, buf));
1113 } else {
1114 ret.code = kadm5_get_principals((void *)handle,
1115 arg->exp, &ret.princs,
1116 &ret.count);
1117 /* Solaris Kerberos */
1118 if( ret.code != 0 )
1119 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1121 audit_kadmind_auth(rqstp->rq_xprt, l_port,
1122 "kadm5_get_principals",
1123 prime_arg, client_name, ret.code);
1124 log_done("kadm5_get_principals", prime_arg,
1125 errmsg ? errmsg : "success",
1126 client_name, service_name, client_addr(rqstp, buf));
1128 if (errmsg != NULL)
1129 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1132 error:
1133 if (name)
1134 gss_release_name(&min_stat, &name);
1135 free_server_handle(handle);
1136 if (client_name)
1137 free(client_name);
1138 if (service_name)
1139 free(service_name);
1140 return (&ret);
1143 generic_ret *
1144 chpass_principal_2_svc(chpass_arg *arg, struct svc_req *rqstp)
1146 static generic_ret ret;
1147 char *prime_arg = NULL;
1148 char *client_name = NULL, *service_name = NULL;
1149 OM_uint32 min_stat;
1150 kadm5_server_handle_t handle;
1151 const char *errmsg = NULL;
1152 gss_name_t name = NULL;
1154 xdr_free(xdr_generic_ret, (char *) &ret);
1156 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1157 return &ret;
1159 if ((ret.code = check_handle((void *)handle)))
1160 goto error;
1161 ret.api_version = handle->api_version;
1163 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1164 ret.code = KADM5_FAILURE;
1165 goto error;
1167 if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) {
1168 ret.code = KADM5_BAD_PRINCIPAL;
1169 goto error;
1171 if (!(name = get_clnt_name(rqstp))) {
1172 ret.code = KADM5_FAILURE;
1173 goto error;
1176 if (cmp_gss_krb5_name(handle, name, arg->princ)) {
1177 ret.code = chpass_principal_wrapper_3((void *)handle, arg->princ,
1178 FALSE, 0, NULL, arg->pass);
1179 } else if (!(CHANGEPW_SERVICE(rqstp)) &&
1180 kadm5int_acl_check(handle->context, name,
1181 ACL_CHANGEPW, arg->princ, NULL)) {
1182 ret.code = kadm5_chpass_principal((void *)handle, arg->princ,
1183 arg->pass);
1184 } else {
1185 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
1186 "kadm5_chpass_principal",
1187 prime_arg, client_name);
1188 log_unauth("kadm5_chpass_principal", prime_arg, client_name,
1189 service_name, client_addr(rqstp, buf));
1190 ret.code = KADM5_AUTH_CHANGEPW;
1193 if(ret.code != KADM5_AUTH_CHANGEPW) {
1194 /* Solaris Kerberos */
1195 if( ret.code != 0 )
1196 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1198 audit_kadmind_auth(rqstp->rq_xprt, l_port,
1199 "kadm5_chpass_principal",
1200 prime_arg, client_name, ret.code);
1201 log_done("kadm5_chpass_principal", prime_arg,
1202 errmsg ? errmsg : "success",
1203 client_name, service_name, client_addr(rqstp, buf));
1205 if (errmsg != NULL)
1206 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1209 error:
1210 if (name)
1211 gss_release_name(&min_stat, &name);
1212 free_server_handle(handle);
1213 if (prime_arg)
1214 free(prime_arg);
1215 if (client_name)
1216 free(client_name);
1217 if (service_name)
1218 free(service_name);
1219 return (&ret);
1222 generic_ret *
1223 chpass_principal3_2_svc(chpass3_arg *arg, struct svc_req *rqstp)
1225 static generic_ret ret;
1226 char *prime_arg = NULL;
1227 char *client_name = NULL,
1228 *service_name = NULL;
1229 OM_uint32 min_stat;
1230 kadm5_server_handle_t handle;
1231 const char *errmsg = NULL;
1232 gss_name_t name = NULL;
1234 xdr_free(xdr_generic_ret, (char *) &ret);
1236 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1237 return &ret;
1239 if ((ret.code = check_handle((void *)handle)))
1240 goto error;
1241 ret.api_version = handle->api_version;
1243 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1244 ret.code = KADM5_FAILURE;
1245 goto error;
1247 if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) {
1248 ret.code = KADM5_BAD_PRINCIPAL;
1249 goto error;
1251 if (!(name = get_clnt_name(rqstp))) {
1252 ret.code = KADM5_FAILURE;
1253 goto error;
1256 if (cmp_gss_krb5_name(handle, name, arg->princ)) {
1257 ret.code = chpass_principal_wrapper_3((void *)handle, arg->princ,
1258 arg->keepold,
1259 arg->n_ks_tuple,
1260 arg->ks_tuple,
1261 arg->pass);
1262 } else if (!(CHANGEPW_SERVICE(rqstp)) &&
1263 kadm5int_acl_check(handle->context, name,
1264 ACL_CHANGEPW, arg->princ, NULL)) {
1265 ret.code = kadm5_chpass_principal_3((void *)handle, arg->princ,
1266 arg->keepold,
1267 arg->n_ks_tuple,
1268 arg->ks_tuple,
1269 arg->pass);
1270 } else {
1271 log_unauth("kadm5_chpass_principal", prime_arg,
1272 client_name, service_name, client_addr(rqstp, buf));
1273 ret.code = KADM5_AUTH_CHANGEPW;
1276 if(ret.code != KADM5_AUTH_CHANGEPW) {
1277 /* Solaris Kerberos */
1278 if( ret.code != 0 )
1279 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1281 log_done("kadm5_chpass_principal", prime_arg,
1282 errmsg ? errmsg : "success",
1283 client_name, service_name, client_addr(rqstp, buf));
1285 if (errmsg != NULL)
1286 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1289 error:
1290 if (name)
1291 gss_release_name(&min_stat, &name);
1292 free_server_handle(handle);
1293 if (client_name)
1294 free(client_name);
1295 if (service_name)
1296 free(service_name);
1297 if (prime_arg)
1298 free(prime_arg);
1299 return (&ret);
1302 #ifdef SUNWOFF
1303 generic_ret *
1304 setv4key_principal_2_svc(setv4key_arg *arg, struct svc_req *rqstp)
1306 static generic_ret ret;
1307 char *prime_arg = NULL;
1308 char *client_name = NULL,
1309 *service_name = NULL;
1310 OM_uint32 min_stat;
1311 kadm5_server_handle_t handle;
1312 const char *errmsg = NULL;
1313 gss_name_t name = NULL;
1315 xdr_free(xdr_generic_ret, (char *) &ret);
1317 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1318 return &ret;
1320 if ((ret.code = check_handle((void *)handle)))
1321 goto error;
1322 ret.api_version = handle->api_version;
1324 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1325 ret.code = KADM5_FAILURE;
1326 goto error;
1328 if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) {
1329 ret.code = KADM5_BAD_PRINCIPAL;
1330 goto error;
1332 if (!(name = get_clnt_name(rqstp))) {
1333 ret.code = KADM5_FAILURE;
1334 goto error;
1337 if (!(CHANGEPW_SERVICE(rqstp)) &&
1338 kadm5int_acl_check(handle->context, name,
1339 ACL_SETKEY, arg->princ, NULL)) {
1340 ret.code = kadm5_setv4key_principal((void *)handle, arg->princ,
1341 arg->keyblock);
1342 } else {
1343 log_unauth("kadm5_setv4key_principal", prime_arg,
1344 client_name, service_name, client_addr(rqstp, buf));
1345 ret.code = KADM5_AUTH_SETKEY;
1348 if(ret.code != KADM5_AUTH_SETKEY) {
1349 /* Solaris Kerberos */
1350 if( ret.code != 0 )
1351 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1353 log_done("kadm5_setv4key_principal", prime_arg,
1354 errmsg ? errmsg : "success",
1355 client_name, service_name, client_addr(rqstp, buf));
1357 if (errmsg != NULL)
1358 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1361 error:
1362 if (name)
1363 gss_release_name(&min_stat, &name);
1364 free_server_handle(handle);
1365 if (client_name)
1366 free(client_name);
1367 if (service_name)
1368 free(service_name);
1369 if (prime_arg)
1370 free(prime_arg);
1371 return (&ret);
1373 #endif
1375 generic_ret *
1376 setkey_principal_2_svc(setkey_arg *arg, struct svc_req *rqstp)
1378 static generic_ret ret;
1379 char *prime_arg;
1380 char *client_name,
1381 *service_name;
1382 OM_uint32 min_stat;
1383 kadm5_server_handle_t handle;
1384 const char *errmsg = NULL;
1385 gss_name_t name;
1387 xdr_free(xdr_generic_ret, (char *) &ret);
1389 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1390 return &ret;
1392 if ((ret.code = check_handle((void *)handle)))
1393 goto error;
1394 ret.api_version = handle->api_version;
1396 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1397 ret.code = KADM5_FAILURE;
1398 goto error;
1400 if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) {
1401 ret.code = KADM5_BAD_PRINCIPAL;
1402 goto error;
1404 if (!(name = get_clnt_name(rqstp))) {
1405 ret.code = KADM5_FAILURE;
1406 goto error;
1409 if (!(CHANGEPW_SERVICE(rqstp)) &&
1410 kadm5int_acl_check(handle->context, name, ACL_SETKEY, arg->princ, NULL)) {
1411 ret.code = kadm5_setkey_principal((void *)handle, arg->princ,
1412 arg->keyblocks, arg->n_keys);
1413 } else {
1414 log_unauth("kadm5_setkey_principal", prime_arg,
1415 client_name, service_name, client_addr(rqstp, buf));
1416 ret.code = KADM5_AUTH_SETKEY;
1419 if(ret.code != KADM5_AUTH_SETKEY) {
1420 /* Solaris Kerberos */
1421 if( ret.code != 0 )
1422 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1424 log_done("kadm5_setkey_principal", prime_arg,
1425 errmsg ? errmsg : "success",
1426 client_name, service_name, client_addr(rqstp, buf));
1428 if (errmsg != NULL)
1429 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1432 error:
1433 if (name)
1434 gss_release_name(&min_stat, &name);
1435 free_server_handle(handle);
1436 if (client_name)
1437 free(client_name);
1438 if (service_name)
1439 free(service_name);
1440 if (prime_arg)
1441 free(prime_arg);
1442 return (&ret);
1445 generic_ret *
1446 setkey_principal3_2_svc(setkey3_arg *arg, struct svc_req *rqstp)
1448 static generic_ret ret;
1449 char *prime_arg = NULL;
1450 char *client_name = NULL,
1451 *service_name = NULL;
1452 OM_uint32 min_stat;
1453 kadm5_server_handle_t handle;
1454 const char *errmsg = NULL;
1455 gss_name_t name = NULL;
1457 xdr_free(xdr_generic_ret, (char *) &ret);
1459 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1460 return &ret;
1462 if ((ret.code = check_handle((void *)handle)))
1463 goto error;
1464 ret.api_version = handle->api_version;
1466 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1467 ret.code = KADM5_FAILURE;
1468 goto error;
1470 if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) {
1471 ret.code = KADM5_BAD_PRINCIPAL;
1472 goto error;
1474 if (!(name = get_clnt_name(rqstp))) {
1475 ret.code = KADM5_FAILURE;
1476 goto error;
1479 if (!(CHANGEPW_SERVICE(rqstp)) &&
1480 kadm5int_acl_check(handle->context, name,
1481 ACL_SETKEY, arg->princ, NULL)) {
1482 ret.code = kadm5_setkey_principal_3((void *)handle, arg->princ,
1483 arg->keepold,
1484 arg->n_ks_tuple,
1485 arg->ks_tuple,
1486 arg->keyblocks, arg->n_keys);
1487 } else {
1488 log_unauth("kadm5_setkey_principal", prime_arg,
1489 client_name, service_name, client_addr(rqstp, buf));
1490 ret.code = KADM5_AUTH_SETKEY;
1493 if(ret.code != KADM5_AUTH_SETKEY) {
1494 /* Solaris Kerberos */
1495 if( ret.code != 0 )
1496 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1498 log_done("kadm5_setkey_principal", prime_arg,
1499 errmsg ? errmsg : "success",
1500 client_name, service_name, client_addr(rqstp, buf));
1502 if (errmsg != NULL)
1503 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1506 error:
1507 if (name)
1508 gss_release_name(&min_stat, &name);
1509 free_server_handle(handle);
1510 if (client_name)
1511 free(client_name);
1512 if (service_name)
1513 free(service_name);
1514 if (prime_arg)
1515 free(prime_arg);
1516 return &ret;
1519 chrand_ret *
1520 chrand_principal_2_svc(chrand_arg *arg, struct svc_req *rqstp)
1522 static chrand_ret ret;
1523 krb5_keyblock *k;
1524 int nkeys;
1525 char *prime_arg = NULL, *funcname;
1526 char *client_name = NULL, *service_name = NULL;
1527 OM_uint32 min_stat;
1528 kadm5_server_handle_t handle;
1529 const char *errmsg = NULL;
1530 gss_name_t name = NULL;
1532 xdr_free(xdr_chrand_ret, (char *) &ret);
1534 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1535 return &ret;
1537 if ((ret.code = check_handle((void *)handle)))
1538 goto error;
1540 ret.api_version = handle->api_version;
1542 funcname = handle->api_version == KADM5_API_VERSION_1 ?
1543 "kadm5_randkey_principal (V1)" : "kadm5_randkey_principal";
1545 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1546 ret.code = KADM5_FAILURE;
1547 goto error;
1549 if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) {
1550 ret.code = KADM5_BAD_PRINCIPAL;
1551 goto error;
1553 if (!(name = get_clnt_name(rqstp))) {
1554 ret.code = KADM5_FAILURE;
1555 goto error;
1558 if (cmp_gss_krb5_name(handle, name, arg->princ)) {
1559 ret.code = randkey_principal_wrapper((void *)handle, arg->princ, &k,
1560 &nkeys);
1561 } else if (!(CHANGEPW_SERVICE(rqstp)) &&
1562 kadm5int_acl_check(handle->context, name,
1563 ACL_CHANGEPW, arg->princ, NULL)) {
1564 ret.code = kadm5_randkey_principal((void *)handle, arg->princ,
1565 &k, &nkeys);
1566 } else {
1567 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
1568 funcname, prime_arg, client_name);
1569 log_unauth(funcname, prime_arg,
1570 client_name, service_name, client_addr(rqstp, buf));
1571 ret.code = KADM5_AUTH_CHANGEPW;
1574 if(ret.code == KADM5_OK) {
1575 if (handle->api_version == KADM5_API_VERSION_1) {
1576 krb5_copy_keyblock_contents(handle->context, k, &ret.key);
1577 krb5_free_keyblock(handle->context, k);
1578 } else {
1579 ret.keys = k;
1580 ret.n_keys = nkeys;
1584 if(ret.code != KADM5_AUTH_CHANGEPW) {
1585 /* Solaris Kerberos */
1586 if( ret.code != 0 )
1587 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1589 audit_kadmind_auth(rqstp->rq_xprt, l_port,
1590 funcname, prime_arg, client_name, ret.code);
1591 log_done(funcname, prime_arg, errmsg ? errmsg : "success",
1592 client_name, service_name, client_addr(rqstp, buf));
1594 if (errmsg != NULL)
1595 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1598 error:
1599 if (name)
1600 gss_release_name(&min_stat, &name);
1601 free_server_handle(handle);
1602 if (prime_arg)
1603 free(prime_arg);
1604 if (client_name)
1605 free(client_name);
1606 if (service_name)
1607 free(service_name);
1608 return &ret;
1611 chrand_ret *
1612 chrand_principal3_2_svc(chrand3_arg *arg, struct svc_req *rqstp)
1614 static chrand_ret ret;
1615 krb5_keyblock *k;
1616 int nkeys;
1617 char *prime_arg = NULL, *funcname;
1618 char *client_name = NULL,
1619 *service_name = NULL;
1620 OM_uint32 min_stat;
1621 kadm5_server_handle_t handle;
1622 const char *errmsg = NULL;
1623 gss_name_t name = NULL;
1625 xdr_free(xdr_chrand_ret, (char *) &ret);
1627 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1628 return &ret;
1630 if ((ret.code = check_handle((void *)handle)))
1631 goto error;
1632 ret.api_version = handle->api_version;
1634 funcname = handle->api_version == KADM5_API_VERSION_1 ?
1635 "kadm5_randkey_principal (V1)" : "kadm5_randkey_principal";
1637 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1638 ret.code = KADM5_FAILURE;
1639 goto error;
1641 if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) {
1642 ret.code = KADM5_BAD_PRINCIPAL;
1643 goto error;
1645 if (!(name = get_clnt_name(rqstp))) {
1646 ret.code = KADM5_FAILURE;
1647 goto error;
1650 if (cmp_gss_krb5_name(handle, name, arg->princ)) {
1651 ret.code = randkey_principal_wrapper_3((void *)handle, arg->princ,
1652 arg->keepold,
1653 arg->n_ks_tuple,
1654 arg->ks_tuple,
1655 &k, &nkeys);
1656 } else if (!(CHANGEPW_SERVICE(rqstp)) &&
1657 kadm5int_acl_check(handle->context, name,
1658 ACL_CHANGEPW, arg->princ, NULL)) {
1659 ret.code = kadm5_randkey_principal_3((void *)handle, arg->princ,
1660 arg->keepold,
1661 arg->n_ks_tuple,
1662 arg->ks_tuple,
1663 &k, &nkeys);
1664 } else {
1665 log_unauth(funcname, prime_arg,
1666 client_name, service_name, client_addr(rqstp, buf));
1667 ret.code = KADM5_AUTH_CHANGEPW;
1670 if(ret.code == KADM5_OK) {
1671 if (handle->api_version == KADM5_API_VERSION_1) {
1672 krb5_copy_keyblock_contents(handle->context, k, &ret.key);
1673 krb5_free_keyblock(handle->context, k);
1674 } else {
1675 ret.keys = k;
1676 ret.n_keys = nkeys;
1680 if(ret.code != KADM5_AUTH_CHANGEPW) {
1681 /* Solaris Kerberos */
1682 if( ret.code != 0 )
1683 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1685 log_done(funcname, prime_arg, errmsg ? errmsg : "success",
1686 client_name, service_name, client_addr(rqstp, buf));
1688 if (errmsg != NULL)
1689 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1692 error:
1693 if (name)
1694 gss_release_name(&min_stat, &name);
1695 free_server_handle(handle);
1696 if (client_name)
1697 free(client_name);
1698 if (service_name)
1699 free(service_name);
1700 if (prime_arg)
1701 free(prime_arg);
1702 return (&ret);
1705 generic_ret *
1706 create_policy_2_svc(cpol_arg *arg, struct svc_req *rqstp)
1708 static generic_ret ret;
1709 char *prime_arg = NULL;
1710 char *client_name = NULL, *service_name = NULL;
1711 OM_uint32 min_stat;
1712 kadm5_server_handle_t handle;
1713 const char *errmsg = NULL;
1714 gss_name_t name = NULL;
1716 xdr_free(xdr_generic_ret, (char *) &ret);
1718 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1719 return &ret;
1721 if ((ret.code = check_handle((void *)handle)))
1722 goto error;
1724 ret.api_version = handle->api_version;
1726 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1727 ret.code = KADM5_FAILURE;
1728 goto error;
1730 prime_arg = arg->rec.policy;
1732 if (!(name = get_clnt_name(rqstp))) {
1733 ret.code = KADM5_FAILURE;
1734 goto error;
1737 if (CHANGEPW_SERVICE(rqstp) || !kadm5int_acl_check(handle->context,
1738 name,
1739 ACL_ADD, NULL, NULL)) {
1740 ret.code = KADM5_AUTH_ADD;
1742 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
1743 "kadm5_create_policy",
1744 prime_arg, client_name);
1745 log_unauth("kadm5_create_policy", prime_arg,
1746 client_name, service_name, client_addr(rqstp, buf));
1748 } else {
1749 ret.code = kadm5_create_policy((void *)handle, &arg->rec,
1750 arg->mask);
1751 /* Solaris Kerberos */
1752 if( ret.code != 0 )
1753 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1755 audit_kadmind_auth(rqstp->rq_xprt, l_port,
1756 "kadm5_create_policy",
1757 prime_arg, client_name, ret.code);
1758 log_done("kadm5_create_policy",
1759 ((prime_arg == NULL) ? "(null)" : prime_arg),
1760 errmsg ? errmsg : "success",
1761 client_name, service_name, client_addr(rqstp, buf));
1763 if (errmsg != NULL)
1764 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1767 error:
1768 if (name)
1769 gss_release_name(&min_stat, &name);
1770 free_server_handle(handle);
1771 if (client_name)
1772 free(client_name);
1773 if (service_name)
1774 free(service_name);
1775 return &ret;
1778 generic_ret *
1779 delete_policy_2_svc(dpol_arg *arg, struct svc_req *rqstp)
1781 static generic_ret ret;
1782 char *prime_arg = NULL;
1783 char *client_name = NULL, *service_name = NULL;
1784 OM_uint32 min_stat;
1785 kadm5_server_handle_t handle;
1786 const char *errmsg = NULL;
1787 gss_name_t name = NULL;
1789 xdr_free(xdr_generic_ret, (char *) &ret);
1791 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1792 return &ret;
1794 if ((ret.code = check_handle((void *)handle)))
1795 goto error;
1796 ret.api_version = handle->api_version;
1798 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1799 ret.code = KADM5_FAILURE;
1800 goto error;
1802 prime_arg = arg->name;
1804 if (!(name = get_clnt_name(rqstp))) {
1805 ret.code = KADM5_FAILURE;
1806 goto error;
1809 if (CHANGEPW_SERVICE(rqstp) || !kadm5int_acl_check(handle->context,
1810 name,
1811 ACL_DELETE, NULL, NULL)) {
1813 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
1814 "kadm5_delete_policy",
1815 prime_arg, client_name);
1816 log_unauth("kadm5_delete_policy", prime_arg,
1817 client_name, service_name, client_addr(rqstp, buf));
1818 ret.code = KADM5_AUTH_DELETE;
1819 } else {
1820 ret.code = kadm5_delete_policy((void *)handle, arg->name);
1821 /* Solaris Kerberos */
1822 if( ret.code != 0 )
1823 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1825 audit_kadmind_auth(rqstp->rq_xprt, l_port,
1826 "kadm5_delete_policy",
1827 prime_arg, client_name, ret.code);
1828 log_done("kadm5_delete_policy",
1829 ((prime_arg == NULL) ? "(null)" : prime_arg),
1830 errmsg ? errmsg : "success",
1831 client_name, service_name, client_addr(rqstp, buf));
1833 if (errmsg != NULL)
1834 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1837 error:
1838 if (name)
1839 gss_release_name(&min_stat, &name);
1840 free_server_handle(handle);
1841 if (client_name)
1842 free(client_name);
1843 if (service_name)
1844 free(service_name);
1845 return &ret;
1848 generic_ret *
1849 modify_policy_2_svc(mpol_arg *arg, struct svc_req *rqstp)
1851 static generic_ret ret;
1852 char *prime_arg = NULL;
1853 char *client_name = NULL, *service_name = NULL;
1854 OM_uint32 min_stat;
1855 kadm5_server_handle_t handle;
1856 const char *errmsg = NULL;
1857 gss_name_t name = NULL;
1859 xdr_free(xdr_generic_ret, (char *) &ret);
1861 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1862 return &ret;
1864 if ((ret.code = check_handle((void *)handle)))
1865 goto error;
1866 ret.api_version = handle->api_version;
1868 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1869 ret.code = KADM5_FAILURE;
1870 goto error;
1872 prime_arg = arg->rec.policy;
1874 if (!(name = get_clnt_name(rqstp))) {
1875 ret.code = KADM5_FAILURE;
1876 goto error;
1879 if (CHANGEPW_SERVICE(rqstp) || !kadm5int_acl_check(handle->context,
1880 name,
1881 ACL_MODIFY, NULL, NULL)) {
1883 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
1884 "kadm5_modify_policy",
1885 prime_arg, client_name);
1886 log_unauth("kadm5_modify_policy", prime_arg,
1887 client_name, service_name, client_addr(rqstp, buf));
1888 ret.code = KADM5_AUTH_MODIFY;
1889 } else {
1890 ret.code = kadm5_modify_policy((void *)handle, &arg->rec,
1891 arg->mask);
1892 /* Solaris Kerberos */
1893 if( ret.code != 0 )
1894 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1896 audit_kadmind_auth(rqstp->rq_xprt, l_port,
1897 "kadm5_modify_policy",
1898 prime_arg, client_name, ret.code);
1899 log_done("kadm5_modify_policy",
1900 ((prime_arg == NULL) ? "(null)" : prime_arg),
1901 errmsg ? errmsg : "success",
1902 client_name, service_name, client_addr(rqstp, buf));
1904 if (errmsg != NULL)
1905 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
1908 error:
1909 if (name)
1910 gss_release_name(&min_stat, &name);
1911 free_server_handle(handle);
1912 if (client_name)
1913 free(client_name);
1914 if (service_name)
1915 free(service_name);
1916 return (&ret);
1919 gpol_ret *
1920 get_policy_2_svc(gpol_arg *arg, struct svc_req *rqstp)
1922 static gpol_ret ret;
1923 kadm5_ret_t ret2;
1924 char *prime_arg = NULL, *funcname;
1925 char *client_name = NULL, *service_name = NULL;
1926 OM_uint32 min_stat;
1927 kadm5_policy_ent_t e;
1928 kadm5_principal_ent_rec caller_ent;
1929 krb5_principal caller;
1930 kadm5_server_handle_t handle;
1931 const char *errmsg = NULL;
1932 gss_name_t name = NULL;
1934 xdr_free(xdr_gpol_ret, (char *) &ret);
1936 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
1937 return &ret;
1939 if ((ret.code = check_handle((void *) handle)))
1940 goto error;
1942 ret.api_version = handle->api_version;
1944 funcname = handle->api_version == KADM5_API_VERSION_1 ?
1945 "kadm5_get_policy (V1)" : "kadm5_get_policy";
1947 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
1948 ret.code = KADM5_FAILURE;
1949 goto error;
1951 prime_arg = arg->name;
1952 ret.code = KADM5_AUTH_GET;
1954 if (!(name = get_clnt_name(rqstp))) {
1955 ret.code = KADM5_FAILURE;
1956 goto error;
1959 if (!CHANGEPW_SERVICE(rqstp) && kadm5int_acl_check(handle->context,
1960 name,
1961 ACL_INQUIRE, NULL, NULL))
1962 ret.code = KADM5_OK;
1963 else {
1964 ret.code = kadm5_get_principal(handle->lhandle,
1965 handle->current_caller,
1966 &caller_ent,
1967 KADM5_PRINCIPAL_NORMAL_MASK);
1968 if (ret.code == KADM5_OK) {
1969 if (caller_ent.aux_attributes & KADM5_POLICY &&
1970 strcmp(caller_ent.policy, arg->name) == 0) {
1971 ret.code = KADM5_OK;
1972 } else ret.code = KADM5_AUTH_GET;
1973 ret2 = kadm5_free_principal_ent(handle->lhandle,
1974 &caller_ent);
1975 ret.code = ret.code ? ret.code : ret2;
1979 if (ret.code == KADM5_OK) {
1980 if (handle->api_version == KADM5_API_VERSION_1) {
1981 ret.code = kadm5_get_policy_v1((void *)handle, arg->name, &e);
1982 if(ret.code == KADM5_OK) {
1983 memcpy(&ret.rec, e, sizeof(kadm5_policy_ent_rec));
1984 free(e);
1986 } else {
1987 ret.code = kadm5_get_policy((void *)handle, arg->name,
1988 &ret.rec);
1991 /* Solaris Kerberos */
1992 if( ret.code != 0 )
1993 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
1995 audit_kadmind_auth(rqstp->rq_xprt, l_port,
1996 funcname, prime_arg, client_name, ret.code);
1997 log_done(funcname,
1998 ((prime_arg == NULL) ? "(null)" : prime_arg),
1999 errmsg ? errmsg : "success",
2000 client_name, service_name, client_addr(rqstp, buf));
2002 if (errmsg != NULL)
2003 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
2005 } else {
2006 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
2007 funcname, prime_arg, client_name);
2008 log_unauth(funcname, prime_arg,
2009 client_name, service_name, client_addr(rqstp, buf));
2012 error:
2013 if (name)
2014 gss_release_name(&min_stat, &name);
2015 free_server_handle(handle);
2016 if (client_name)
2017 free(client_name);
2018 if (service_name)
2019 free(service_name);
2020 return (&ret);
2024 gpols_ret *
2025 get_pols_2_svc(gpols_arg *arg, struct svc_req *rqstp)
2027 static gpols_ret ret;
2028 char *prime_arg = NULL;
2029 char *client_name = NULL, *service_name = NULL;
2030 OM_uint32 min_stat;
2031 kadm5_server_handle_t handle;
2032 const char *errmsg = NULL;
2033 gss_name_t name = NULL;
2035 xdr_free(xdr_gpols_ret, (char *) &ret);
2037 if ((ret.code = new_server_handle(arg->api_version, rqstp, &handle)))
2038 return &ret;
2040 if ((ret.code = check_handle((void *)handle)))
2041 goto error;
2043 ret.api_version = handle->api_version;
2045 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
2046 ret.code = KADM5_FAILURE;
2047 goto error;
2049 prime_arg = arg->exp;
2050 if (prime_arg == NULL)
2051 prime_arg = "*";
2053 if (!(name = get_clnt_name(rqstp))) {
2054 ret.code = KADM5_FAILURE;
2055 goto error;
2058 if (CHANGEPW_SERVICE(rqstp) || !kadm5int_acl_check(handle->context,
2059 name,
2060 ACL_LIST, NULL, NULL)) {
2061 ret.code = KADM5_AUTH_LIST;
2063 audit_kadmind_unauth(rqstp->rq_xprt, l_port,
2064 "kadm5_get_policies",
2065 prime_arg, client_name);
2066 log_unauth("kadm5_get_policies", prime_arg,
2067 client_name, service_name, client_addr(rqstp, buf));
2068 } else {
2069 ret.code = kadm5_get_policies((void *)handle,
2070 arg->exp, &ret.pols,
2071 &ret.count);
2072 /* Solaris Kerberos */
2073 if( ret.code != 0 )
2074 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
2076 audit_kadmind_auth(rqstp->rq_xprt, l_port,
2077 "kadm5_get_policies",
2078 prime_arg, client_name, ret.code);
2079 log_done("kadm5_get_policies", prime_arg,
2080 errmsg ? errmsg : "success",
2081 client_name, service_name, client_addr(rqstp, buf));
2083 if (errmsg != NULL)
2084 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
2087 error:
2088 if (name)
2089 gss_release_name(&min_stat, &name);
2090 free_server_handle(handle);
2091 if (client_name)
2092 free(client_name);
2093 if (service_name)
2094 free(service_name);
2095 return (&ret);
2098 getprivs_ret * get_privs_2_svc(krb5_ui_4 *arg, struct svc_req *rqstp)
2100 static getprivs_ret ret;
2101 char *client_name = NULL, *service_name = NULL;
2102 OM_uint32 min_stat;
2103 kadm5_server_handle_t handle;
2104 const char *errmsg = NULL;
2105 gss_name_t name = NULL;
2107 xdr_free(xdr_getprivs_ret, (char *) &ret);
2109 if ((ret.code = new_server_handle(*arg, rqstp, &handle)))
2110 return &ret;
2112 if ((ret.code = check_handle((void *)handle)))
2113 goto error;
2115 ret.api_version = handle->api_version;
2117 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
2118 ret.code = KADM5_FAILURE;
2119 goto error;
2121 if (!(name = get_clnt_name(rqstp))) {
2122 ret.code = KADM5_FAILURE;
2123 goto error;
2126 ret.code = __kadm5_get_priv((void *) handle, &ret.privs, name);
2127 /* Solaris Kerberos */
2128 if( ret.code != 0 )
2129 errmsg = krb5_get_error_message(handle ? handle->context : NULL, ret.code);
2131 audit_kadmind_auth(rqstp->rq_xprt, l_port,
2132 "kadm5_get_privs", NULL, client_name,
2133 ret.code);
2134 log_done("kadm5_get_privs", client_name,
2135 errmsg ? errmsg : "success",
2136 client_name, service_name, client_addr(rqstp, buf));
2138 if (errmsg != NULL)
2139 krb5_free_error_message(handle ? handle->context : NULL, errmsg);
2141 error:
2142 if (name)
2143 gss_release_name(&min_stat, &name);
2144 free_server_handle(handle);
2145 if (client_name)
2146 free(client_name);
2147 if (service_name)
2148 free(service_name);
2149 return (&ret);
2152 generic_ret *init_2_svc(krb5_ui_4 *arg, struct svc_req *rqstp)
2154 static generic_ret ret;
2155 char *client_name, *service_name;
2156 kadm5_server_handle_t handle;
2157 const char *errmsg = NULL;
2158 size_t clen, slen;
2159 char *cdots, *sdots;
2161 xdr_free(xdr_generic_ret, (char *) &ret);
2163 if ((ret.code = new_server_handle(*arg, rqstp, &handle)))
2164 return &ret;
2165 if (! (ret.code = check_handle((void *)handle))) {
2166 ret.api_version = handle->api_version;
2169 free_server_handle(handle);
2171 if (setup_gss_names(rqstp, &client_name, &service_name) < 0) {
2172 ret.code = KADM5_FAILURE;
2173 return &ret;
2176 /* Solaris Kerberos */
2177 if (ret.code != 0)
2178 errmsg = krb5_get_error_message(NULL, ret.code);
2180 audit_kadmind_auth(rqstp->rq_xprt, l_port,
2181 (ret.api_version == KADM5_API_VERSION_1 ?
2182 "kadm5_init (V1)" : "kadm5_init"),
2183 NULL, client_name, ret.code);
2185 clen = strlen(client_name);
2186 trunc_name(&clen, &cdots);
2187 slen = strlen(service_name);
2188 trunc_name(&slen, &sdots);
2189 krb5_klog_syslog(LOG_NOTICE, "Request: %s, %.*s%s, %s, "
2190 "client=%.*s%s, service=%.*s%s, addr=%s, flavor=%d",
2191 (ret.api_version == KADM5_API_VERSION_1 ?
2192 "kadm5_init (V1)" : "kadm5_init"),
2193 clen, client_name, cdots,
2194 errmsg ? errmsg : "success",
2195 clen, client_name, cdots,
2196 slen, service_name, sdots,
2197 client_addr(rqstp, buf),
2198 rqstp->rq_cred.oa_flavor);
2199 if (errmsg != NULL)
2200 krb5_free_error_message(NULL, errmsg);
2201 free(client_name);
2202 free(service_name);
2204 return (&ret);