2 * $Id: pam_client.h,v 1.4 2001/01/20 22:29:47 agmorgan Exp $
4 * Copyright (c) 1999 Andrew G. Morgan <morgan@linux.kernel.org>
6 * This header file provides the prototypes for the PAM client API
16 /* opaque agent handling structure */
18 typedef struct pamc_handle_s *pamc_handle_t;
20 /* binary prompt structure pointer */
22 # define __u32 unsigned int
25 # define __u8 unsigned char
27 typedef struct { __u32 length; __u8 control; } *pamc_bp_t;
30 * functions provided by libpamc
34 * Initialize the agent abstraction library
37 pamc_handle_t pamc_start(void);
40 * Terminate the authentication process
43 int pamc_end(pamc_handle_t *pch);
46 * force the loading of a specified agent
49 int pamc_load(pamc_handle_t pch, const char *agent_id);
52 * Single conversation interface for binary prompts
55 int pamc_converse(pamc_handle_t pch, pamc_bp_t *prompt_p);
61 int pamc_disable(pamc_handle_t pch, const char *agent_id);
64 * obtain a list of available agents
67 char **pamc_list_agents(pamc_handle_t pch);
70 * PAM_BP_ MACROS for creating, destroying and manipulating binary prompts
78 # define PAM_BP_ASSERT(x) do { printf(__FILE__ "(%d): %s\n", \
79 __LINE__, x) ; exit(1); } while (0)
80 #endif /* PAM_BP_ASSERT */
83 # define PAM_BP_CALLOC calloc
84 #endif /* PAM_BP_CALLOC */
87 # define PAM_BP_FREE free
88 #endif /* PAM_BP_FREE */
90 #define __PAM_BP_WOCTET(x,y) (*((y) + (__u8 *)(x)))
91 #define __PAM_BP_ROCTET(x,y) (*((y) + (const __u8 *)(x)))
93 #define PAM_BP_MIN_SIZE (sizeof(__u32) + sizeof(__u8))
94 #define PAM_BP_MAX_LENGTH 0x20000 /* an advisory limit */
95 #define PAM_BP_WCONTROL(x) (__PAM_BP_WOCTET(x,4))
96 #define PAM_BP_RCONTROL(x) (__PAM_BP_ROCTET(x,4))
97 #define PAM_BP_SIZE(x) ((__PAM_BP_ROCTET(x,0)<<24)+ \
98 (__PAM_BP_ROCTET(x,1)<<16)+ \
99 (__PAM_BP_ROCTET(x,2)<< 8)+ \
100 (__PAM_BP_ROCTET(x,3) ))
101 #define PAM_BP_LENGTH(x) (PAM_BP_SIZE(x) - PAM_BP_MIN_SIZE)
102 #define PAM_BP_WDATA(x) (PAM_BP_MIN_SIZE + (__u8 *) (x))
103 #define PAM_BP_RDATA(x) (PAM_BP_MIN_SIZE + (const __u8 *) (x))
105 /* Note, this macro always '\0' terminates renewed packets */
107 #define PAM_BP_RENEW(old_p, cntrl, data_length) \
112 __size = PAM_BP_SIZE(*(old_p)); \
113 memset(*(old_p), 0, __size); \
114 PAM_BP_FREE(*(old_p)); \
119 __size = PAM_BP_MIN_SIZE + data_length; \
120 if ((*(old_p) = PAM_BP_CALLOC(1, 1+__size))) { \
121 __PAM_BP_WOCTET(*(old_p), 3) = __size & 0xFF; \
122 __PAM_BP_WOCTET(*(old_p), 2) = (__size>>=8) & 0xFF; \
123 __PAM_BP_WOCTET(*(old_p), 1) = (__size>>=8) & 0xFF; \
124 __PAM_BP_WOCTET(*(old_p), 0) = (__size>>=8) & 0xFF; \
125 (*(old_p))->control = cntrl; \
127 PAM_BP_ASSERT("out of memory for binary prompt"); \
133 PAM_BP_ASSERT("programming error, invalid binary prompt pointer"); \
137 #define PAM_BP_FILL(prmpt, offset, length, data) \
140 __u8 *prompt = (__u8 *) (prmpt); \
141 bp_length = PAM_BP_LENGTH(prompt); \
142 if (bp_length < ((length)+(offset))) { \
143 PAM_BP_ASSERT("attempt to write over end of prompt"); \
145 memcpy((offset) + PAM_BP_WDATA(prompt), (data), (length)); \
148 #define PAM_BP_EXTRACT(prmpt, offset, length, data) \
151 const __u8 *__prompt = (const __u8 *) (prmpt); \
152 __bp_length = PAM_BP_LENGTH(__prompt); \
153 if (((offset) < 0) || (__bp_length < ((length)+(offset))) \
154 || ((length) < 0)) { \
155 PAM_BP_ASSERT("invalid extraction from prompt"); \
157 memcpy((data), (offset) + PAM_BP_RDATA(__prompt), (length)); \
163 #define PAM_BPC_FALSE 0
164 #define PAM_BPC_TRUE 1
166 #define PAM_BPC_OK 0x01 /* continuation packet */
167 #define PAM_BPC_SELECT 0x02 /* initialization packet */
168 #define PAM_BPC_DONE 0x03 /* termination packet */
169 #define PAM_BPC_FAIL 0x04 /* unable to execute */
171 /* The following control characters are only legal for echanges
172 between an agent and a client (it is the responsibility of the
173 client to enforce this rule in the face of a rogue server): */
175 #define PAM_BPC_GETENV 0x41 /* obtain client env.var */
176 #define PAM_BPC_PUTENV 0x42 /* set client env.var */
177 #define PAM_BPC_TEXT 0x43 /* display message */
178 #define PAM_BPC_ERROR 0x44 /* display error message */
179 #define PAM_BPC_PROMPT 0x45 /* echo'd text prompt */
180 #define PAM_BPC_PASS 0x46 /* non-echo'd text prompt*/
182 /* quick check for prompts that are legal for the client (by
183 implication the server too) to send to libpamc */
185 #define PAM_BPC_FOR_CLIENT(/* pamc_bp_t */ prompt) \
186 (((prompt)->control <= PAM_BPC_FAIL && (prompt)->control >= PAM_BPC_OK) \
187 ? PAM_BPC_TRUE:PAM_BPC_FALSE)
190 #endif /* PAM_CLIENT_H */