2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
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
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>
38 #include <arpa/inet.h> /* inet_ntoa */
39 #include <krb5/adm_proto.h> /* krb5_klog_syslog */
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
;
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
);
71 kadm5_get_priv(void *server_handle
,
72 long *privs
, gss_name_t clnt
);
75 get_clnt_name(struct svc_req
* rqstp
)
77 OM_uint32 maj_stat
, min_stat
;
79 rpc_gss_rawcred_t
*raw_cred
;
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
) {
95 client_addr(struct svc_req
* req
, char *buf
)
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);
113 * No IP address to print. If there was a host name
114 * printed, then we print a space.
116 (void) sprintf(buf
, frontspace
);
122 static int cmp_gss_names(gss_name_t n1
, gss_name_t n2
)
124 OM_uint32 emaj
, emin
;
127 if (GSS_ERROR(emaj
= gss_compare_name(&emin
, n1
, n2
, &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
)
140 ret
= cmp_gss_names(n1
, n2
);
141 if (n1
) (void) gss_release_name(&min_stat
, &n1
);
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.
153 * handle The server handle.
156 static int check_handle(void *handle
)
158 CHECK_HANDLE(handle
);
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
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
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
191 kadm5_server_handle_t handle
;
195 if (! (handle
= (kadm5_server_handle_t
)
196 malloc(sizeof(*handle
))))
199 *handle
= *(kadm5_server_handle_t
)global_server_handle
;
200 handle
->api_version
= api_version
;
202 if (!(name
= get_clnt_name(rqstp
))) {
204 return KADM5_FAILURE
;
206 if (! gss_to_krb5_name(handle
, name
, &handle
->current_caller
)) {
208 gss_release_name(&min_stat
, &name
);
209 return KADM5_FAILURE
;
211 gss_release_name(&min_stat
, &name
);
213 *out_handle
= handle
;
218 * Function: free_server_handle
220 * Purpose: Free handle memory allocated by new_server_handle
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
);
232 * Function: setup_gss_names
234 * Purpose: Create printable representations of the client and server
238 * rqstp (r) the RPC request
239 * client_name (w) pointer to client_name string
240 * server_name (w) pointer to server_name string
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.
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
;
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
)
270 if (!(name
= get_clnt_name(rqstp
))) {
275 maj_stat
= gss_display_name(&min_stat
, name
, &name_buf
, NULL
);
276 if (maj_stat
!= GSS_S_COMPLETE
) {
278 gss_release_name(&min_stat
, &name
);
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. */
296 memcpy(tmp
, val
, len
- 1);
303 /* Were done with the GSS buffer */
304 (void) gss_release_buffer(&min_stat
, &name_buf
);
308 return (tmp
? 0 : -1);
311 static gss_name_t
acceptor_name(struct svc_req
* rqstp
)
313 OM_uint32 maj_stat
, min_stat
;
315 rpc_gss_rawcred_t
*raw_cred
;
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
);
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
);
333 gss_release_buffer(&min_stat
, &name_buff
);
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
;
344 if (! gss_to_krb5_name(handle
, gss_name
, &princ2
))
346 status
= krb5_principal_compare(handle
->context
, princ
, princ2
);
347 krb5_free_principal(handle
->context
, princ2
);
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
) {
370 ptr
= strchr(userdata
, '@');
372 user
= (char *)malloc(ptr
- userdata
+ 1);
373 (void) strlcpy(user
, userdata
, (ptr
- userdata
) + 1);
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
));
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
);
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
);
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
);
413 (void) pam_end(pamh
, PAM_SUCCESS
);
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
;
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
)))
428 success
= (krb5_parse_name(handle
->context
, gss_str
.value
, princ
) == 0);
429 gss_release_buffer(&minor_stat
, &gss_str
);
434 gss_name_to_string(gss_name_t gss_name
, gss_buffer_desc
*str
)
436 OM_uint32 status
, minor_stat
;
439 status
= gss_display_name(&minor_stat
, gss_name
, str
, &gss_type
);
440 if ((status
!= GSS_S_COMPLETE
) || (gss_type
!= gss_nt_krb5_name
))
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
,
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
,
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
;
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
)))
520 if ((ret
.code
= check_handle((void *)handle
)))
522 ret
.api_version
= handle
->api_version
;
524 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
525 ret
.code
= KADM5_FAILURE
;
528 if (krb5_unparse_name(handle
->context
, arg
->rec
.principal
, &prime_arg
)) {
529 ret
.code
= KADM5_BAD_PRINCIPAL
;
532 if (!(name
= get_clnt_name(rqstp
))) {
533 ret
.code
= KADM5_FAILURE
;
537 if (kadm5int_acl_check(handle
->context
, name
, ACL_MIGRATE
,
538 arg
->rec
.principal
, &rp
) &&
539 verify_pam_pw(prime_arg
, arg
->passwd
)) {
543 if (CHANGEPW_SERVICE(rqstp
)
544 || (!kadm5int_acl_check(handle
->context
, name
, ACL_ADD
,
545 arg
->rec
.principal
, &rp
) &&
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
));
557 ret
.code
= kadm5_create_principal((void *)handle
,
558 &arg
->rec
, arg
->mask
,
560 /* Solaris Kerberos */
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
));
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
)) {
578 arg
->mask
|= KADM5_POLICY
;
579 arg
->mask
|= KADM5_PW_EXPIRATION
;
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
));
596 gss_release_name(&minor_stat
, &name
);
597 free_server_handle(handle
);
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
;
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
)))
627 if ((ret
.code
= check_handle((void *)handle
)))
629 ret
.api_version
= handle
->api_version
;
631 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
632 ret
.code
= KADM5_FAILURE
;
635 if (krb5_unparse_name(handle
->context
, arg
->rec
.principal
, &prime_arg
)) {
636 ret
.code
= KADM5_BAD_PRINCIPAL
;
639 if (!(name
= get_clnt_name(rqstp
))) {
640 ret
.code
= KADM5_FAILURE
;
644 if (kadm5int_acl_check(handle
->context
, name
, ACL_MIGRATE
,
645 arg
->rec
.principal
, &rp
) &&
646 verify_pam_pw(prime_arg
, arg
->passwd
)) {
650 if (CHANGEPW_SERVICE(rqstp
)
651 || (!kadm5int_acl_check(handle
->context
, name
, ACL_ADD
,
652 arg
->rec
.principal
, &rp
) &&
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
));
660 ret
.code
= kadm5_create_principal_3((void *)handle
,
661 &arg
->rec
, arg
->mask
,
665 /* Solaris Kerberos */
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
));
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
)) {
680 arg
->mask
|= KADM5_POLICY
;
681 arg
->mask
|= KADM5_PW_EXPIRATION
;
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
));
697 gss_release_name(&minor_stat
, &name
);
698 free_server_handle(handle
);
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
;
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
)))
726 if ((ret
.code
= check_handle((void *)handle
)))
728 ret
.api_version
= handle
->api_version
;
730 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
731 ret
.code
= KADM5_FAILURE
;
734 if (krb5_unparse_name(handle
->context
, arg
->princ
, &prime_arg
)) {
735 ret
.code
= KADM5_BAD_PRINCIPAL
;
738 if (!(name
= get_clnt_name(rqstp
))) {
739 ret
.code
= KADM5_FAILURE
;
743 if (CHANGEPW_SERVICE(rqstp
)
744 || !kadm5int_acl_check(handle
->context
, name
, ACL_DELETE
,
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
));
754 ret
.code
= kadm5_delete_principal((void *)handle
, arg
->princ
);
755 /* Solaris Kerberos */
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
));
767 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
773 gss_release_name(&min_stat
, &name
);
776 free_server_handle(handle
);
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
;
791 kadm5_server_handle_t handle
;
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
)))
801 if ((ret
.code
= check_handle((void *)handle
)))
803 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
804 ret
.code
= KADM5_FAILURE
;
807 if (krb5_unparse_name(handle
->context
, arg
->rec
.principal
, &prime_arg
)) {
808 ret
.code
= KADM5_BAD_PRINCIPAL
;
811 if (!(name
= get_clnt_name(rqstp
))) {
812 ret
.code
= KADM5_FAILURE
;
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
));
829 ret
.code
= kadm5_modify_principal((void *)handle
, &arg
->rec
,
831 /* Solaris Kerberos */
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
));
843 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
848 gss_release_name(&min_stat
, &name
);
849 free_server_handle(handle
);
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
;
867 kadm5_server_handle_t handle
;
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
)))
879 if ((ret
.code
= check_handle((void *)handle
)))
881 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
882 ret
.code
= KADM5_FAILURE
;
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
;
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
);
904 if (!(name
= get_clnt_name(rqstp
))) {
905 ret
.code
= KADM5_FAILURE
;
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
;
919 ret
.code
= KADM5_AUTH_ADD
;
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, "
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
));
938 ret
.code
= kadm5_rename_principal((void *)handle
, arg
->src
,
940 /* Solaris Kerberos */
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
));
959 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
964 gss_release_name(&min_stat
, &name
);
965 free_server_handle(handle
);
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
;
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
)))
994 if ((ret
.code
= check_handle((void *)handle
)))
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
;
1005 if (krb5_unparse_name(handle
->context
, arg
->princ
, &prime_arg
)) {
1006 ret
.code
= KADM5_BAD_PRINCIPAL
;
1009 if (!(name
= get_clnt_name(rqstp
))) {
1010 ret
.code
= KADM5_FAILURE
;
1014 if (! cmp_gss_krb5_name(handle
, name
, arg
->princ
) &&
1015 (CHANGEPW_SERVICE(rqstp
) || !kadm5int_acl_check(handle
->context
,
1020 ret
.code
= KADM5_AUTH_GET
;
1022 audit_kadmind_unauth(rqstp
->rq_xprt
, l_port
,
1024 prime_arg
, client_name
);
1025 log_unauth(funcname
, prime_arg
, client_name
, service_name
,
1026 client_addr(rqstp
, buf
));
1028 if (handle
->api_version
== KADM5_API_VERSION_1
) {
1029 ret
.code
= kadm5_get_principal_v1((void *)handle
,
1031 if(ret
.code
== KADM5_OK
) {
1032 memcpy(&ret
.rec
, e
, sizeof(kadm5_principal_ent_rec_v1
));
1036 ret
.code
= kadm5_get_principal((void *)handle
,
1037 arg
->princ
, &ret
.rec
,
1041 /* Solaris Kerberos */
1043 errmsg
= krb5_get_error_message(handle
? handle
->context
: NULL
, ret
.code
);
1045 audit_kadmind_auth(rqstp
->rq_xprt
, l_port
,
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
));
1052 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1057 gss_release_name(&min_stat
, &name
);
1058 free_server_handle(handle
);
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
;
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
)))
1084 if ((ret
.code
= check_handle((void *)handle
)))
1086 ret
.api_version
= handle
->api_version
;
1088 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
1089 ret
.code
= KADM5_FAILURE
;
1092 prime_arg
= arg
->exp
;
1093 if (prime_arg
== NULL
)
1096 if (!(name
= get_clnt_name(rqstp
))) {
1097 ret
.code
= KADM5_FAILURE
;
1101 if (CHANGEPW_SERVICE(rqstp
) || !kadm5int_acl_check(handle
->context
,
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
));
1114 ret
.code
= kadm5_get_principals((void *)handle
,
1115 arg
->exp
, &ret
.princs
,
1117 /* Solaris Kerberos */
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
));
1129 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1134 gss_release_name(&min_stat
, &name
);
1135 free_server_handle(handle
);
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
;
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
)))
1159 if ((ret
.code
= check_handle((void *)handle
)))
1161 ret
.api_version
= handle
->api_version
;
1163 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
1164 ret
.code
= KADM5_FAILURE
;
1167 if (krb5_unparse_name(handle
->context
, arg
->princ
, &prime_arg
)) {
1168 ret
.code
= KADM5_BAD_PRINCIPAL
;
1171 if (!(name
= get_clnt_name(rqstp
))) {
1172 ret
.code
= KADM5_FAILURE
;
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
,
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 */
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
));
1206 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1211 gss_release_name(&min_stat
, &name
);
1212 free_server_handle(handle
);
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
;
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
)))
1239 if ((ret
.code
= check_handle((void *)handle
)))
1241 ret
.api_version
= handle
->api_version
;
1243 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
1244 ret
.code
= KADM5_FAILURE
;
1247 if (krb5_unparse_name(handle
->context
, arg
->princ
, &prime_arg
)) {
1248 ret
.code
= KADM5_BAD_PRINCIPAL
;
1251 if (!(name
= get_clnt_name(rqstp
))) {
1252 ret
.code
= KADM5_FAILURE
;
1256 if (cmp_gss_krb5_name(handle
, name
, arg
->princ
)) {
1257 ret
.code
= chpass_principal_wrapper_3((void *)handle
, arg
->princ
,
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
,
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 */
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
));
1286 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1291 gss_release_name(&min_stat
, &name
);
1292 free_server_handle(handle
);
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
;
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
)))
1320 if ((ret
.code
= check_handle((void *)handle
)))
1322 ret
.api_version
= handle
->api_version
;
1324 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
1325 ret
.code
= KADM5_FAILURE
;
1328 if (krb5_unparse_name(handle
->context
, arg
->princ
, &prime_arg
)) {
1329 ret
.code
= KADM5_BAD_PRINCIPAL
;
1332 if (!(name
= get_clnt_name(rqstp
))) {
1333 ret
.code
= KADM5_FAILURE
;
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
,
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 */
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
));
1358 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1363 gss_release_name(&min_stat
, &name
);
1364 free_server_handle(handle
);
1376 setkey_principal_2_svc(setkey_arg
*arg
, struct svc_req
*rqstp
)
1378 static generic_ret ret
;
1383 kadm5_server_handle_t handle
;
1384 const char *errmsg
= NULL
;
1387 xdr_free(xdr_generic_ret
, (char *) &ret
);
1389 if ((ret
.code
= new_server_handle(arg
->api_version
, rqstp
, &handle
)))
1392 if ((ret
.code
= check_handle((void *)handle
)))
1394 ret
.api_version
= handle
->api_version
;
1396 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
1397 ret
.code
= KADM5_FAILURE
;
1400 if (krb5_unparse_name(handle
->context
, arg
->princ
, &prime_arg
)) {
1401 ret
.code
= KADM5_BAD_PRINCIPAL
;
1404 if (!(name
= get_clnt_name(rqstp
))) {
1405 ret
.code
= KADM5_FAILURE
;
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
);
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 */
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
));
1429 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1434 gss_release_name(&min_stat
, &name
);
1435 free_server_handle(handle
);
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
;
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
)))
1462 if ((ret
.code
= check_handle((void *)handle
)))
1464 ret
.api_version
= handle
->api_version
;
1466 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
1467 ret
.code
= KADM5_FAILURE
;
1470 if (krb5_unparse_name(handle
->context
, arg
->princ
, &prime_arg
)) {
1471 ret
.code
= KADM5_BAD_PRINCIPAL
;
1474 if (!(name
= get_clnt_name(rqstp
))) {
1475 ret
.code
= KADM5_FAILURE
;
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
,
1486 arg
->keyblocks
, arg
->n_keys
);
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 */
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
));
1503 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1508 gss_release_name(&min_stat
, &name
);
1509 free_server_handle(handle
);
1520 chrand_principal_2_svc(chrand_arg
*arg
, struct svc_req
*rqstp
)
1522 static chrand_ret ret
;
1525 char *prime_arg
= NULL
, *funcname
;
1526 char *client_name
= NULL
, *service_name
= NULL
;
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
)))
1537 if ((ret
.code
= check_handle((void *)handle
)))
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
;
1549 if (krb5_unparse_name(handle
->context
, arg
->princ
, &prime_arg
)) {
1550 ret
.code
= KADM5_BAD_PRINCIPAL
;
1553 if (!(name
= get_clnt_name(rqstp
))) {
1554 ret
.code
= KADM5_FAILURE
;
1558 if (cmp_gss_krb5_name(handle
, name
, arg
->princ
)) {
1559 ret
.code
= randkey_principal_wrapper((void *)handle
, arg
->princ
, &k
,
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
,
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
);
1584 if(ret
.code
!= KADM5_AUTH_CHANGEPW
) {
1585 /* Solaris Kerberos */
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
));
1595 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1600 gss_release_name(&min_stat
, &name
);
1601 free_server_handle(handle
);
1612 chrand_principal3_2_svc(chrand3_arg
*arg
, struct svc_req
*rqstp
)
1614 static chrand_ret ret
;
1617 char *prime_arg
= NULL
, *funcname
;
1618 char *client_name
= NULL
,
1619 *service_name
= NULL
;
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
)))
1630 if ((ret
.code
= check_handle((void *)handle
)))
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
;
1641 if (krb5_unparse_name(handle
->context
, arg
->princ
, &prime_arg
)) {
1642 ret
.code
= KADM5_BAD_PRINCIPAL
;
1645 if (!(name
= get_clnt_name(rqstp
))) {
1646 ret
.code
= KADM5_FAILURE
;
1650 if (cmp_gss_krb5_name(handle
, name
, arg
->princ
)) {
1651 ret
.code
= randkey_principal_wrapper_3((void *)handle
, arg
->princ
,
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
,
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
);
1680 if(ret
.code
!= KADM5_AUTH_CHANGEPW
) {
1681 /* Solaris Kerberos */
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
));
1689 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1694 gss_release_name(&min_stat
, &name
);
1695 free_server_handle(handle
);
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
;
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
)))
1721 if ((ret
.code
= check_handle((void *)handle
)))
1724 ret
.api_version
= handle
->api_version
;
1726 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
1727 ret
.code
= KADM5_FAILURE
;
1730 prime_arg
= arg
->rec
.policy
;
1732 if (!(name
= get_clnt_name(rqstp
))) {
1733 ret
.code
= KADM5_FAILURE
;
1737 if (CHANGEPW_SERVICE(rqstp
) || !kadm5int_acl_check(handle
->context
,
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
));
1749 ret
.code
= kadm5_create_policy((void *)handle
, &arg
->rec
,
1751 /* Solaris Kerberos */
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
));
1764 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1769 gss_release_name(&min_stat
, &name
);
1770 free_server_handle(handle
);
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
;
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
)))
1794 if ((ret
.code
= check_handle((void *)handle
)))
1796 ret
.api_version
= handle
->api_version
;
1798 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
1799 ret
.code
= KADM5_FAILURE
;
1802 prime_arg
= arg
->name
;
1804 if (!(name
= get_clnt_name(rqstp
))) {
1805 ret
.code
= KADM5_FAILURE
;
1809 if (CHANGEPW_SERVICE(rqstp
) || !kadm5int_acl_check(handle
->context
,
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
;
1820 ret
.code
= kadm5_delete_policy((void *)handle
, arg
->name
);
1821 /* Solaris Kerberos */
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
));
1834 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1839 gss_release_name(&min_stat
, &name
);
1840 free_server_handle(handle
);
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
;
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
)))
1864 if ((ret
.code
= check_handle((void *)handle
)))
1866 ret
.api_version
= handle
->api_version
;
1868 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
1869 ret
.code
= KADM5_FAILURE
;
1872 prime_arg
= arg
->rec
.policy
;
1874 if (!(name
= get_clnt_name(rqstp
))) {
1875 ret
.code
= KADM5_FAILURE
;
1879 if (CHANGEPW_SERVICE(rqstp
) || !kadm5int_acl_check(handle
->context
,
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
;
1890 ret
.code
= kadm5_modify_policy((void *)handle
, &arg
->rec
,
1892 /* Solaris Kerberos */
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
));
1905 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
1910 gss_release_name(&min_stat
, &name
);
1911 free_server_handle(handle
);
1920 get_policy_2_svc(gpol_arg
*arg
, struct svc_req
*rqstp
)
1922 static gpol_ret ret
;
1924 char *prime_arg
= NULL
, *funcname
;
1925 char *client_name
= NULL
, *service_name
= NULL
;
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
)))
1939 if ((ret
.code
= check_handle((void *) handle
)))
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
;
1951 prime_arg
= arg
->name
;
1952 ret
.code
= KADM5_AUTH_GET
;
1954 if (!(name
= get_clnt_name(rqstp
))) {
1955 ret
.code
= KADM5_FAILURE
;
1959 if (!CHANGEPW_SERVICE(rqstp
) && kadm5int_acl_check(handle
->context
,
1961 ACL_INQUIRE
, NULL
, NULL
))
1962 ret
.code
= KADM5_OK
;
1964 ret
.code
= kadm5_get_principal(handle
->lhandle
,
1965 handle
->current_caller
,
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
,
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
));
1987 ret
.code
= kadm5_get_policy((void *)handle
, arg
->name
,
1991 /* Solaris Kerberos */
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
);
1998 ((prime_arg
== NULL
) ? "(null)" : prime_arg
),
1999 errmsg
? errmsg
: "success",
2000 client_name
, service_name
, client_addr(rqstp
, buf
));
2003 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
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
));
2014 gss_release_name(&min_stat
, &name
);
2015 free_server_handle(handle
);
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
;
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
)))
2040 if ((ret
.code
= check_handle((void *)handle
)))
2043 ret
.api_version
= handle
->api_version
;
2045 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
2046 ret
.code
= KADM5_FAILURE
;
2049 prime_arg
= arg
->exp
;
2050 if (prime_arg
== NULL
)
2053 if (!(name
= get_clnt_name(rqstp
))) {
2054 ret
.code
= KADM5_FAILURE
;
2058 if (CHANGEPW_SERVICE(rqstp
) || !kadm5int_acl_check(handle
->context
,
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
));
2069 ret
.code
= kadm5_get_policies((void *)handle
,
2070 arg
->exp
, &ret
.pols
,
2072 /* Solaris Kerberos */
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
));
2084 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
2089 gss_release_name(&min_stat
, &name
);
2090 free_server_handle(handle
);
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
;
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
)))
2112 if ((ret
.code
= check_handle((void *)handle
)))
2115 ret
.api_version
= handle
->api_version
;
2117 if (setup_gss_names(rqstp
, &client_name
, &service_name
) < 0) {
2118 ret
.code
= KADM5_FAILURE
;
2121 if (!(name
= get_clnt_name(rqstp
))) {
2122 ret
.code
= KADM5_FAILURE
;
2126 ret
.code
= __kadm5_get_priv((void *) handle
, &ret
.privs
, name
);
2127 /* Solaris Kerberos */
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
,
2134 log_done("kadm5_get_privs", client_name
,
2135 errmsg
? errmsg
: "success",
2136 client_name
, service_name
, client_addr(rqstp
, buf
));
2139 krb5_free_error_message(handle
? handle
->context
: NULL
, errmsg
);
2143 gss_release_name(&min_stat
, &name
);
2144 free_server_handle(handle
);
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
;
2159 char *cdots
, *sdots
;
2161 xdr_free(xdr_generic_ret
, (char *) &ret
);
2163 if ((ret
.code
= new_server_handle(*arg
, rqstp
, &handle
)))
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
;
2176 /* Solaris Kerberos */
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
);
2200 krb5_free_error_message(NULL
, errmsg
);