aboutsummaryrefslogtreecommitdiff
path: root/src/lib/kadm5/clnt/clnt_policy.c
blob: fc91245e8ec652893e2a3cc503a94607d6710b4f (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
/*
 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
 *
 * $Header$
 */

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

#include    <gssrpc/rpc.h>
#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 (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;
}