xref: /titanic_50/usr/src/lib/krb5/kadm5/clnt/clnt_policy.c (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 /*
2  * Copyright 2006 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.4 2004/02/19 01:22:26 raeburn 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     mpol_arg		arg;
91     generic_ret		*r;
92     kadm5_server_handle_t handle = server_handle;
93 
94     CHECK_HANDLE(server_handle);
95 
96     if(policy == (kadm5_policy_ent_t) NULL)
97 	return EINVAL;
98 
99     arg.mask = mask;
100     arg.api_version = handle->api_version;
101 
102     memcpy(&arg.rec, policy, sizeof(kadm5_policy_ent_rec));
103     r = modify_policy_1(&arg, handle->clnt);
104     if(r == NULL)
105 	return KADM5_RPC_ERROR;
106     return r->code;
107 }
108 
109 kadm5_ret_t
110 kadm5_get_policy(void *server_handle, char *name, kadm5_policy_ent_t ent)
111 {
112     gpol_arg	    arg;
113     gpol_ret	    *r;
114     kadm5_server_handle_t handle = server_handle;
115 
116     CHECK_HANDLE(server_handle);
117 
118     arg.name = name;
119     arg.api_version = handle->api_version;
120 
121     if(name == NULL)
122 	return EINVAL;
123 
124     r = get_policy_1(&arg, handle->clnt);
125     if(r == NULL)
126 	return KADM5_RPC_ERROR;
127     if (handle->api_version == KADM5_API_VERSION_1) {
128 	 kadm5_policy_ent_t *entp;
129 
130 	 entp = (kadm5_policy_ent_t *) ent;
131 	 if(r->code == 0) {
132 	      if (!(*entp = (kadm5_policy_ent_t)
133 		    malloc(sizeof(kadm5_policy_ent_rec))))
134 		   return ENOMEM;
135 	      memcpy(*entp, &r->rec, sizeof(**entp));
136 	 } else {
137 	      *entp = NULL;
138 	 }
139     } else {
140 	 if (r->code == 0)
141 	      memcpy(ent, &r->rec, sizeof(r->rec));
142     }
143 
144     return r->code;
145 }
146 
147 kadm5_ret_t
148 kadm5_get_policies(void *server_handle,
149 			  char *exp, char ***pols, int *count)
150 {
151     gpols_arg	arg;
152     gpols_ret	*r;
153     kadm5_server_handle_t handle = server_handle;
154 
155     CHECK_HANDLE(server_handle);
156 
157     if(pols == NULL || count == NULL)
158 	return EINVAL;
159     arg.exp = exp;
160     arg.api_version = handle->api_version;
161     r = get_pols_1(&arg, handle->clnt);
162     if(r == NULL)
163 	return KADM5_RPC_ERROR;
164     if(r->code == 0) {
165 	 *count = r->count;
166 	 *pols = r->pols;
167     } else {
168 	 *count = 0;
169 	 *pols = NULL;
170     }
171 
172     return r->code;
173 }
174