Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 64 additions & 64 deletions labels/debug.asm

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions labels/flagparser.asm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ parse_flags:
jmp .next_arg

.error_e:
PRINTN log_flag_e_error, log_flag_e_error_len
PRINTN str_flag_e_error, str_flag_e_error_len
EXIT 1


Expand All @@ -126,12 +126,12 @@ parse_flags:
ret

.arg_not_recognized:
PRINT log_arg_not_recognized_p1, log_arg_not_recognized_p1_len
PRINT str_arg_not_recognized_p1, str_arg_not_recognized_p1_len

STRLEN rsi, rcx
PRINT rsi, rcx

PRINTN log_arg_not_recognized_p2, log_arg_not_recognized_p2_len
PRINTN str_arg_not_recognized_p2, str_arg_not_recognized_p2_len
EXIT 1

.done:
Expand Down
58 changes: 29 additions & 29 deletions labels/initialsetup.asm
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ section .bss
auth_realm resb 129 ; HTTP 1.0 Basic Auth Realm

; logs
log_level_str resb 6 ; "debug\0"
log_level resb 1 ; 0 = none, 1 = normal, 2 = verbose
log_file_path resb 129 ; Path to access/error log
log_file resq 1 ; Log file descriptor (64-bit)
str_level_str resb 6 ; "debug\0"
str_level resb 1 ; 0 = none, 1 = normal, 2 = verbose
str_file_path resb 129 ; Path to access/error log
str_file resq 1 ; Log file descriptor (64-bit)

; errordocs
errordoc_400 resb 129
Expand Down Expand Up @@ -241,11 +241,11 @@ initial_setup:
BOOL_FLAG be_nobody_str, be_nobody

; process the log level
ENV_DEFAULT env_path_buf, key_loglevel, log_level_str, 6, default_loglevel
call .parse_log_level
ENV_DEFAULT env_path_buf, key_loglevel, str_level_str, 6, default_loglevel
call .parse_str_level

; open the log file
ENV_DEFAULT env_path_buf, key_logfile, log_file_path, 129, default_logfile
ENV_DEFAULT env_path_buf, key_logfile, str_file_path, 129, default_logfile
call .open_logfile

ENV_DEFAULT env_path_buf, key_bindaddr, bind_addr_str, 16, default_bindaddr
Expand Down Expand Up @@ -285,26 +285,26 @@ initial_setup:
ret ; .build_server_name return point

.open_logfile:
cmp byte [rel log_file_path], 0
je .no_log_file
cmp byte [rel str_file_path], 0
je .no_str_file

OPEN_FILE_A log_file_path
OPEN_FILE_A str_file_path

cmp rax, 0
jl .no_log_file ; failed to open / create it
jl .no_str_file ; failed to open / create it

mov qword [rel log_file], rax
mov qword [rel str_file], rax

jmp .log_file_end
jmp .str_file_end

.no_log_file:
mov qword [rel log_file], 1 ; no log file = stdout
.no_str_file:
mov qword [rel str_file], 1 ; no log file = stdout

.log_file_end:
.str_file_end:
ret ; open_logfile len

.parse_log_level:
lea rax, [rel log_level_str]
.parse_str_level:
lea rax, [rel str_level_str]

; "debug"
cmp dword [rax], 'debu'
Expand All @@ -313,41 +313,41 @@ initial_setup:
cmp byte [rax+4], 'g'
jne .check_none

mov byte [rel log_level], 2
mov byte [rel str_level], 2

jmp .log_level_end
jmp .str_level_end

.check_none:
; "none"
cmp dword [rax], 'none'
jne .check_info

mov byte [rel log_level], 0
mov byte [rel str_level], 0

jmp .log_level_end
jmp .str_level_end

.check_info:
; "info" or anything unrecognized = 0
mov byte [rel log_level], 1
mov byte [rel str_level], 1
ret

.log_level_end:
ret ; .parse_log_level return point
.str_level_end:
ret ; .parse_str_level return point

.failed_read_file:
LOG_ERR log_fail_read_env, log_fail_read_env_len
LOG_ERR str_fail_read_env, str_fail_read_env_len
EXIT 1

.bad_bind_addr:
LOG_ERR log_fail_build_addr, log_fail_build_addr_len
LOG_ERR str_fail_build_addr, str_fail_build_addr_len
EXIT 1

.display_help:
PRINTN log_help_text, log_help_text_len
PRINTN str_help_text, str_help_text_len
EXIT 0

.display_version:
PRINT log_version, log_version_len
PRINT str_version, str_version_len
STRLEN server_w_ver, rcx
PRINTN server_w_ver, rcx
EXIT 0
12 changes: 6 additions & 6 deletions labels/preserve.asm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pre_serve:
BUILDPATH errordoc_401_path, document_root, errordoc_401
BUILDPATH errordoc_400_path, document_root, errordoc_400

LOG_DEBUG log_errordoc_paths_rebuilt, log_errordoc_paths_rebuilt_len
LOG_DEBUG str_errordoc_paths_rebuilt, str_errordoc_paths_rebuilt_len

jmp .chroot_end

Expand Down Expand Up @@ -135,11 +135,11 @@ pre_serve:

mov dword [rel current_uid], 65534

LOG_DEBUG log_nobody_succeeded, log_nobody_succeeded_len
LOG_DEBUG str_nobody_succeeded, str_nobody_succeeded_len
jmp .nobody_end

.nobody_fail:
LOG_WARNING log_nobody_failed, log_nobody_failed_len
LOG_WARNING str_nobody_failed, str_nobody_failed_len

.nobody_end:
ret ; .im_nobody return point
Expand Down Expand Up @@ -306,16 +306,16 @@ pre_serve:
ret ; return point for .sigint_handler

.fail_socket:
LOG_ERR log_fail_socket, log_fail_socket_len
LOG_ERR str_fail_socket, str_fail_socket_len
mov rdi, rax
EXIT rdi

.fail_setsockopt:
LOG_ERR log_fail_setsockopt, log_fail_setsockopt_len
LOG_ERR str_fail_setsockopt, str_fail_setsockopt_len
mov rdi, rax
EXIT rdi

.fail_bind:
LOG_ERR log_fail_bind, log_fail_bind_len
LOG_ERR str_fail_bind, str_fail_bind_len
mov rdi, rax
EXIT rdi
28 changes: 14 additions & 14 deletions labels/startupchecks.asm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ startup_checks:
cmp rax, 2
je .check_docroot_perms

LOG_ERR log_check_docroot_missing, log_check_docroot_missing_len
LOG_ERR str_check_docroot_missing, str_check_docroot_missing_len
EXIT 1

.check_docroot_perms:
Expand All @@ -33,7 +33,7 @@ startup_checks:
cmp rax, 0
je .check_errordocs

LOG_ERR log_check_docroot_perms, log_check_docroot_perms_len
LOG_ERR str_check_docroot_perms, str_check_docroot_perms_len
EXIT 1

.check_errordocs:
Expand All @@ -49,7 +49,7 @@ startup_checks:
cmp rax, 1
je .check_errordoc_401

LOG_WARNING log_check_errordoc_missing, log_check_errordoc_missing_len
LOG_WARNING str_check_errordoc_missing, str_check_errordoc_missing_len

.check_errordoc_401:
lea rdi, [rel errordoc_401_path]
Expand All @@ -62,7 +62,7 @@ startup_checks:
cmp rax, 1
je .check_errordoc_403

LOG_WARNING log_check_errordoc_missing, log_check_errordoc_missing_len
LOG_WARNING str_check_errordoc_missing, str_check_errordoc_missing_len

.check_errordoc_403:
lea rdi, [rel errordoc_403_path]
Expand All @@ -75,7 +75,7 @@ startup_checks:
cmp rax, 1
je .check_errordoc_404

LOG_WARNING log_check_errordoc_missing, log_check_errordoc_missing_len
LOG_WARNING str_check_errordoc_missing, str_check_errordoc_missing_len

.check_errordoc_404:
lea rdi, [rel errordoc_404_path]
Expand All @@ -88,7 +88,7 @@ startup_checks:
cmp rax, 1
je .check_errordoc_405

LOG_WARNING log_check_errordoc_missing, log_check_errordoc_missing_len
LOG_WARNING str_check_errordoc_missing, str_check_errordoc_missing_len

.check_errordoc_405:
lea rdi, [rel errordoc_405_path]
Expand All @@ -101,17 +101,17 @@ startup_checks:
cmp rax, 1
je .check_logfile

LOG_WARNING log_check_errordoc_missing, log_check_errordoc_missing_len
LOG_WARNING str_check_errordoc_missing, str_check_errordoc_missing_len

.check_logfile:
cmp byte [rel log_file_path], 0
cmp byte [rel str_file_path], 0
je .check_port ; no file path provided, just skep

cmp qword [rel log_file], 1
cmp qword [rel str_file], 1
jne .check_port ; if != 1, its ok

; if its 1, it means that we failed to open the file
LOG_WARNING log_log_file_not_opened, log_log_file_not_opened_len
LOG_WARNING str_str_file_not_opened, str_str_file_not_opened_len

.check_port:
mov eax, [rel current_uid]
Expand All @@ -122,7 +122,7 @@ startup_checks:
cmp rax, 1024
jge .check_chroot

LOG_WARNING log_check_port_privileged, log_check_port_privileged_len
LOG_WARNING str_check_port_privileged, str_check_port_privileged_len

.check_chroot:
cmp byte [rel use_chroot], 1
Expand All @@ -133,7 +133,7 @@ startup_checks:
je .check_nobody

; if not root, we won't be able to chroot
LOG_WARNING log_chroot_noroot, log_chroot_noroot_len
LOG_WARNING str_chroot_noroot, str_chroot_noroot_len

.check_nobody:
cmp byte [rel be_nobody], 1
Expand All @@ -144,10 +144,10 @@ startup_checks:
je .checks_done

; if not root, we won't be able to set uid to nobody
LOG_WARNING log_nobody_noroot, log_nobody_noroot_len
LOG_WARNING str_nobody_noroot, str_nobody_noroot_len

.checks_done:
LOG_INFO log_startup_ok, log_startup_ok_len
LOG_INFO str_startup_ok, str_startup_ok_len

pop rbp
ret
Loading
Loading