2
* $Id: pam_client.h,v 1.4 2002/09/15 21:30:26 hartmans Exp $
4
* Copyright (c) 1999 Andrew G. Morgan <morgan@linux.kernel.org>
6
* This header file provides the prototypes for the PAM client API
14
#endif /* def __cplusplus */
24
/* opaque agent handling structure */
26
typedef struct pamc_handle_s *pamc_handle_t;
28
/* binary prompt structure pointer */
30
# define __u32 unsigned int
33
# define __u8 unsigned char
35
typedef struct { __u32 length; __u8 control; } *pamc_bp_t;
38
* functions provided by libpamc
42
* Initialize the agent abstraction library
45
pamc_handle_t pamc_start(void);
48
* Terminate the authentication process
51
int pamc_end(pamc_handle_t *pch);
54
* force the loading of a specified agent
57
int pamc_load(pamc_handle_t pch, const char *agent_id);
60
* Single conversation interface for binary prompts
63
int pamc_converse(pamc_handle_t pch, pamc_bp_t *prompt_p);
69
int pamc_disable(pamc_handle_t pch, const char *agent_id);
72
* obtain a list of available agents
75
char **pamc_list_agents(pamc_handle_t pch);
78
* PAM_BP_ MACROS for creating, destroying and manipulating binary prompts
86
# define PAM_BP_ASSERT(x) do { printf(__FILE__ "(%d): %s\n", \
87
__LINE__, x) ; exit(1); } while (0)
88
#endif /* PAM_BP_ASSERT */
91
# define PAM_BP_CALLOC calloc
92
#endif /* PAM_BP_CALLOC */
95
# define PAM_BP_FREE free
96
#endif /* PAM_BP_FREE */
98
#define __PAM_BP_WOCTET(x,y) (*((y) + (__u8 *)(x)))
99
#define __PAM_BP_ROCTET(x,y) (*((y) + (const __u8 *)(x)))
101
#define PAM_BP_MIN_SIZE (sizeof(__u32) + sizeof(__u8))
102
#define PAM_BP_MAX_LENGTH 0x20000 /* an advisory limit */
103
#define PAM_BP_WCONTROL(x) (__PAM_BP_WOCTET(x,4))
104
#define PAM_BP_RCONTROL(x) (__PAM_BP_ROCTET(x,4))
105
#define PAM_BP_SIZE(x) ((__PAM_BP_ROCTET(x,0)<<24)+ \
106
(__PAM_BP_ROCTET(x,1)<<16)+ \
107
(__PAM_BP_ROCTET(x,2)<< 8)+ \
108
(__PAM_BP_ROCTET(x,3) ))
109
#define PAM_BP_LENGTH(x) (PAM_BP_SIZE(x) - PAM_BP_MIN_SIZE)
110
#define PAM_BP_WDATA(x) (PAM_BP_MIN_SIZE + (__u8 *) (x))
111
#define PAM_BP_RDATA(x) (PAM_BP_MIN_SIZE + (const __u8 *) (x))
113
/* Note, this macro always '\0' terminates renewed packets */
115
#define PAM_BP_RENEW(old_p, cntrl, data_length) \
120
__size = PAM_BP_SIZE(*(old_p)); \
121
memset(*(old_p), 0, __size); \
122
PAM_BP_FREE(*(old_p)); \
127
__size = PAM_BP_MIN_SIZE + data_length; \
128
if ((*(old_p) = PAM_BP_CALLOC(1, 1+__size))) { \
129
__PAM_BP_WOCTET(*(old_p), 3) = __size & 0xFF; \
130
__PAM_BP_WOCTET(*(old_p), 2) = (__size>>=8) & 0xFF; \
131
__PAM_BP_WOCTET(*(old_p), 1) = (__size>>=8) & 0xFF; \
132
__PAM_BP_WOCTET(*(old_p), 0) = (__size>>=8) & 0xFF; \
133
(*(old_p))->control = cntrl; \
135
PAM_BP_ASSERT("out of memory for binary prompt"); \
141
PAM_BP_ASSERT("programming error, invalid binary prompt pointer"); \
145
#define PAM_BP_FILL(prmpt, offset, length, data) \
148
__u8 *prompt = (__u8 *) (prmpt); \
149
bp_length = PAM_BP_LENGTH(prompt); \
150
if (bp_length < ((length)+(offset))) { \
151
PAM_BP_ASSERT("attempt to write over end of prompt"); \
153
memcpy((offset) + PAM_BP_WDATA(prompt), (data), (length)); \
156
#define PAM_BP_EXTRACT(prmpt, offset, length, data) \
158
size_t __bp_length; \
159
const __u8 *__prompt = (const __u8 *) (prmpt); \
160
__bp_length = PAM_BP_LENGTH(__prompt); \
161
if (((offset) < 0) || (__bp_length < ((length)+(offset))) \
162
|| ((length) < 0)) { \
163
PAM_BP_ASSERT("invalid extraction from prompt"); \
165
memcpy((data), (offset) + PAM_BP_RDATA(__prompt), (length)); \
174
#define PAM_BPC_FALSE 0
175
#define PAM_BPC_TRUE 1
177
#define PAM_BPC_OK 0x01 /* continuation packet */
178
#define PAM_BPC_SELECT 0x02 /* initialization packet */
179
#define PAM_BPC_DONE 0x03 /* termination packet */
180
#define PAM_BPC_FAIL 0x04 /* unable to execute */
182
/* The following control characters are only legal for echanges
183
between an agent and a client (it is the responsibility of the
184
client to enforce this rule in the face of a rogue server): */
186
#define PAM_BPC_GETENV 0x41 /* obtain client env.var */
187
#define PAM_BPC_PUTENV 0x42 /* set client env.var */
188
#define PAM_BPC_TEXT 0x43 /* display message */
189
#define PAM_BPC_ERROR 0x44 /* display error message */
190
#define PAM_BPC_PROMPT 0x45 /* echo'd text prompt */
191
#define PAM_BPC_PASS 0x46 /* non-echo'd text prompt*/
193
/* quick check for prompts that are legal for the client (by
194
implication the server too) to send to libpamc */
196
#define PAM_BPC_FOR_CLIENT(/* pamc_bp_t */ prompt) \
197
(((prompt)->control <= PAM_BPC_FAIL && (prompt)->control >= PAM_BPC_OK) \
198
? PAM_BPC_TRUE:PAM_BPC_FALSE)
202
#endif /* def __cplusplus */
204
#endif /* PAM_CLIENT_H */