Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
bb21ffec
Commit
bb21ffec
authored
Aug 30, 2010
by
valenok
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved document_root verification to standalone server (into main.c)
parent
39c6d3ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
23 deletions
+22
-23
main.c
main.c
+22
-0
mongoose.c
mongoose.c
+0
-23
No files found.
main.c
View file @
bb21ffec
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#define _CRT_SECURE_NO_WARNINGS
/* Disable deprecation warning in VS2005 */
#define _CRT_SECURE_NO_WARNINGS
/* Disable deprecation warning in VS2005 */
#endif
/* _WIN32 */
#endif
/* _WIN32 */
#include <sys/stat.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <signal.h>
#include <signal.h>
...
@@ -117,6 +118,23 @@ static void show_usage_and_exit(void) {
...
@@ -117,6 +118,23 @@ static void show_usage_and_exit(void) {
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
static
void
verify_document_root
(
const
char
*
root
)
{
const
char
*
p
,
*
path
;
char
buf
[
PATH_MAX
];
struct
stat
st
;
path
=
root
;
if
((
p
=
strchr
(
root
,
','
))
!=
NULL
&&
(
size_t
)
(
p
-
root
)
<
sizeof
(
buf
))
{
strncpy
(
buf
,
root
,
p
-
root
);
path
=
buf
;
}
if
(
stat
(
path
,
&
st
)
!=
0
)
{
fprintf
(
stderr
,
"Invalid root directory:
\"
%s
\"\n
"
,
root
);
exit
(
EXIT_FAILURE
);
}
}
static
char
*
sdup
(
const
char
*
str
)
{
static
char
*
sdup
(
const
char
*
str
)
{
char
*
p
;
char
*
p
;
if
((
p
=
malloc
(
strlen
(
str
)
+
1
))
!=
NULL
)
{
if
((
p
=
malloc
(
strlen
(
str
)
+
1
))
!=
NULL
)
{
...
@@ -128,6 +146,10 @@ static char *sdup(const char *str) {
...
@@ -128,6 +146,10 @@ static char *sdup(const char *str) {
static
void
set_option
(
char
**
options
,
const
char
*
name
,
const
char
*
value
)
{
static
void
set_option
(
char
**
options
,
const
char
*
name
,
const
char
*
value
)
{
int
i
;
int
i
;
if
(
!
strcmp
(
name
,
"document_root"
))
{
verify_document_root
(
value
);
}
for
(
i
=
0
;
i
<
MAX_OPTIONS
-
3
;
i
++
)
{
for
(
i
=
0
;
i
<
MAX_OPTIONS
-
3
;
i
++
)
{
if
(
options
[
i
]
==
NULL
)
{
if
(
options
[
i
]
==
NULL
)
{
options
[
i
]
=
sdup
(
name
);
options
[
i
]
=
sdup
(
name
);
...
...
mongoose.c
View file @
bb21ffec
...
@@ -3459,24 +3459,6 @@ static int set_acl_option(struct mg_context *ctx) {
...
@@ -3459,24 +3459,6 @@ static int set_acl_option(struct mg_context *ctx) {
return
check_acl
(
ctx
,
&
fake
);
return
check_acl
(
ctx
,
&
fake
);
}
}
static
int
verify_document_root
(
struct
mg_context
*
ctx
)
{
char
path
[
PATH_MAX
],
*
p
;
struct
mgstat
buf
;
const
char
*
root
=
ctx
->
config
[
DOCUMENT_ROOT
];
if
((
p
=
strchr
(
root
,
','
))
==
NULL
)
{
mg_strlcpy
(
path
,
root
,
sizeof
(
path
));
}
else
{
mg_strlcpy
(
path
,
root
,
p
-
root
+
1
);
}
if
(
mg_stat
(
path
,
&
buf
)
!=
0
)
{
cry
(
fc
(
ctx
),
"Invalid root directory:
\"
%s
\"
"
,
root
);
return
0
;
}
return
1
;
}
static
void
reset_per_request_attributes
(
struct
mg_connection
*
conn
)
{
static
void
reset_per_request_attributes
(
struct
mg_connection
*
conn
)
{
if
(
conn
->
request_info
.
remote_user
!=
NULL
)
{
if
(
conn
->
request_info
.
remote_user
!=
NULL
)
{
free
((
void
*
)
conn
->
request_info
.
remote_user
);
free
((
void
*
)
conn
->
request_info
.
remote_user
);
...
@@ -3830,11 +3812,6 @@ struct mg_context *mg_start(mg_callback_t user_callback, const char **options) {
...
@@ -3830,11 +3812,6 @@ struct mg_context *mg_start(mg_callback_t user_callback, const char **options) {
DEBUG_TRACE
((
"[%s] -> [%s]"
,
name
,
value
));
DEBUG_TRACE
((
"[%s] -> [%s]"
,
name
,
value
));
}
}
if
(
!
verify_document_root
(
ctx
))
{
free_context
(
ctx
);
return
NULL
;
}
// NOTE(lsm): order is important here. SSL certificates must
// NOTE(lsm): order is important here. SSL certificates must
// be initialized before listening ports. UID must be set last.
// be initialized before listening ports. UID must be set last.
if
(
!
set_ssl_option
(
ctx
)
||
if
(
!
set_ssl_option
(
ctx
)
||
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment