~ubuntu-branches/ubuntu/breezy/pam/breezy

« back to all changes in this revision

Viewing changes to Linux-PAM/libpamc/include/security/pam_client.h

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2004-06-28 14:28:08 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040628142808-adikk7vtfg3pzcjw
Tags: 0.76-22
* Add uploaders
* Document location of repository
* Fix options containing arguments in pam_unix, Closes: #254904

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: pam_client.h,v 1.4 2002/09/15 21:30:26 hartmans Exp $
 
3
 *
 
4
 * Copyright (c) 1999 Andrew G. Morgan <morgan@linux.kernel.org>
 
5
 *
 
6
 * This header file provides the prototypes for the PAM client API
 
7
 */
 
8
 
 
9
#ifndef PAM_CLIENT_H
 
10
#define PAM_CLIENT_H
 
11
 
 
12
#ifdef __cplusplus 
 
13
extern "C" { 
 
14
#endif /* def __cplusplus */
 
15
 
 
16
#include <unistd.h>
 
17
#include <string.h>
 
18
#include <stdio.h>
 
19
 
 
20
#ifdef __cplusplus
 
21
extern "C" {
 
22
#endif
 
23
 
 
24
/* opaque agent handling structure */
 
25
 
 
26
typedef struct pamc_handle_s *pamc_handle_t;
 
27
 
 
28
/* binary prompt structure pointer */
 
29
#ifndef __u32
 
30
# define __u32  unsigned int
 
31
#endif
 
32
#ifndef __u8
 
33
# define __u8  unsigned char
 
34
#endif
 
35
typedef struct { __u32 length; __u8 control; } *pamc_bp_t;
 
36
 
 
37
/*
 
38
 * functions provided by libpamc
 
39
 */
 
40
 
 
41
/*
 
42
 * Initialize the agent abstraction library
 
43
 */
 
44
 
 
45
pamc_handle_t pamc_start(void);
 
46
 
 
47
/*
 
48
 * Terminate the authentication process
 
49
 */
 
50
 
 
51
int pamc_end(pamc_handle_t *pch);
 
52
 
 
53
/*
 
54
 * force the loading of a specified agent
 
55
 */
 
56
 
 
57
int pamc_load(pamc_handle_t pch, const char *agent_id);
 
58
 
 
59
/*
 
60
 * Single conversation interface for binary prompts
 
61
 */
 
62
 
 
63
int pamc_converse(pamc_handle_t pch, pamc_bp_t *prompt_p);
 
64
 
 
65
/*
 
66
 * disable an agent
 
67
 */
 
68
 
 
69
int pamc_disable(pamc_handle_t pch, const char *agent_id);
 
70
 
 
71
/*
 
72
 * obtain a list of available agents
 
73
 */
 
74
 
 
75
char **pamc_list_agents(pamc_handle_t pch);
 
76
 
 
77
/*
 
78
 * PAM_BP_ MACROS for creating, destroying and manipulating binary prompts
 
79
 */
 
80
 
 
81
#include <stdlib.h>
 
82
#include <stdio.h>
 
83
#include <unistd.h>
 
84
 
 
85
#ifndef PAM_BP_ASSERT
 
86
# define PAM_BP_ASSERT(x)   do { printf(__FILE__ "(%d): %s\n", \
 
87
                                        __LINE__, x) ; exit(1); } while (0)
 
88
#endif /* PAM_BP_ASSERT */
 
89
 
 
90
#ifndef PAM_BP_CALLOC
 
91
# define PAM_BP_CALLOC      calloc
 
92
#endif /* PAM_BP_CALLOC */
 
93
 
 
94
#ifndef PAM_BP_FREE
 
95
# define PAM_BP_FREE        free
 
96
#endif /* PAM_BP_FREE */
 
97
 
 
98
#define __PAM_BP_WOCTET(x,y)  (*((y) + (__u8 *)(x)))
 
99
#define __PAM_BP_ROCTET(x,y)  (*((y) + (const __u8 *)(x)))
 
100
 
 
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))
 
112
 
 
113
/* Note, this macro always '\0' terminates renewed packets */
 
114
 
 
115
#define PAM_BP_RENEW(old_p, cntrl, data_length)                            \
 
116
do {                                                                       \
 
117
    if (old_p) {                                                           \
 
118
        if (*(old_p)) {                                                    \
 
119
            __u32 __size;                                                  \
 
120
            __size = PAM_BP_SIZE(*(old_p));                                \
 
121
            memset(*(old_p), 0, __size);                                   \
 
122
            PAM_BP_FREE(*(old_p));                                         \
 
123
        }                                                                  \
 
124
        if (cntrl) {                                                       \
 
125
            __u32 __size;                                                  \
 
126
                                                                           \
 
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;                               \
 
134
            } else {                                                       \
 
135
                PAM_BP_ASSERT("out of memory for binary prompt");          \
 
136
            }                                                              \
 
137
        } else {                                                           \
 
138
            *old_p = NULL;                                                 \
 
139
        }                                                                  \
 
140
    } else {                                                               \
 
141
        PAM_BP_ASSERT("programming error, invalid binary prompt pointer"); \
 
142
    }                                                                      \
 
143
} while (0)
 
144
 
 
145
#define PAM_BP_FILL(prmpt, offset, length, data)                           \
 
146
do {                                                                       \
 
147
    size_t bp_length;                                                      \
 
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");              \
 
152
    }                                                                      \
 
153
    memcpy((offset) + PAM_BP_WDATA(prompt), (data), (length));             \
 
154
} while (0)
 
155
 
 
156
#define PAM_BP_EXTRACT(prmpt, offset, length, data)                        \
 
157
do {                                                                       \
 
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");                   \
 
164
    }                                                                      \
 
165
    memcpy((data), (offset) + PAM_BP_RDATA(__prompt), (length));           \
 
166
} while (0)
 
167
 
 
168
#ifdef __cplusplus
 
169
}
 
170
#endif
 
171
 
 
172
/* Control types */
 
173
 
 
174
#define PAM_BPC_FALSE   0
 
175
#define PAM_BPC_TRUE    1
 
176
 
 
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     */
 
181
 
 
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): */
 
185
 
 
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*/
 
192
 
 
193
/* quick check for prompts that are legal for the client (by
 
194
   implication the server too) to send to libpamc */
 
195
 
 
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)
 
199
 
 
200
#ifdef __cplusplus
 
201
}
 
202
#endif /* def __cplusplus */
 
203
 
 
204
#endif /* PAM_CLIENT_H */