Skip to content

Commit 761c02d

Browse files
committed
1.1
1.1
1 parent 4badaad commit 761c02d

File tree

8 files changed

+65
-15
lines changed

8 files changed

+65
-15
lines changed

script/heaphttpd.conf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ ProxyAuthenticate = None
6969

7070
################################################################
7171
# User List #
72+
# "IntegrateLocalUsers" only supports Basic auth way #
73+
# "IntegrateLocalUsers" excludes root #
7274
################################################################
73-
UserListFile=/etc/heaphttpd/users.xml
75+
IntegrateLocalUsers = no
76+
UsersListFile=/etc/heaphttpd/users.xml
7477

7578
################################################################
7679
# Private path: for temporary files #

src/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ INCDIR = -I../$(OPENSSL_DIR)/include
4141
LDDIRS = -L.
4242

4343
ifdef memcached
44-
LDLIST_HTTP = -lstdc++ -lmemcached -lheapauth -lheapwebsocket
44+
LDLIST_HTTP = -lstdc++ -lcrypt -lmemcached -lheapauth -lheapwebsocket
4545
MEMCACHED_DEF = _WITH_MEMCACHED_
4646
else
47-
LDLIST_HTTP = -lstdc++ -lheapauth -lheapwebsocket
47+
LDLIST_HTTP = -lstdc++ -lcrypt -lheapauth -lheapwebsocket
4848
MEMCACHED_DEF = _WITHOUT_MEMCACHED_
4949
endif
5050

src/base.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ vector<string> CHttpBase::m_permit_list;
115115

116116
vector<string> CHttpBase::m_default_webpages;
117117

118+
BOOL CHttpBase::m_integrate_local_users = FALSE;
119+
118120
#ifdef _WITH_MEMCACHED_
119121
map<string, int> CHttpBase::m_memcached_list;
120122
#endif /* _WITH_MEMCACHED_ */
@@ -189,7 +191,7 @@ BOOL CHttpBase::LoadConfig()
189191
strcut(strline.c_str(), "=", NULL, m_ext_list_file);
190192
strtrim(m_ext_list_file);
191193
}
192-
else if(strncasecmp(strline.c_str(), "UserListFile", sizeof("UserListFile") - 1) == 0)
194+
else if(strncasecmp(strline.c_str(), "UsersListFile", sizeof("UsersListFile") - 1) == 0)
193195
{
194196
strcut(strline.c_str(), "=", NULL, m_users_list_file);
195197
strtrim(m_users_list_file);
@@ -327,6 +329,13 @@ BOOL CHttpBase::LoadConfig()
327329
strcut(strline.c_str(), "=", NULL, m_proxy_authenticate );
328330
strtrim(m_proxy_authenticate);
329331
}
332+
else if(strncasecmp(strline.c_str(), "IntegrateLocalUsers", sizeof("IntegrateLocalUsers") - 1) == 0)
333+
{
334+
string IntegrateLocalUsers;
335+
strcut(strline.c_str(), "=", NULL, IntegrateLocalUsers );
336+
strtrim(IntegrateLocalUsers);
337+
m_integrate_local_users = (strcasecmp(IntegrateLocalUsers.c_str(), "yes")) == 0 ? TRUE : FALSE;
338+
}
330339
else if(strncasecmp(strline.c_str(), "DefaultWebPages", sizeof("DefaultWebPages") - 1) == 0)
331340
{
332341
string default_webpages;

src/base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ class CHttpBase
472472

473473
static vector<string> m_default_webpages;
474474

475+
static BOOL m_integrate_local_users;
476+
475477
static string m_www_authenticate;
476478
static string m_proxy_authenticate;
477479
static BOOL m_client_cer_check;

src/http.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ Http_Connection CHttp::LineParse(const char* text)
11281128

11291129
string php_auth_pwd;
11301130

1131-
if(WWW_Auth(this, asBasic, strauth.c_str(), m_username, php_auth_pwd))
1131+
if(WWW_Auth(this, asBasic, CHttpBase::m_integrate_local_users ? true : false, strauth.c_str(), m_username, php_auth_pwd))
11321132
{
11331133
m_passed_wwwauth = TRUE;
11341134
m_cgi.SetMeta("REMOTE_USER", m_username.c_str());
@@ -1146,7 +1146,7 @@ Http_Connection CHttp::LineParse(const char* text)
11461146

11471147
m_cgi.SetMeta("AUTH_TYPE", "Digest");
11481148

1149-
if(WWW_Auth(this, asDigest, strauth.c_str(), m_username, php_digest, HTTP_METHOD_NAME[m_http_method]))
1149+
if(WWW_Auth(this, asDigest, CHttpBase::m_integrate_local_users ? true : false, strauth.c_str(), m_username, php_digest, HTTP_METHOD_NAME[m_http_method]))
11501150
{
11511151
m_passed_wwwauth = TRUE;
11521152
m_cgi.SetMeta("REMOTE_USER", m_username.c_str());
@@ -1161,7 +1161,7 @@ Http_Connection CHttp::LineParse(const char* text)
11611161

11621162
string php_auth_pwd;
11631163

1164-
if(WWW_Auth(this, asBasic, strauth.c_str(), m_username, php_auth_pwd))
1164+
if(WWW_Auth(this, asBasic, CHttpBase::m_integrate_local_users ? true : false, strauth.c_str(), m_username, php_auth_pwd))
11651165
{
11661166
m_passed_proxyauth = TRUE;
11671167
}
@@ -1173,7 +1173,7 @@ Http_Connection CHttp::LineParse(const char* text)
11731173

11741174
string php_digest;
11751175

1176-
if(WWW_Auth(this, asDigest, strauth.c_str(), m_username, php_digest, HTTP_METHOD_NAME[m_http_method]))
1176+
if(WWW_Auth(this, asDigest, CHttpBase::m_integrate_local_users ? true : false, strauth.c_str(), m_username, php_digest, HTTP_METHOD_NAME[m_http_method]))
11771177
{
11781178
m_passed_proxyauth = TRUE;
11791179
}

src/wwwauth.cpp

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
#include <stdlib.h>
66
#include <stdio.h>
77
#include <string.h>
8+
#include <errno.h>
9+
#include <crypt.h>
10+
#include <shadow.h>
11+
#include <string.h>
12+
#include <unistd.h>
813
#include "wwwauth.h"
914
#include "util/digcalc.h"
1015
#include "util/base64.h"
@@ -106,7 +111,7 @@ void __inline__ _strtrim_dquote_(string &src) /* icnluding double quote mark*/
106111
}
107112
}
108113

109-
bool WWW_Auth(CHttp* psession, AUTH_SCHEME scheme, const char* authinfo, string& username, string &keywords, const char* method)
114+
bool WWW_Auth(CHttp* psession, AUTH_SCHEME scheme, bool integrate_local_users, const char* authinfo, string& username, string &keywords, const char* method)
110115
{
111116
string password, real_password;
112117
if(scheme == asBasic)
@@ -125,13 +130,44 @@ bool WWW_Auth(CHttp* psession, AUTH_SCHEME scheme, const char* authinfo, string&
125130

126131
keywords = password;
127132

128-
if(heaphttpd_usrdef_get_password(psession, username.c_str(), real_password) && password == real_password)
133+
if(integrate_local_users)
129134
{
130-
keywords = real_password;
131-
return true;
135+
if(strcasecmp(username.c_str(),"root") == 0)// forbid root for login for security reason.
136+
{
137+
return false;
138+
}
139+
//Get shadow password.
140+
struct spwd *spw_info = getspnam(username.c_str());
141+
if (!spw_info)
142+
{
143+
return false;
144+
}
145+
146+
// Hash and report.
147+
struct crypt_data pwd_data;
148+
pwd_data.initialized = 0;
149+
char *pwd_hashed = crypt_r(password.c_str(), spw_info->sp_pwdp, &pwd_data);
150+
if (pwd_hashed && strcmp(spw_info->sp_pwdp, pwd_hashed) == 0)
151+
{
152+
return true;
153+
}
154+
else
155+
{
156+
return false;
157+
}
158+
159+
160+
}
161+
else
162+
{
163+
if(heaphttpd_usrdef_get_password(psession, username.c_str(), real_password) && password == real_password)
164+
{
165+
keywords = real_password;
166+
return true;
167+
}
168+
else
169+
return false;
132170
}
133-
else
134-
return false;
135171
}
136172
else if(scheme == asDigest)
137173
{

src/wwwauth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ typedef enum
2020
asDigest
2121
} AUTH_SCHEME;
2222

23-
bool WWW_Auth(CHttp* psession, AUTH_SCHEME scheme, const char* authinfo, string& username, string &keywords, const char* method = "GET");
23+
bool WWW_Auth(CHttp* psession, AUTH_SCHEME scheme, bool integrate_local_users, const char* authinfo, string& username, string &keywords, const char* method = "GET");
2424

2525
#endif /* _WWW_AUTH_ */
344 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)