Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 61544 | Differences between
and this patch

Collapse All | Expand All

(-)hylafax-org/hfaxd/HylaFAXServer.h (-1 / +22 lines)
Lines 48-53 Link Here
48
}
48
}
49
#endif // HAVE_PAM
49
#endif // HAVE_PAM
50
50
51
#ifdef HAVE_LDAP
52
#include <ldap.h>
53
#include <string.h>
54
#include <stdlib.h>
55
#include <sys/time.h>
56
#include <stdio.h>
57
#include <lber.h>
58
#include <iostream.h>
59
#include <fstream.h>
60
61
extern char sIP [ ];
62
extern int iPort;
63
extern int iLDAPVersion;
64
extern char p_LDAP_Admin_Name [ ];
65
extern char p_LDAP_Admin_Passwd [ ];
66
extern char p_LDAP_Base [ ];
67
int read_ldap_config(const char* pConfig, char* pIP, int* pPort, char* pAdminLogin, char* pAdminPassword, char* pBase, int* pVersion);
68
#endif // HAVE_LDAP
69
51
#include <sys/types.h>
70
#include <sys/types.h>
52
#include <sys/socket.h>
71
#include <sys/socket.h>
53
#include <dirent.h>
72
#include <dirent.h>
Lines 355-360 Link Here
355
    bool userID(const char*, u_int& id);
374
    bool userID(const char*, u_int& id);
356
    void fillIDCache(void);
375
    void fillIDCache(void);
357
376
377
    bool ldapCheck(const char* user, const char* pass);
378
358
    bool cvtPasswd(const char* type, const char* pass, fxStr& result);
379
    bool cvtPasswd(const char* type, const char* pass, fxStr& result);
359
    bool findUser(FILE* db, const char* user, u_int& newuid);
380
    bool findUser(FILE* db, const char* user, u_int& newuid);
360
    bool addUser(FILE* db, const char* user, u_int uid,
381
    bool addUser(FILE* db, const char* user, u_int uid,
Lines 589-595 Link Here
589
 * business seeing.  Also we implement an access
610
 * business seeing.  Also we implement an access
590
 * control system that is built on top of the
611
 * control system that is built on top of the
591
 * normal UNIX protection mechanisms.
612
 * normal UNIX protection mechanisms.
592
 */ 
613
 */
593
struct SpoolDir {
614
struct SpoolDir {
594
    const char*	pathname;
615
    const char*	pathname;
595
    bool adminOnly;	// accessible by unprivileged clients
616
    bool adminOnly;	// accessible by unprivileged clients
(-)hylafax-org/hfaxd/Login.c++ (+105 lines)
Lines 137-142 Link Here
137
	return(retval);
137
	return(retval);
138
}
138
}
139
139
140
/**
141
* ldapCheck
142
* function checks if user with selected login and password exists in LDAP
143
* param user [IN] - pointer to string containing user login
144
* param pass [IN] - pointer to string containing user password
145
* return true if user exists
146
*/
147
bool
148
HylaFAXServer::ldapCheck( const char* user, const char* pass )
149
{
150
	bool retval = false;
151
#ifdef HAVE_LDAP
152
153
	int err;
154
	char filter [ 255 ];
155
	snprintf( filter, 255, "uid=%s", user );
156
	char* pspass;
157
	char spass[ 255 ];
158
	LDAPMessage* pEntries;
159
	LDAPMessage* pEntry;
160
	char **p_arr_values;
161
	char ldap_conf_file [ 1024 ];
162
	LDAP* p_LDAPConn;
163
164
	snprintf( ldap_conf_file, 1024, "%s/etc/ldap.conf", FAX_SPOOLDIR ); // create string with configuration file path name
165
166
	err = read_ldap_config( ( const char* ) ldap_conf_file, sIP, &iPort, p_LDAP_Admin_Name, p_LDAP_Admin_Passwd, p_LDAP_Base, &iLDAPVersion );
167
168
	if ( err == -1 )
169
	{
170
		reply( 530, "Configuration file not found" );
171
		return false;
172
	}
173
	if ( err == -2 )
174
	{
175
		reply( 530, "Configuration file incomplete" );
176
		return false;
177
	}
178
179
	p_LDAPConn = ldap_init( sIP, iPort );
180
	if ( p_LDAPConn == NULL )
181
	{
182
		reply( 530, "Unable to connect to LDAP" );
183
		return false;
184
	}
185
	err = ldap_set_option( p_LDAPConn, LDAP_OPT_PROTOCOL_VERSION, ( void * ) & iLDAPVersion );
186
	if ( err != LDAP_SUCCESS )
187
	{
188
		reply( 530, "Set Option LDAP error %d: %s", err, ldap_err2string( err ) );
189
		ldap_unbind_s( p_LDAPConn );
190
		return false;
191
	}
192
193
	err = ldap_simple_bind_s( p_LDAPConn, p_LDAP_Admin_Name, p_LDAP_Admin_Passwd );
194
	if ( err != LDAP_SUCCESS )
195
	{
196
		reply( 530, "Bind LDAP error %d: %s", err, ldap_err2string( err ) );
197
		ldap_unbind_s( p_LDAPConn );
198
		return false;
199
	}
200
201
	err = ldap_search_s( p_LDAPConn, p_LDAP_Base, LDAP_SCOPE_SUBTREE, filter, NULL, 0, &pEntries );
202
	if ( err != LDAP_SUCCESS )
203
	{
204
		reply( 530, "Search LDAP error %d: %s", err, ldap_err2string( err ) );
205
		ldap_unbind_s( p_LDAPConn );
206
		return false;
207
	}
208
	pEntry = ldap_first_entry( p_LDAPConn, pEntries );
209
	if ( pEntry == NULL )
210
	{
211
		reply( 530, "LDAP user not found" );
212
		ldap_unbind_s( p_LDAPConn );
213
		return false;
214
	}
215
216
	p_arr_values = ldap_get_values( p_LDAPConn, pEntry, "userPassword" );
217
	if ( p_arr_values == NULL )
218
	{
219
		reply( 530, "LDAP attribute userPassword not found" );
220
		ldap_unbind_s( p_LDAPConn );
221
		return false;
222
	}
223
224
	strcpy( spass, p_arr_values[ 0 ] );
225
	ldap_value_free( p_arr_values );
226
	ldap_unbind_s( p_LDAPConn );
227
228
	pspass = spass;
229
230
	if ( strncmp( spass, "{crypt}", 7 ) == 0 )
231
		pspass += 7;
232
233
	retval = ( strcmp( crypt( pass, pspass ), pspass ) == 0 );
234
#endif //HAVE_LDAP
235
236
	return retval;
237
}
238
140
bool
239
bool
141
HylaFAXServer::pamCheck(const char* user, const char* pass)
240
HylaFAXServer::pamCheck(const char* user, const char* pass)
142
{
241
{
Lines 196-202 Link Here
196
	pass++;
295
	pass++;
197
    } else
296
    } else
198
	state |= S_LREPLIES;
297
	state |= S_LREPLIES;
298
#ifdef HAVE_LDAP
299
    if (pass[0] == '\0' || !(ldapCheck(the_user, pass))) {
300
#else
199
    if (pass[0] == '\0' || !(strcmp(crypt(pass, passwd), passwd) == 0 || pamCheck(the_user, pass))) {
301
    if (pass[0] == '\0' || !(strcmp(crypt(pass, passwd), passwd) == 0 || pamCheck(the_user, pass))) {
302
#endif
200
	if (++loginAttempts >= maxLoginAttempts) {
303
	if (++loginAttempts >= maxLoginAttempts) {
201
	    reply(530, "Login incorrect (closing connection).");
304
	    reply(530, "Login incorrect (closing connection).");
202
	    logNotice("Repeated login failures for user %s from %s [%s]"
305
	    logNotice("Repeated login failures for user %s from %s [%s]"
Lines 332-334 Link Here
332
	Sys::unlink(clientFIFOName);
435
	Sys::unlink(clientFIFOName);
333
    _exit(status);		// beware of flushing buffers after a SIGPIPE
436
    _exit(status);		// beware of flushing buffers after a SIGPIPE
334
}
437
}
438
439
(-)hylafax-org/hfaxd/User.c++ (+172 lines)
Lines 49-54 Link Here
49
gid_t	HylaFAXServer::faxuid = 0;		// reserved fax uid
49
gid_t	HylaFAXServer::faxuid = 0;		// reserved fax uid
50
#define	FAXUID_RESV	HylaFAXServer::faxuid	// reserved fax uid
50
#define	FAXUID_RESV	HylaFAXServer::faxuid	// reserved fax uid
51
51
52
#ifdef HAVE_LDAP
53
char sIP [ 16 ];
54
int iPort;
55
int iLDAPVersion;
56
char p_LDAP_Admin_Name [ 255 ];
57
char p_LDAP_Admin_Passwd [ 255 ];
58
char p_LDAP_Base [ 1024 ];
59
#endif // HAVE_LDAP
60
61
62
#ifdef HAVE_LDAP
63
/**
64
* read_ldap_config
65
* param pConfig [IN] points to configuration file name
66
* param pIP [OUT] (attribute "LDAPServerIP") points to buffer which will receive LDAP Server IP (buffer must be large enough - there isn't any overrun protection)
67
* param pPort [OUT] (attribute "LDAPServerPort") points to variable which will receive LDAP Server port
68
* param pAdminLogin [OUT] (attribute "LDAPAdminName") points to buffer which will receive LDAP Server Admin Login (buffer must be large enough - there isn't any overrun protection)
69
* param pAdminPassword [OUT] (attribute "LDAPAdminPasswd") points to buffer which will receive LDAP Server Admin Password (buffer must be large enough - there isn't any overrun protection)
70
* param pBase [OUT] (attribute "LDAPBase") points to buffer which will receive LDAP Server Base Node Value (buffer must be large enough - there isn't any overrun protection)
71
* param pVersion [OUT] (attribute "LDAPVersion") points to variable which will receive LDAP Server Version to set
72
* return 0 - no error occured
73
* return -1 - configuration file missing / not found / unable to open
74
* return -2 - at least one of output values were not found in configuration file and not set
75
* configuration line format: <attribute>':'[' ' | '\t']<value>
76
*/
77
int read_ldap_config(const char* pConfig, char* pIP, int* pPort, char* pAdminLogin, char* pAdminPassword, char* pBase, int* pVersion)
78
{
79
    static bool bRead = false;
80
    if (bRead)
81
	return 0;
82
83
    int retval;
84
    int cnt = 0;
85
    char line [ 1024 ];
86
    char* pA, *pB;
87
    bool fTrim;
88
89
    uid_t ouid = geteuid();
90
    seteuid( 0 );
91
92
    FILE* stream = fopen((char*) pConfig, "r"); // open configuration file
93
94
    int err = errno;
95
    seteuid(ouid);
96
97
    if (stream == NULL) {
98
	return -1;
99
    }
100
101
    // Parse configuration file
102
    while (!feof(stream)) {
103
	if (fgets(line, sizeof(line), stream) == NULL)
104
	    break;
105
106
	fTrim = false;
107
	pA = (char*) line;
108
	if ( line[strlen(line)-1] == '\n')
109
	    line[strlen(line)-1] = 0;
110
111
	int len = strlen(line);
112
	for (int i = 0; i < len; i++) {
113
	    if (fTrim) {
114
		if (line[i] == ' ' || line[i] == '\t') {
115
		    line[ i ] = 0;
116
		    pB = ((char*) line)+i+1;
117
		} else
118
    		    break;
119
    	    }
120
	    if (line[i] == ':') {
121
		line[i] = 0;
122
		fTrim = true;
123
		pB = ((char*) line)+i+1;
124
	    }
125
	}
126
	
127
        if (strcmp(pA,"LDAPServerIP") == 0) {
128
    	    strcpy(pIP, pB);
129
	    cnt++;
130
	}
131
	if (strcmp(pA, "LDAPServerPort") == 0) {
132
	    *pPort = atoi(pB);
133
	    cnt++;
134
	}
135
	if (strcmp(pA, "LDAPAdminName") == 0) {
136
	    strcpy(pAdminLogin, pB);
137
	    cnt++;
138
	}
139
	if (strcmp(pA, "LDAPAdminPasswd") == 0) {
140
	    strcpy(pAdminPassword, pB);
141
	    cnt++;
142
	}
143
	if (strcmp(pA, "LDAPBase") == 0) {
144
	    strcpy(pBase, pB);
145
	    cnt++;
146
	}
147
	if (strcmp(pA, "LDAPVersion") == 0) {
148
	    *pVersion = atoi( pB );
149
	    cnt++;
150
	}
151
    }
152
153
    fclose(stream); // close configuration file
154
155
    // end of parsing configuration file
156
    if (cnt != 6)
157
	return -2;
158
159
    bRead = true;
160
    return 0;
161
}
162
#endif // HAVE_LDAP
163
164
165
#ifdef HAVE_LDAP
166
bool
167
HylaFAXServer::checkUser(const char* name)
168
{
169
    int err;
170
    LDAP* p_LDAPConn;
171
    char filter [255];
172
    
173
    snprintf(filter, 255, "uid=%s", name);
174
    
175
    char* pspass;
176
    char spass[255];
177
    LDAPMessage* pEntries;
178
    bool retval;
179
180
    char ldap_conf_file [1024];
181
    snprintf(ldap_conf_file, 1024, "%s/etc/ldap.conf", FAX_SPOOLDIR); // create string with configuration file path name
182
183
    err = read_ldap_config((const char*) ldap_conf_file, sIP, &iPort, p_LDAP_Admin_Name, p_LDAP_Admin_Passwd, p_LDAP_Base, &iLDAPVersion);
184
    if (err == -1) {
185
	reply(530, "Configuration file not found");
186
	return false;
187
    }
188
    if (err == -2) {
189
	reply(530, "Configuration file incomplete");
190
	return false;
191
    }
192
193
    p_LDAPConn = ldap_init(sIP, iPort);
194
    if (p_LDAPConn == NULL) {
195
	reply(530, "Unable to connect to LDAP");
196
	return false;
197
    }
198
    err = ldap_set_option(p_LDAPConn, LDAP_OPT_PROTOCOL_VERSION, (void *) & iLDAPVersion);
199
    if (err != LDAP_SUCCESS) {
200
	reply(530, "Set Option LDAP error %d: %s", err, ldap_err2string(err));
201
	ldap_unbind_s(p_LDAPConn);
202
	return false;
203
    }
204
    err = ldap_simple_bind_s(p_LDAPConn, p_LDAP_Admin_Name, p_LDAP_Admin_Passwd);
205
    if (err != LDAP_SUCCESS) {
206
	reply(530, "Bind LDAP error %d: %s", err, ldap_err2string(err));
207
	ldap_unbind_s(p_LDAPConn);
208
	return false;
209
    }
210
    err = ldap_search_s(p_LDAPConn, p_LDAP_Base, LDAP_SCOPE_SUBTREE, filter, NULL, 0, &pEntries);
211
    if (err != LDAP_SUCCESS) {
212
	reply(530, "Search LDAP error %d: %s", err, ldap_err2string(err));
213
	ldap_unbind_s(p_LDAPConn);
214
	return false;
215
    }
216
    retval = (ldap_first_entry(p_LDAPConn, pEntries) != NULL);
217
    ldap_unbind_s(p_LDAPConn);
218
219
    return retval;
220
}
221
#else // HAVE_LDAP is not defined
222
// previous (original) checkUser function version used by non-LDAP authentication
52
bool
223
bool
53
HylaFAXServer::checkUser(const char* name)
224
HylaFAXServer::checkUser(const char* name)
54
{
225
{
Lines 62-67 Link Here
62
	    (const char*) userAccessFile, strerror(errno));
233
	    (const char*) userAccessFile, strerror(errno));
63
    return (check);
234
    return (check);
64
}
235
}
236
#endif // HAVE_LDAP
65
237
66
static bool
238
static bool
67
nextRecord(FILE* db, char line[], u_int size)
239
nextRecord(FILE* db, char line[], u_int size)

Return to bug 61544