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