10Sstevel@tonic-gate /*
2*7934SMark.Phalan@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
50Sstevel@tonic-gate
60Sstevel@tonic-gate
70Sstevel@tonic-gate /*
80Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
90Sstevel@tonic-gate *
100Sstevel@tonic-gate * Openvision retains the copyright to derivative works of
110Sstevel@tonic-gate * this source code. Do *NOT* create a derivative of this
120Sstevel@tonic-gate * source code before consulting with your legal department.
130Sstevel@tonic-gate * Do *NOT* integrate *ANY* of this source code into another
140Sstevel@tonic-gate * product before consulting with your legal department.
150Sstevel@tonic-gate *
160Sstevel@tonic-gate * For further information, read the top-level Openvision
170Sstevel@tonic-gate * copyright which is contained in the top-level MIT Kerberos
180Sstevel@tonic-gate * copyright.
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
210Sstevel@tonic-gate *
220Sstevel@tonic-gate */
230Sstevel@tonic-gate
240Sstevel@tonic-gate
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
270Sstevel@tonic-gate *
28*7934SMark.Phalan@Sun.COM * $Header$
290Sstevel@tonic-gate */
300Sstevel@tonic-gate
310Sstevel@tonic-gate #if !defined(lint) && !defined(__CODECENTER__)
32*7934SMark.Phalan@Sun.COM static char *rcsid = "$Header$";
330Sstevel@tonic-gate #endif
340Sstevel@tonic-gate
350Sstevel@tonic-gate #include <rpc/rpc.h> /* SUNWresync121 XXX */
360Sstevel@tonic-gate #include <kadm5/admin.h>
370Sstevel@tonic-gate #include <kadm5/kadm_rpc.h>
380Sstevel@tonic-gate #include "client_internal.h"
390Sstevel@tonic-gate #include <stdlib.h>
400Sstevel@tonic-gate #include <string.h>
41*7934SMark.Phalan@Sun.COM #include <errno.h>
420Sstevel@tonic-gate
430Sstevel@tonic-gate kadm5_ret_t
kadm5_create_policy(void * server_handle,kadm5_policy_ent_t policy,long mask)440Sstevel@tonic-gate kadm5_create_policy(void *server_handle,
450Sstevel@tonic-gate kadm5_policy_ent_t policy, long mask)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate cpol_arg arg;
480Sstevel@tonic-gate generic_ret *r;
490Sstevel@tonic-gate kadm5_server_handle_t handle = server_handle;
500Sstevel@tonic-gate
510Sstevel@tonic-gate CHECK_HANDLE(server_handle);
520Sstevel@tonic-gate
530Sstevel@tonic-gate if(policy == (kadm5_policy_ent_t) NULL)
540Sstevel@tonic-gate return EINVAL;
550Sstevel@tonic-gate
560Sstevel@tonic-gate arg.mask = mask;
570Sstevel@tonic-gate arg.api_version = handle->api_version;
580Sstevel@tonic-gate memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
59*7934SMark.Phalan@Sun.COM r = create_policy_2(&arg, handle->clnt);
600Sstevel@tonic-gate if(r == NULL)
610Sstevel@tonic-gate return KADM5_RPC_ERROR;
62*7934SMark.Phalan@Sun.COM
630Sstevel@tonic-gate return r->code;
640Sstevel@tonic-gate }
650Sstevel@tonic-gate
660Sstevel@tonic-gate kadm5_ret_t
kadm5_delete_policy(void * server_handle,char * name)670Sstevel@tonic-gate kadm5_delete_policy(void *server_handle, char *name)
680Sstevel@tonic-gate {
690Sstevel@tonic-gate dpol_arg arg;
700Sstevel@tonic-gate generic_ret *r;
710Sstevel@tonic-gate kadm5_server_handle_t handle = server_handle;
720Sstevel@tonic-gate
730Sstevel@tonic-gate CHECK_HANDLE(server_handle);
740Sstevel@tonic-gate
750Sstevel@tonic-gate if(name == NULL)
760Sstevel@tonic-gate return EINVAL;
770Sstevel@tonic-gate
780Sstevel@tonic-gate arg.name = name;
790Sstevel@tonic-gate arg.api_version = handle->api_version;
800Sstevel@tonic-gate
81*7934SMark.Phalan@Sun.COM r = delete_policy_2(&arg, handle->clnt);
820Sstevel@tonic-gate if(r == NULL)
830Sstevel@tonic-gate return KADM5_RPC_ERROR;
84*7934SMark.Phalan@Sun.COM
850Sstevel@tonic-gate return r->code;
860Sstevel@tonic-gate }
870Sstevel@tonic-gate
880Sstevel@tonic-gate kadm5_ret_t
kadm5_modify_policy(void * server_handle,kadm5_policy_ent_t policy,long mask)890Sstevel@tonic-gate kadm5_modify_policy(void *server_handle,
900Sstevel@tonic-gate kadm5_policy_ent_t policy, long mask)
910Sstevel@tonic-gate {
920Sstevel@tonic-gate mpol_arg arg;
930Sstevel@tonic-gate generic_ret *r;
940Sstevel@tonic-gate kadm5_server_handle_t handle = server_handle;
950Sstevel@tonic-gate
960Sstevel@tonic-gate CHECK_HANDLE(server_handle);
970Sstevel@tonic-gate
980Sstevel@tonic-gate if(policy == (kadm5_policy_ent_t) NULL)
990Sstevel@tonic-gate return EINVAL;
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate arg.mask = mask;
1020Sstevel@tonic-gate arg.api_version = handle->api_version;
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
105*7934SMark.Phalan@Sun.COM r = modify_policy_2(&arg, handle->clnt);
1060Sstevel@tonic-gate if(r == NULL)
1070Sstevel@tonic-gate return KADM5_RPC_ERROR;
108*7934SMark.Phalan@Sun.COM
1090Sstevel@tonic-gate return r->code;
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate kadm5_ret_t
kadm5_get_policy(void * server_handle,char * name,kadm5_policy_ent_t ent)1130Sstevel@tonic-gate kadm5_get_policy(void *server_handle, char *name, kadm5_policy_ent_t ent)
1140Sstevel@tonic-gate {
1150Sstevel@tonic-gate gpol_arg arg;
1160Sstevel@tonic-gate gpol_ret *r;
1170Sstevel@tonic-gate kadm5_server_handle_t handle = server_handle;
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate CHECK_HANDLE(server_handle);
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate arg.name = name;
1220Sstevel@tonic-gate arg.api_version = handle->api_version;
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate if(name == NULL)
1250Sstevel@tonic-gate return EINVAL;
1260Sstevel@tonic-gate
127*7934SMark.Phalan@Sun.COM r = get_policy_2(&arg, handle->clnt);
1280Sstevel@tonic-gate if(r == NULL)
1290Sstevel@tonic-gate return KADM5_RPC_ERROR;
1300Sstevel@tonic-gate if (handle->api_version == KADM5_API_VERSION_1) {
1310Sstevel@tonic-gate kadm5_policy_ent_t *entp;
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate entp = (kadm5_policy_ent_t *) ent;
1340Sstevel@tonic-gate if(r->code == 0) {
1350Sstevel@tonic-gate if (!(*entp = (kadm5_policy_ent_t)
1360Sstevel@tonic-gate malloc(sizeof(kadm5_policy_ent_rec))))
1370Sstevel@tonic-gate return ENOMEM;
1380Sstevel@tonic-gate memcpy(*entp, &r->rec, sizeof(**entp));
1390Sstevel@tonic-gate } else {
1400Sstevel@tonic-gate *entp = NULL;
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate } else {
1430Sstevel@tonic-gate if (r->code == 0)
1440Sstevel@tonic-gate memcpy(ent, &r->rec, sizeof(r->rec));
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate return r->code;
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate kadm5_ret_t
kadm5_get_policies(void * server_handle,char * exp,char *** pols,int * count)1510Sstevel@tonic-gate kadm5_get_policies(void *server_handle,
1520Sstevel@tonic-gate char *exp, char ***pols, int *count)
1530Sstevel@tonic-gate {
1540Sstevel@tonic-gate gpols_arg arg;
1550Sstevel@tonic-gate gpols_ret *r;
1560Sstevel@tonic-gate kadm5_server_handle_t handle = server_handle;
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate CHECK_HANDLE(server_handle);
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate if(pols == NULL || count == NULL)
1610Sstevel@tonic-gate return EINVAL;
1620Sstevel@tonic-gate arg.exp = exp;
1630Sstevel@tonic-gate arg.api_version = handle->api_version;
164*7934SMark.Phalan@Sun.COM r = get_pols_2(&arg, handle->clnt);
1650Sstevel@tonic-gate if(r == NULL)
1660Sstevel@tonic-gate return KADM5_RPC_ERROR;
1670Sstevel@tonic-gate if(r->code == 0) {
1680Sstevel@tonic-gate *count = r->count;
1690Sstevel@tonic-gate *pols = r->pols;
1700Sstevel@tonic-gate } else {
1710Sstevel@tonic-gate *count = 0;
1720Sstevel@tonic-gate *pols = NULL;
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate
1750Sstevel@tonic-gate return r->code;
1760Sstevel@tonic-gate }
177