xref: /titanic_52/usr/src/lib/krb5/kadm5/clnt/clnt_policy.c (revision d58fda4376e4bf67072ce2e69f6f47036f9dbb68)
1 /*
2  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
10  *
11  *	Openvision retains the copyright to derivative works of
12  *	this source code.  Do *NOT* create a derivative of this
13  *	source code before consulting with your legal department.
14  *	Do *NOT* integrate *ANY* of this source code into another
15  *	product before consulting with your legal department.
16  *
17  *	For further information, read the top-level Openvision
18  *	copyright which is contained in the top-level MIT Kerberos
19  *	copyright.
20  *
21  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
22  *
23  */
24 
25 
26 /*
27  * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
28  *
29  * $Header: /cvs/krbdev/krb5/src/lib/kadm5/clnt/clnt_policy.c,v 1.2 1998/02/14 02:32:57 tlyu Exp $
30  */
31 
32 #if !defined(lint) && !defined(__CODECENTER__)
33 static char *rcsid = "$Header: /cvs/krbdev/krb5/src/lib/kadm5/clnt/clnt_policy.c,v 1.2 1998/02/14 02:32:57 tlyu Exp $";
34 #endif
35 
36 #include    <rpc/rpc.h> /* SUNWresync121 XXX */
37 #include    <kadm5/admin.h>
38 #include    <kadm5/kadm_rpc.h>
39 #include    "client_internal.h"
40 #include	<stdlib.h>
41 #include	<string.h>
42 
43 kadm5_ret_t
44 kadm5_create_policy(void *server_handle,
45 			 kadm5_policy_ent_t policy, long mask)
46 {
47     cpol_arg		arg;
48     generic_ret		*r;
49     kadm5_server_handle_t handle = server_handle;
50 
51     CHECK_HANDLE(server_handle);
52 
53     if(policy == (kadm5_policy_ent_t) NULL)
54 	return EINVAL;
55 
56     arg.mask = mask;
57     arg.api_version = handle->api_version;
58     memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
59     r = create_policy_1(&arg, handle->clnt);
60     if(r == NULL)
61 	return KADM5_RPC_ERROR;
62     return r->code;
63 }
64 
65 kadm5_ret_t
66 kadm5_delete_policy(void *server_handle, char *name)
67 {
68     dpol_arg		arg;
69     generic_ret		*r;
70     kadm5_server_handle_t handle = server_handle;
71 
72     CHECK_HANDLE(server_handle);
73 
74     if(name == NULL)
75 	return EINVAL;
76 
77     arg.name = name;
78     arg.api_version = handle->api_version;
79 
80     r = delete_policy_1(&arg, handle->clnt);
81     if(r == NULL)
82 	return KADM5_RPC_ERROR;
83     return r->code;
84 }
85 
86 kadm5_ret_t
87 kadm5_modify_policy(void *server_handle,
88 			 kadm5_policy_ent_t policy, long mask)
89 
90 {
91     mpol_arg		arg;
92     generic_ret		*r;
93     kadm5_server_handle_t handle = server_handle;
94 
95     CHECK_HANDLE(server_handle);
96 
97     if(policy == (kadm5_policy_ent_t) NULL)
98 	return EINVAL;
99 
100     arg.mask = mask;
101     arg.api_version = handle->api_version;
102 
103     memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
104     r = modify_policy_1(&arg, handle->clnt);
105     if(r == NULL)
106 	return KADM5_RPC_ERROR;
107     return r->code;
108 }
109 
110 kadm5_ret_t
111 kadm5_get_policy(void *server_handle, char *name, kadm5_policy_ent_t ent)
112 
113 {
114     gpol_arg	    arg;
115     gpol_ret	    *r;
116     kadm5_server_handle_t handle = server_handle;
117 
118     CHECK_HANDLE(server_handle);
119 
120     arg.name = name;
121     arg.api_version = handle->api_version;
122 
123     if(name == NULL)
124 	return EINVAL;
125 
126     r = get_policy_1(&arg, handle->clnt);
127     if(r == NULL)
128 	return KADM5_RPC_ERROR;
129     if (handle->api_version == KADM5_API_VERSION_1) {
130 	 kadm5_policy_ent_t *entp;
131 
132 	 entp = (kadm5_policy_ent_t *) ent;
133 	 if(r->code == 0) {
134 	      if (!(*entp = (kadm5_policy_ent_t)
135 		    malloc(sizeof(kadm5_policy_ent_rec))))
136 		   return ENOMEM;
137 	      memcpy(*entp, &r->rec, sizeof(**entp));
138 	 } else {
139 	      *entp = NULL;
140 	 }
141     } else {
142 	 if (r->code == 0)
143 	      memcpy(ent, &r->rec, sizeof(r->rec));
144     }
145 
146     return r->code;
147 }
148 
149 kadm5_ret_t
150 kadm5_get_policies(void *server_handle,
151 			  char *exp, char ***pols, int *count)
152 {
153     gpols_arg	arg;
154     gpols_ret	*r;
155     kadm5_server_handle_t handle = server_handle;
156 
157     CHECK_HANDLE(server_handle);
158 
159     if(pols == NULL || count == NULL)
160 	return EINVAL;
161     arg.exp = exp;
162     arg.api_version = handle->api_version;
163     r = get_pols_1(&arg, handle->clnt);
164     if(r == NULL)
165 	return KADM5_RPC_ERROR;
166     if(r->code == 0) {
167 	 *count = r->count;
168 	 *pols = r->pols;
169     } else {
170 	 *count = 0;
171 	 *pols = NULL;
172     }
173 
174     return r->code;
175 }
176