summaryrefslogtreecommitdiff
path: root/usr/src/lib/krb5/kadm5/clnt/clnt_policy.c
blob: 2c97b167236218960dd045f30970cb6682cffec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */


/*
 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 
 *
 *	Openvision retains the copyright to derivative works of
 *	this source code.  Do *NOT* create a derivative of this
 *	source code before consulting with your legal department.
 *	Do *NOT* integrate *ANY* of this source code into another
 *	product before consulting with your legal department.
 *
 *	For further information, read the top-level Openvision
 *	copyright which is contained in the top-level MIT Kerberos
 *	copyright.
 *
 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
 *
 */


/*
 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
 *
 * $Header$
 */

#if !defined(lint) && !defined(__CODECENTER__)
static char *rcsid = "$Header$";
#endif

#include    <rpc/rpc.h> /* SUNWresync121 XXX */
#include    <kadm5/admin.h>
#include    <kadm5/kadm_rpc.h>
#include    "client_internal.h"
#include	<stdlib.h>
#include	<string.h>
#include	<errno.h>

kadm5_ret_t
kadm5_create_policy(void *server_handle,
			 kadm5_policy_ent_t policy, long mask)
{
    cpol_arg		arg;
    generic_ret		*r;
    kadm5_server_handle_t handle = server_handle;

    CHECK_HANDLE(server_handle);

    if(policy == (kadm5_policy_ent_t) NULL)
	return EINVAL;

    arg.mask = mask;
    arg.api_version = handle->api_version;
    memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
    r = create_policy_2(&arg, handle->clnt);
    if(r == NULL)
	return KADM5_RPC_ERROR;    

    return r->code;
}

kadm5_ret_t
kadm5_delete_policy(void *server_handle, char *name)
{
    dpol_arg		arg;
    generic_ret		*r;
    kadm5_server_handle_t handle = server_handle;
	 
    CHECK_HANDLE(server_handle);

    if(name == NULL)
	return EINVAL;

    arg.name = name;
    arg.api_version = handle->api_version;

    r = delete_policy_2(&arg, handle->clnt);
    if(r == NULL)
	return KADM5_RPC_ERROR;    

    return r->code;
}

kadm5_ret_t
kadm5_modify_policy(void *server_handle,
			 kadm5_policy_ent_t policy, long mask)
{
    mpol_arg		arg;
    generic_ret		*r;
    kadm5_server_handle_t handle = server_handle;

    CHECK_HANDLE(server_handle);

    if(policy == (kadm5_policy_ent_t) NULL)
	return EINVAL;
	
    arg.mask = mask;
    arg.api_version = handle->api_version;

    memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
    r = modify_policy_2(&arg, handle->clnt);
    if(r == NULL)
	return KADM5_RPC_ERROR;    

    return r->code;
}

kadm5_ret_t
kadm5_get_policy(void *server_handle, char *name, kadm5_policy_ent_t ent)
{
    gpol_arg	    arg;
    gpol_ret	    *r;
    kadm5_server_handle_t handle = server_handle;

    CHECK_HANDLE(server_handle);

    arg.name = name;
    arg.api_version = handle->api_version;

    if(name == NULL)
	return EINVAL;
	
    r = get_policy_2(&arg, handle->clnt);
    if(r == NULL)
	return KADM5_RPC_ERROR;
    if (handle->api_version == KADM5_API_VERSION_1) {
	 kadm5_policy_ent_t *entp;

	 entp = (kadm5_policy_ent_t *) ent;
	 if(r->code == 0) {
	      if (!(*entp = (kadm5_policy_ent_t)
		    malloc(sizeof(kadm5_policy_ent_rec))))
		   return ENOMEM;
	      memcpy(*entp, &r->rec, sizeof(**entp));
	 } else {
	      *entp = NULL;
	 }
    } else {
	 if (r->code == 0)
	      memcpy(ent, &r->rec, sizeof(r->rec));
    }
	 
    return r->code;
}

kadm5_ret_t
kadm5_get_policies(void *server_handle,
			  char *exp, char ***pols, int *count)
{
    gpols_arg	arg;
    gpols_ret	*r;
    kadm5_server_handle_t handle = server_handle;

    CHECK_HANDLE(server_handle);

    if(pols == NULL || count == NULL)
	return EINVAL;
    arg.exp = exp;
    arg.api_version = handle->api_version;
    r = get_pols_2(&arg, handle->clnt);
    if(r == NULL)
	return KADM5_RPC_ERROR;
    if(r->code == 0) {
	 *count = r->count;
	 *pols = r->pols;
    } else {
	 *count = 0;
	 *pols = NULL;
    }
    
    return r->code;
}