17c478bdstevel@tonic-gate/*
2159d09aMark Phalan * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
37c478bdstevel@tonic-gate * Use is subject to license terms.
47c478bdstevel@tonic-gate */
57c478bdstevel@tonic-gate
67c478bdstevel@tonic-gate
77c478bdstevel@tonic-gate/*
87c478bdstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
97c478bdstevel@tonic-gate *
107c478bdstevel@tonic-gate *	Openvision retains the copyright to derivative works of
117c478bdstevel@tonic-gate *	this source code.  Do *NOT* create a derivative of this
127c478bdstevel@tonic-gate *	source code before consulting with your legal department.
137c478bdstevel@tonic-gate *	Do *NOT* integrate *ANY* of this source code into another
147c478bdstevel@tonic-gate *	product before consulting with your legal department.
157c478bdstevel@tonic-gate *
167c478bdstevel@tonic-gate *	For further information, read the top-level Openvision
177c478bdstevel@tonic-gate *	copyright which is contained in the top-level MIT Kerberos
187c478bdstevel@tonic-gate *	copyright.
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
217c478bdstevel@tonic-gate *
227c478bdstevel@tonic-gate */
237c478bdstevel@tonic-gate
247c478bdstevel@tonic-gate
257c478bdstevel@tonic-gate/*
267c478bdstevel@tonic-gate * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
277c478bdstevel@tonic-gate *
28159d09aMark Phalan * $Header$
297c478bdstevel@tonic-gate */
307c478bdstevel@tonic-gate
317c478bdstevel@tonic-gate#if !defined(lint) && !defined(__CODECENTER__)
32159d09aMark Phalanstatic char *rcsid = "$Header$";
337c478bdstevel@tonic-gate#endif
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate#include    <rpc/rpc.h> /* SUNWresync121 XXX */
367c478bdstevel@tonic-gate#include    <kadm5/admin.h>
377c478bdstevel@tonic-gate#include    <kadm5/kadm_rpc.h>
387c478bdstevel@tonic-gate#include    "client_internal.h"
397c478bdstevel@tonic-gate#include	<stdlib.h>
407c478bdstevel@tonic-gate#include	<string.h>
41159d09aMark Phalan#include	<errno.h>
427c478bdstevel@tonic-gate
437c478bdstevel@tonic-gatekadm5_ret_t
447c478bdstevel@tonic-gatekadm5_create_policy(void *server_handle,
457c478bdstevel@tonic-gate			 kadm5_policy_ent_t policy, long mask)
467c478bdstevel@tonic-gate{
477c478bdstevel@tonic-gate    cpol_arg		arg;
487c478bdstevel@tonic-gate    generic_ret		*r;
497c478bdstevel@tonic-gate    kadm5_server_handle_t handle = server_handle;
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gate    CHECK_HANDLE(server_handle);
527c478bdstevel@tonic-gate
537c478bdstevel@tonic-gate    if(policy == (kadm5_policy_ent_t) NULL)
547c478bdstevel@tonic-gate	return EINVAL;
557c478bdstevel@tonic-gate
567c478bdstevel@tonic-gate    arg.mask = mask;
577c478bdstevel@tonic-gate    arg.api_version = handle->api_version;
587c478bdstevel@tonic-gate    memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
59159d09aMark Phalan    r = create_policy_2(&arg, handle->clnt);
607c478bdstevel@tonic-gate    if(r == NULL)
617c478bdstevel@tonic-gate	return KADM5_RPC_ERROR;
62159d09aMark Phalan
637c478bdstevel@tonic-gate    return r->code;
647c478bdstevel@tonic-gate}
657c478bdstevel@tonic-gate
667c478bdstevel@tonic-gatekadm5_ret_t
677c478bdstevel@tonic-gatekadm5_delete_policy(void *server_handle, char *name)
687c478bdstevel@tonic-gate{
697c478bdstevel@tonic-gate    dpol_arg		arg;
707c478bdstevel@tonic-gate    generic_ret		*r;
717c478bdstevel@tonic-gate    kadm5_server_handle_t handle = server_handle;
727c478bdstevel@tonic-gate
737c478bdstevel@tonic-gate    CHECK_HANDLE(server_handle);
747c478bdstevel@tonic-gate
757c478bdstevel@tonic-gate    if(name == NULL)
767c478bdstevel@tonic-gate	return EINVAL;
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate    arg.name = name;
797c478bdstevel@tonic-gate    arg.api_version = handle->api_version;
807c478bdstevel@tonic-gate
81159d09aMark Phalan    r = delete_policy_2(&arg, handle->clnt);
827c478bdstevel@tonic-gate    if(r == NULL)
837c478bdstevel@tonic-gate	return KADM5_RPC_ERROR;
84159d09aMark Phalan
857c478bdstevel@tonic-gate    return r->code;
867c478bdstevel@tonic-gate}
877c478bdstevel@tonic-gate
887c478bdstevel@tonic-gatekadm5_ret_t
897c478bdstevel@tonic-gatekadm5_modify_policy(void *server_handle,
907c478bdstevel@tonic-gate			 kadm5_policy_ent_t policy, long mask)
917c478bdstevel@tonic-gate{
927c478bdstevel@tonic-gate    mpol_arg		arg;
937c478bdstevel@tonic-gate    generic_ret		*r;
947c478bdstevel@tonic-gate    kadm5_server_handle_t handle = server_handle;
957c478bdstevel@tonic-gate
967c478bdstevel@tonic-gate    CHECK_HANDLE(server_handle);
977c478bdstevel@tonic-gate
987c478bdstevel@tonic-gate    if(policy == (kadm5_policy_ent_t) NULL)
997c478bdstevel@tonic-gate	return EINVAL;
1007c478bdstevel@tonic-gate
1017c478bdstevel@tonic-gate    arg.mask = mask;
1027c478bdstevel@tonic-gate    arg.api_version = handle->api_version;
1037c478bdstevel@tonic-gate
1047c478bdstevel@tonic-gate    memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
105159d09aMark Phalan    r = modify_policy_2(&arg, handle->clnt);
1067c478bdstevel@tonic-gate    if(r == NULL)
1077c478bdstevel@tonic-gate	return KADM5_RPC_ERROR;
108159d09aMark Phalan
1097c478bdstevel@tonic-gate    return r->code;
1107c478bdstevel@tonic-gate}
1117c478bdstevel@tonic-gate
1127c478bdstevel@tonic-gatekadm5_ret_t
1137c478bdstevel@tonic-gatekadm5_get_policy(void *server_handle, char *name, kadm5_policy_ent_t ent)
1147c478bdstevel@tonic-gate{
1157c478bdstevel@tonic-gate    gpol_arg	    arg;
1167c478bdstevel@tonic-gate    gpol_ret	    *r;
1177c478bdstevel@tonic-gate    kadm5_server_handle_t handle = server_handle;
1187c478bdstevel@tonic-gate
1197c478bdstevel@tonic-gate    CHECK_HANDLE(server_handle);
1207c478bdstevel@tonic-gate
1217c478bdstevel@tonic-gate    arg.name = name;
1227c478bdstevel@tonic-gate    arg.api_version = handle->api_version;
1237c478bdstevel@tonic-gate
1247c478bdstevel@tonic-gate    if(name == NULL)
1257c478bdstevel@tonic-gate	return EINVAL;
1267c478bdstevel@tonic-gate
127159d09aMark Phalan    r = get_policy_2(&arg, handle->clnt);
1287c478bdstevel@tonic-gate    if(r == NULL)
1297c478bdstevel@tonic-gate	return KADM5_RPC_ERROR;
1307c478bdstevel@tonic-gate    if (handle->api_version == KADM5_API_VERSION_1) {
1317c478bdstevel@tonic-gate	 kadm5_policy_ent_t *entp;
1327c478bdstevel@tonic-gate
1337c478bdstevel@tonic-gate	 entp = (kadm5_policy_ent_t *) ent;
1347c478bdstevel@tonic-gate	 if(r->code == 0) {
1357c478bdstevel@tonic-gate	      if (!(*entp = (kadm5_policy_ent_t)
1367c478bdstevel@tonic-gate		    malloc(sizeof(kadm5_policy_ent_rec))))
1377c478bdstevel@tonic-gate		   return ENOMEM;
1387c478bdstevel@tonic-gate	      memcpy(*entp, &r->rec, sizeof(**entp));
1397c478bdstevel@tonic-gate	 } else {
1407c478bdstevel@tonic-gate	      *entp = NULL;
1417c478bdstevel@tonic-gate	 }
1427c478bdstevel@tonic-gate    } else {
1437c478bdstevel@tonic-gate	 if (r->code == 0)
1447c478bdstevel@tonic-gate	      memcpy(ent, &r->rec, sizeof(r->rec));
1457c478bdstevel@tonic-gate    }
1467c478bdstevel@tonic-gate
1477c478bdstevel@tonic-gate    return r->code;
1487c478bdstevel@tonic-gate}
1497c478bdstevel@tonic-gate
1507c478bdstevel@tonic-gatekadm5_ret_t
1517c478bdstevel@tonic-gatekadm5_get_policies(void *server_handle,
1527c478bdstevel@tonic-gate			  char *exp, char ***pols, int *count)
1537c478bdstevel@tonic-gate{
1547c478bdstevel@tonic-gate    gpols_arg	arg;
1557c478bdstevel@tonic-gate    gpols_ret	*r;
1567c478bdstevel@tonic-gate    kadm5_server_handle_t handle = server_handle;
1577c478bdstevel@tonic-gate
1587c478bdstevel@tonic-gate    CHECK_HANDLE(server_handle);
1597c478bdstevel@tonic-gate
1607c478bdstevel@tonic-gate    if(pols == NULL || count == NULL)
1617c478bdstevel@tonic-gate	return EINVAL;
1627c478bdstevel@tonic-gate    arg.exp = exp;
1637c478bdstevel@tonic-gate    arg.api_version = handle->api_version;
164159d09aMark Phalan    r = get_pols_2(&arg, handle->clnt);
1657c478bdstevel@tonic-gate    if(r == NULL)
1667c478bdstevel@tonic-gate	return KADM5_RPC_ERROR;
1677c478bdstevel@tonic-gate    if(r->code == 0) {
1687c478bdstevel@tonic-gate	 *count = r->count;
1697c478bdstevel@tonic-gate	 *pols = r->pols;
1707c478bdstevel@tonic-gate    } else {
1717c478bdstevel@tonic-gate	 *count = 0;
1727c478bdstevel@tonic-gate	 *pols = NULL;
1737c478bdstevel@tonic-gate    }
1747c478bdstevel@tonic-gate
1757c478bdstevel@tonic-gate    return r->code;
1767c478bdstevel@tonic-gate}
177