From b2d6ff5690832d1945fda82b631834e918366cbb Mon Sep 17 00:00:00 2001 From: douxxtech Date: Sun, 14 Jun 2026 23:48:53 +0200 Subject: [PATCH 1/3] Moved all logutils.asm strings to strings.asm --- labels/debug.asm | 128 ++++++++--------- labels/flagparser.asm | 6 +- labels/initialsetup.asm | 58 ++++---- labels/preserve.asm | 12 +- labels/startupchecks.asm | 28 ++-- labels/strings.asm | 206 +++++++++++++++++++++++++++ macros/logutils.asm | 292 ++++++--------------------------------- program.asm | 32 +++-- 8 files changed, 382 insertions(+), 380 deletions(-) create mode 100644 labels/strings.asm diff --git a/labels/debug.asm b/labels/debug.asm index 262ff6c..370f5a3 100644 --- a/labels/debug.asm +++ b/labels/debug.asm @@ -14,7 +14,7 @@ section .text global warn_sighandler_fail dbg_new_child: - cmp byte [rel log_level], 2 + cmp byte [rel str_level], 2 jne dbg_skip CLB @@ -24,9 +24,9 @@ dbg_new_child: ITOA r10, current_pid_str, rcx lea r9, [rel log_buffer] - AAPPEND r9, log_child_created_p1 + AAPPEND r9, str_child_created_p1 AAPPEND r9, current_pid_str - AAPPEND r9, log_child_created_p2 + AAPPEND r9, str_child_created_p2 AAPPEND r9, client_ip_str mov byte [r9], 0 @@ -39,15 +39,15 @@ dbg_new_child: ret ; dbg_new_child return point dbg_child_exit: - cmp byte [rel log_level], 2 + cmp byte [rel str_level], 2 jne dbg_skip CLB lea r9, [rel log_buffer] - AAPPEND r9, log_child_exit_p1 + AAPPEND r9, str_child_exit_p1 AAPPEND r9, current_pid_str - AAPPEND r9, log_child_exit_p2 + AAPPEND r9, str_child_exit_p2 mov byte [r9], 0 lea rcx, [rel log_buffer] @@ -59,13 +59,13 @@ dbg_child_exit: ret ; dbg_child_exit return point dbg_path_resolved: - cmp byte [rel log_level], 2 + cmp byte [rel str_level], 2 jne dbg_skip CLB lea r9, [rel log_buffer] - AAPPEND r9, log_path_resolved + AAPPEND r9, str_path_resolved lea rdi, [rel path] STRLEN rdi, rcx @@ -79,13 +79,13 @@ dbg_path_resolved: ret ; dbg_path_resolved return point dbg_dotfile_blocked: - cmp byte [rel log_level], 2 + cmp byte [rel str_level], 2 jne dbg_skip CLB lea r9, [rel log_buffer] - AAPPEND r9, log_dotfile_blocked + AAPPEND r9, str_dotfile_blocked lea rdi, [rel path] STRLEN rdi, rcx @@ -99,7 +99,7 @@ dbg_dotfile_blocked: ret ; dbg_dotfile_blocked return point dbg_status_code: - cmp byte [rel log_level], 2 + cmp byte [rel str_level], 2 jne dbg_skip mov r10, rdi @@ -110,7 +110,7 @@ dbg_status_code: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_replying_with_code + AAPPEND r9, str_replying_with_code AAPPEND r9, itoa_buf lea rcx, [rel log_buffer] @@ -123,7 +123,7 @@ dbg_status_code: ret ; dbg_status_code return point dbg_bytes_sent: - cmp byte [rel log_level], 2 + cmp byte [rel str_level], 2 jne dbg_skip mov r10, rax @@ -133,9 +133,9 @@ dbg_bytes_sent: lea r9, [rel log_buffer] - AAPPEND r9, log_sent_bytes_p1 + AAPPEND r9, str_sent_bytes_p1 AAPPEND r9, itoa_buf - AAPPEND r9, log_sent_bytes_p2 + AAPPEND r9, str_sent_bytes_p2 lea rcx, [rel log_buffer] sub r9, rcx @@ -146,7 +146,7 @@ dbg_bytes_sent: ret ; dbg_bytes_sent return point dbg_process_reaped: - cmp byte [rel log_level], 2 + cmp byte [rel str_level], 2 jne dbg_skip CLB @@ -156,13 +156,13 @@ dbg_process_reaped: lea r9, [rel log_buffer] - AAPPEND r9, log_process_reaped + AAPPEND r9, str_process_reaped AAPPEND r9, itoa_buf movzx r10, word [rel max_requests] ITOA r10, itoa_buf, rcx - AAPPEND r9, log_slash + AAPPEND r9, str_slash AAPPEND r9, itoa_buf lea rcx, [rel log_buffer] @@ -174,14 +174,14 @@ dbg_process_reaped: ret ; dbg_process_reaped return point dbg_chroot_success: - cmp byte [rel log_level], 2 + cmp byte [rel str_level], 2 jne dbg_skip CLB lea r9, [rel log_buffer] - AAPPEND r9, log_chroot_succeeded + AAPPEND r9, str_chroot_succeeded AAPPEND r9, document_root lea rcx, [rel log_buffer] @@ -193,16 +193,16 @@ dbg_chroot_success: ret ; warn_chroot_fail return point warn_chroot_fail: ; yea thats a warning but meh - cmp byte [rel log_level], 0 + cmp byte [rel str_level], 0 je dbg_skip CLB lea r9, [rel log_buffer] - AAPPEND r9, log_chroot_failed_p1 + AAPPEND r9, str_chroot_failed_p1 AAPPEND r9, document_root - AAPPEND r9, log_chroot_failed_p2 + AAPPEND r9, str_chroot_failed_p2 lea rcx, [rel log_buffer] sub r9, rcx @@ -213,7 +213,7 @@ warn_chroot_fail: ; yea thats a warning but meh ret ; warn_chroot_fail return point dbg_sighandler_success: - cmp byte [rel log_level], 0 + cmp byte [rel str_level], 0 je dbg_skip mov r10, rax ; rax content: 17 = sigchld, 15 = sigterm, 2 = sigint @@ -222,7 +222,7 @@ dbg_sighandler_success: lea r9, [rel log_buffer] - AAPPEND r9, log_success_sighandler_p1 + AAPPEND r9, str_success_sighandler_p1 cmp r10, 17 je .sigchld @@ -236,19 +236,19 @@ dbg_sighandler_success: je dbg_skip ; if its something unexpected, just skip .sigchld: - AAPPEND r9, log_sighanlder_sigchld + AAPPEND r9, str_sighanlder_sigchld jmp .end .sigterm: - AAPPEND r9, log_sighanlder_sigterm + AAPPEND r9, str_sighanlder_sigterm jmp .end .sigint: - AAPPEND r9, log_sighanlder_sigint + AAPPEND r9, str_sighanlder_sigint jmp .end .end: - AAPPEND r9, log_success_sighandler_p2 + AAPPEND r9, str_success_sighandler_p2 lea rcx, [rel log_buffer] sub r9, rcx @@ -260,7 +260,7 @@ dbg_sighandler_success: warn_sighandler_fail: - cmp byte [rel log_level], 0 + cmp byte [rel str_level], 0 je dbg_skip mov r10, rax ; rax content: 17 = sigchld, 15 = sigterm, 2 = sigint @@ -269,7 +269,7 @@ warn_sighandler_fail: lea r9, [rel log_buffer] - AAPPEND r9, log_fail_sighandler_p1 + AAPPEND r9, str_fail_sighandler_p1 cmp r10, 17 je .sigchld @@ -283,19 +283,19 @@ warn_sighandler_fail: je dbg_skip ; if its something unexpected, just skip .sigchld: - AAPPEND r9, log_sighanlder_sigchld + AAPPEND r9, str_sighanlder_sigchld jmp .end .sigterm: - AAPPEND r9, log_sighanlder_sigterm + AAPPEND r9, str_sighanlder_sigterm jmp .end .sigint: - AAPPEND r9, log_sighanlder_sigint + AAPPEND r9, str_sighanlder_sigint jmp .end .end: - AAPPEND r9, log_fail_sighandler_p2 + AAPPEND r9, str_fail_sighandler_p2 lea rcx, [rel log_buffer] sub r9, rcx @@ -306,7 +306,7 @@ warn_sighandler_fail: ret ; warn_sighandler_fail return point dbg_startup_infos: - cmp byte [rel log_level], 2 + cmp byte [rel str_level], 2 jne dbg_skip .pid_uid: @@ -317,9 +317,9 @@ dbg_startup_infos: lea r9, [rel log_buffer] - AAPPEND r9, log_process_started_p1 + AAPPEND r9, str_process_started_p1 AAPPEND r9, itoa_buf - AAPPEND r9, log_process_started_p2 + AAPPEND r9, str_process_started_p2 AAPPEND r9, current_pid_str lea rcx, [rel log_buffer] @@ -331,7 +331,7 @@ dbg_startup_infos: .config: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_header + AAPPEND r9, str_config_header lea rcx, [rel log_buffer] sub r9, rcx mov rbx, r9 @@ -339,7 +339,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_docroot + AAPPEND r9, str_config_docroot AAPPEND r9, document_root lea rcx, [rel log_buffer] sub r9, rcx @@ -348,7 +348,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_index + AAPPEND r9, str_config_index AAPPEND r9, index_file lea rcx, [rel log_buffer] sub r9, rcx @@ -357,7 +357,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_bindaddr + AAPPEND r9, str_config_bindaddr AAPPEND r9, bind_addr_str lea rcx, [rel log_buffer] sub r9, rcx @@ -366,7 +366,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_port + AAPPEND r9, str_config_port movzx r10, word [rel port] ITOA r10, itoa_buf, rcx AAPPEND r9, itoa_buf @@ -377,7 +377,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_maxreqs + AAPPEND r9, str_config_maxreqs movzx r10, word [rel max_requests] ITOA r10, itoa_buf, rcx AAPPEND r9, itoa_buf @@ -388,7 +388,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_maxage + AAPPEND r9, str_config_maxage mov r10d, dword [rel max_age] ITOA r10, itoa_buf, rcx AAPPEND r9, itoa_buf @@ -399,7 +399,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_lingerto + AAPPEND r9, str_config_lingerto movzx r10, word [rel linger_to] ITOA r10, itoa_buf, rcx AAPPEND r9, itoa_buf @@ -410,7 +410,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_servername + AAPPEND r9, str_config_servername AAPPEND r9, server_w_ver lea rcx, [rel log_buffer] sub r9, rcx @@ -419,8 +419,8 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_logfile - AAPPEND r9, log_file_path + AAPPEND r9, str_config_logfile + AAPPEND r9, str_file_path lea rcx, [rel log_buffer] sub r9, rcx mov rbx, r9 @@ -428,8 +428,8 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_loglevel - AAPPEND r9, log_level_str + AAPPEND r9, str_config_loglevel + AAPPEND r9, str_level_str lea rcx, [rel log_buffer] sub r9, rcx mov rbx, r9 @@ -437,7 +437,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_servedots + AAPPEND r9, str_config_servedots AAPPEND r9, serve_dots_str lea rcx, [rel log_buffer] sub r9, rcx @@ -446,7 +446,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_usexri + AAPPEND r9, str_config_usexri AAPPEND r9, use_xri_str lea rcx, [rel log_buffer] sub r9, rcx @@ -455,7 +455,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_usechroot + AAPPEND r9, str_config_usechroot AAPPEND r9, use_chroot_str lea rcx, [rel log_buffer] sub r9, rcx @@ -464,7 +464,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_noperms + AAPPEND r9, str_config_noperms AAPPEND r9, be_nobody_str lea rcx, [rel log_buffer] sub r9, rcx @@ -473,7 +473,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_authrealm + AAPPEND r9, str_config_authrealm AAPPEND r9, auth_realm lea rcx, [rel log_buffer] sub r9, rcx @@ -482,7 +482,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_authuser + AAPPEND r9, str_config_authuser AAPPEND r9, auth_username lea rcx, [rel log_buffer] sub r9, rcx @@ -492,10 +492,10 @@ dbg_startup_infos: ; auth_password: show ****** if set, empty if not CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_authpass + AAPPEND r9, str_config_authpass cmp byte [rel auth_password], 0 je .config_pass_empty - AAPPEND r9, log_config_authpass_set + AAPPEND r9, str_config_authpass_set .config_pass_empty: lea rcx, [rel log_buffer] sub r9, rcx @@ -504,7 +504,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_err400 + AAPPEND r9, str_config_err400 AAPPEND r9, errordoc_400_path lea rcx, [rel log_buffer] sub r9, rcx @@ -513,7 +513,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_err401 + AAPPEND r9, str_config_err401 AAPPEND r9, errordoc_401_path lea rcx, [rel log_buffer] sub r9, rcx @@ -522,7 +522,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_err403 + AAPPEND r9, str_config_err403 AAPPEND r9, errordoc_403_path lea rcx, [rel log_buffer] sub r9, rcx @@ -531,7 +531,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_err404 + AAPPEND r9, str_config_err404 AAPPEND r9, errordoc_404_path lea rcx, [rel log_buffer] sub r9, rcx @@ -540,7 +540,7 @@ dbg_startup_infos: CLB lea r9, [rel log_buffer] - AAPPEND r9, log_config_err405 + AAPPEND r9, str_config_err405 AAPPEND r9, errordoc_405_path lea rcx, [rel log_buffer] sub r9, rcx diff --git a/labels/flagparser.asm b/labels/flagparser.asm index cd15263..6025ffa 100644 --- a/labels/flagparser.asm +++ b/labels/flagparser.asm @@ -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 @@ -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: diff --git a/labels/initialsetup.asm b/labels/initialsetup.asm index d627cfb..e2871b3 100644 --- a/labels/initialsetup.asm +++ b/labels/initialsetup.asm @@ -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 @@ -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 @@ -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' @@ -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 \ No newline at end of file diff --git a/labels/preserve.asm b/labels/preserve.asm index b292c7a..da17de1 100644 --- a/labels/preserve.asm +++ b/labels/preserve.asm @@ -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 @@ -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 @@ -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 \ No newline at end of file diff --git a/labels/startupchecks.asm b/labels/startupchecks.asm index ce9d39d..2593fe0 100644 --- a/labels/startupchecks.asm +++ b/labels/startupchecks.asm @@ -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: @@ -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: @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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 @@ -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 @@ -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 \ No newline at end of file diff --git a/labels/strings.asm b/labels/strings.asm new file mode 100644 index 0000000..c79f11d --- /dev/null +++ b/labels/strings.asm @@ -0,0 +1,206 @@ +; strings.asm - all strings for this program + +section .text + str_space db " ", 0 + str_space_len equ $ - str_space - 1 + + str_quotation_mark db 0x22, 0 ; '"' + str_quotation_mark_len equ $ - str_quotation_mark - 1 + + str_two_dots db ":", 0 + str_two_dots_len equ $ - str_two_dots - 1 + + str_slash db "/", 0 + str_slash_len equ $ - str_slash - 1 + + + ; startup banner + str_started_nasmserver db "Started the NASMServer static files HTTP server.", 0xa, 0 + str_started_nasmserver_len equ $ - str_started_nasmserver - 1 + + + ; startup checks + str_startup_ok db "Startup checks passed", 0 + str_startup_ok_len equ $ - str_startup_ok - 1 + + str_check_docroot_missing db "document_root does not exist or is not a directory", 0 + str_check_docroot_missing_len equ $ - str_check_docroot_missing - 1 + + str_check_docroot_perms db "document_root is not readable/accessible", 0 + str_check_docroot_perms_len equ $ - str_check_docroot_perms - 1 + + str_check_errordoc_missing db "Errordoc file not found (requests will get empty error pages)", 0 + str_check_errordoc_missing_len equ $ - str_check_errordoc_missing - 1 + + str_check_port_privileged db "Port < 1024 might require root privileges", 0 + str_check_port_privileged_len equ $ - str_check_port_privileged - 1 + + str_str_file_not_opened db "Failed to open the provided log file (missing permissions?). STDOUT will be used instead.", 0 + str_str_file_not_opened_len equ $ - str_str_file_not_opened - 1 + + str_chroot_noroot db "Not able to chroot since we're not root", 0 + str_chroot_noroot_len equ $ - str_chroot_noroot - 1 + + str_nobody_noroot db "Not able to set uid to nobody since we're not root", 0 + str_nobody_noroot_len equ $ - str_nobody_noroot - 1 + + ; startup errors / warnings + str_fail_read_env db "Failed to read the provided configuration file path", 0 + str_fail_read_env_len equ $ - str_fail_read_env - 1 + + str_fail_build_addr db "Failed to parse the provided BIND_ADDRESS. Make sure to provide a valid IPv4 address.", 0 + str_fail_build_addr_len equ $ - str_fail_build_addr - 1 + + str_fail_socket db "Failed to open socket", 0 + str_fail_socket_len equ $ - str_fail_socket - 1 + + str_fail_setsockopt db "Failed to set socket options", 0 + str_fail_setsockopt_len equ $ - str_fail_setsockopt - 1 + + str_fail_bind db "Failed to bind to port", 0 + str_fail_bind_len equ $ - str_fail_bind - 1 + + str_fail_accept db "Failed to accept connection", 0 + str_fail_accept_len equ $ - str_fail_accept - 1 + + str_listening_on db "Listening on ", 0 + str_listening_on_len equ $ - str_listening_on - 1 + + ; request logging + ; common log format extended + clfe_missing db "-", 0 + clfe_missing_len equ $ - clfe_missing - 1 + + clfe_start_ts db "[", 0 + clfe_start_ts_len equ $ - clfe_start_ts - 1 + + clfe_end_ts db "]", 0 + clfe_end_ts_len equ $ - clfe_end_ts - 1 + + clfe_nobytes db "0", 0 + clfe_nobytes_len equ $ - clfe_nobytes - 1 + + ; HTTP status messages + str_status_200 db "200 OK", 0xa, 0 + str_status_200_len equ $ - str_status_200 - 1 + + str_status_304 db "304 Not Modified", 0xa, 0 + str_status_304_len equ $ - str_status_304 - 1 + + str_status_400 db "400 Bad Request", 0xa, 0 + str_status_400_len equ $ - str_status_400 - 1 + + str_status_401 db "401 Unauthorized", 0xa, 0 + str_status_401_len equ $ - str_status_401 - 1 + + str_status_403 db "403 Forbidden", 0xa, 0 + str_status_403_len equ $ - str_status_403 - 1 + + str_status_404 db "404 Not Found", 0xa, 0 + str_status_404_len equ $ - str_status_404 - 1 + + str_status_405 db "405 Method Not Allowed", 0xa, 0 + str_status_405_len equ $ - str_status_405 - 1 + + + ; runtime logs + str_too_many_concurrent db "Rejected request: too many concurrent requests", 0 + str_too_many_concurrent_len equ $ - str_too_many_concurrent - 1 + + str_stopping db "Stopping... (signal received)", 0 + str_stopping_len equ $ - str_stopping - 1 + + str_child_created_p1 db "Started new child (", 0 + str_child_created_p2 db ") to handle request from ", 0 + + str_child_exit_p1 db "Exiting child (", 0 + str_child_exit_p2 db "): request served", 0 + + str_method_head db "Resolved method to HEAD", 0 + str_method_head_len equ $ - str_method_head - 1 + + str_method_get db "Resolved method to GET", 0 + str_method_get_len equ $ - str_method_get - 1 + + str_path_resolved db "Resolved path to ", 0 + + str_dotfile_blocked db "Dotfile access blocked: ", 0 + + str_replying_with_code db "Replying to request with status code ", 0 + + str_sent_bytes_p1 db "Replying to request with ", 0 + str_sent_bytes_p2 db " bytes (body)", 0 + + str_process_reaped db "Process reaped, current count: ", 0 + + str_chroot_failed_p1 db "Failed to chroot into ", 0 + str_chroot_failed_p2 db ", continuing anyways...", 0 + + str_chroot_succeeded db "Successfully chroot-ed into ", 0 + + str_errordoc_paths_rebuilt db "Errordoc paths rebuilt", 0 + str_errordoc_paths_rebuilt_len equ $ - str_errordoc_paths_rebuilt - 1 + + str_nobody_failed db "Failed to drop privileges to nobody, continuing anyways...", 0 + str_nobody_failed_len equ $ - str_nobody_failed - 1 + + str_nobody_succeeded db "Successfully dropped privileges to nobody", 0 + str_nobody_succeeded_len equ $ - str_nobody_succeeded - 1 + + str_success_sighandler_p1 db "Successfully registered the ", 0 + str_success_sighandler_p2 db " signal handler", 0 + + str_fail_sighandler_p1 db "Failed to register the ", 0 + str_fail_sighandler_p2 db ", continuing anyways...", 0 + + str_sighanlder_sigterm db "SIGTERM", 0 + str_sighanlder_sigint db "SIGINT", 0 + str_sighanlder_sigchld db "SIGCHLD", 0 + + str_process_started_p1 db "Main process started by UID ", 0 + str_process_started_p2 db " with PID ", 0 + + str_config_header db "Loaded config:", 0 + str_config_docroot db " DOCUMENT_ROOT: ", 0 + str_config_index db " INDEX_FILE: ", 0 + str_config_bindaddr db " BIND_ADDRESS: ", 0 + str_config_port db " PORT: ", 0 + str_config_maxreqs db " MAX_REQUESTS: ", 0 + str_config_maxage db " MAX_AGE: ", 0 + str_config_lingerto db " LINGER_TIMEOUT: ", 0 + str_config_servername db " SERVER_NAME: ", 0 + str_config_logfile db " LOG_FILE: ", 0 + str_config_loglevel db " LOG_LEVEL: ", 0 + str_config_servedots db " SERVE_DOTS: ", 0 + str_config_usexri db " USE_X_REAL_IP: ", 0 + str_config_usechroot db " USE_CHROOT: ", 0 + str_config_noperms db " DROP_PRIVILEGES: ", 0 + str_config_authrealm db " AUTH_REALM: ", 0 + str_config_authuser db " AUTH_USER: ", 0 + str_config_authpass db " AUTH_PASSWORD: ", 0 + str_config_authpass_set db "********", 0 ; shown if password is set + str_config_err400 db " ERRORDOC_400: ", 0 + str_config_err401 db " ERRORDOC_401: ", 0 + str_config_err403 db " ERRORDOC_403: ", 0 + str_config_err404 db " ERRORDOC_404: ", 0 + str_config_err405 db " ERRORDOC_405: ", 0 + + ; CLI / arguments / help + str_arg_not_recognized_p1 db "Argument '", 0 + str_arg_not_recognized_p1_len equ $ - str_arg_not_recognized_p1 - 1 + + str_arg_not_recognized_p2 db "' is not recognized by NASMServer.", 0xa, \ + "Run nasmserver -h to see the list of available flags and arguments.", 0 + str_arg_not_recognized_p2_len equ $ - str_arg_not_recognized_p2 - 1 + + str_flag_e_error db "Missing value after '-e'. Usage: -e ", 0 + str_flag_e_error_len equ $ - str_flag_e_error - 1 + + str_help_text db "Usage: nasmserver [-h] [-e ]", 0xa, \ + " -h show this help", 0xa, \ + " -v show the current version", 0xa, \ + " -e path to the .env config file", 0xa, 0 + str_help_text_len equ $ - str_help_text - 1 + + str_version db "Server version: ", 0 + str_version_len equ $ - str_version - 1 \ No newline at end of file diff --git a/macros/logutils.asm b/macros/logutils.asm index 6542692..65fa63c 100644 --- a/macros/logutils.asm +++ b/macros/logutils.asm @@ -9,223 +9,17 @@ section .data rs_fmt db "%d/%b/%Y:%H:%M:%S %z", 0 - log_space db " ", 0 - log_space_len equ $ - log_space - 1 + str_prefix_info db "[INFO] ", 0 + str_prefix_info_len equ $ - str_prefix_info - 1 - log_quotation_mark db 0x22, 0 ; '"' - log_quotation_mark_len equ $ - log_quotation_mark - 1 + str_prefix_warning db "[WARNING] ", 0 + str_prefix_warning_len equ $ - str_prefix_warning - 1 - log_two_dots db ":", 0 - log_two_dots_len equ $ - log_two_dots - 1 + str_prefix_err db "[ERROR] ", 0 + str_prefix_err_len equ $ - str_prefix_err - 1 - log_slash db "/", 0 - log_slash_len equ $ - log_slash - 1 - - - ; log level prefixes - - log_prefix_info db "[INFO] ", 0 - log_prefix_info_len equ $ - log_prefix_info - 1 - - log_prefix_warning db "[WARNING] ", 0 - log_prefix_warning_len equ $ - log_prefix_warning - 1 - - log_prefix_err db "[ERROR] ", 0 - log_prefix_err_len equ $ - log_prefix_err - 1 - - log_prefix_dbg db "* ", 0 - log_prefix_dbg_len equ $ - log_prefix_dbg - 1 - - ; startup banner - log_started_nasmserver db "Started the NASMServer static files HTTP server.", 0xa, 0 - log_started_nasmserver_len equ $ - log_started_nasmserver - 1 - - - ; startup checks - log_startup_ok db "Startup checks passed", 0 - log_startup_ok_len equ $ - log_startup_ok - 1 - - log_check_docroot_missing db "document_root does not exist or is not a directory", 0 - log_check_docroot_missing_len equ $ - log_check_docroot_missing - 1 - - log_check_docroot_perms db "document_root is not readable/accessible", 0 - log_check_docroot_perms_len equ $ - log_check_docroot_perms - 1 - - log_check_errordoc_missing db "Errordoc file not found (requests will get empty error pages)", 0 - log_check_errordoc_missing_len equ $ - log_check_errordoc_missing - 1 - - log_check_port_privileged db "Port < 1024 might require root privileges", 0 - log_check_port_privileged_len equ $ - log_check_port_privileged - 1 - - log_log_file_not_opened db "Failed to open the provided log file (missing permissions?). STDOUT will be used instead.", 0 - log_log_file_not_opened_len equ $ - log_log_file_not_opened - 1 - - log_chroot_noroot db "Not able to chroot since we're not root", 0 - log_chroot_noroot_len equ $ - log_chroot_noroot - 1 - - log_nobody_noroot db "Not able to set uid to nobody since we're not root", 0 - log_nobody_noroot_len equ $ - log_nobody_noroot - 1 - - ; startup errors / warnings - log_fail_read_env db "Failed to read the provided configuration file path", 0 - log_fail_read_env_len equ $ - log_fail_read_env - 1 - - log_fail_build_addr db "Failed to parse the provided BIND_ADDRESS. Make sure to provide a valid IPv4 address.", 0 - log_fail_build_addr_len equ $ - log_fail_build_addr - 1 - - log_fail_socket db "Failed to open socket", 0 - log_fail_socket_len equ $ - log_fail_socket - 1 - - log_fail_setsockopt db "Failed to set socket options", 0 - log_fail_setsockopt_len equ $ - log_fail_setsockopt - 1 - - log_fail_bind db "Failed to bind to port", 0 - log_fail_bind_len equ $ - log_fail_bind - 1 - - log_fail_accept db "Failed to accept connection", 0 - log_fail_accept_len equ $ - log_fail_accept - 1 - - log_listening_on db "Listening on ", 0 - log_listening_on_len equ $ - log_listening_on - 1 - - ; request logging - ; common log format extended - clfe_missing db "-", 0 - clfe_missing_len equ $ - clfe_missing - 1 - - clfe_start_ts db "[", 0 - clfe_start_ts_len equ $ - clfe_start_ts - 1 - - clfe_end_ts db "]", 0 - clfe_end_ts_len equ $ - clfe_end_ts - 1 - - clfe_nobytes db "0", 0 - clfe_nobytes_len equ $ - clfe_nobytes - 1 - - ; HTTP status messages - log_status_200 db "200 OK", 0xa, 0 - log_status_200_len equ $ - log_status_200 - 1 - - log_status_304 db "304 Not Modified", 0xa, 0 - log_status_304_len equ $ - log_status_304 - 1 - - log_status_400 db "400 Bad Request", 0xa, 0 - log_status_400_len equ $ - log_status_400 - 1 - - log_status_401 db "401 Unauthorized", 0xa, 0 - log_status_401_len equ $ - log_status_401 - 1 - - log_status_403 db "403 Forbidden", 0xa, 0 - log_status_403_len equ $ - log_status_403 - 1 - - log_status_404 db "404 Not Found", 0xa, 0 - log_status_404_len equ $ - log_status_404 - 1 - - log_status_405 db "405 Method Not Allowed", 0xa, 0 - log_status_405_len equ $ - log_status_405 - 1 - - - ; runtime logs - log_too_many_concurrent db "Rejected request: too many concurrent requests", 0 - log_too_many_concurrent_len equ $ - log_too_many_concurrent - 1 - - log_stopping db "Stopping... (signal received)", 0 - log_stopping_len equ $ - log_stopping - 1 - - log_child_created_p1 db "Started new child (", 0 - log_child_created_p2 db ") to handle request from ", 0 - - log_child_exit_p1 db "Exiting child (", 0 - log_child_exit_p2 db "): request served", 0 - - log_method_head db "Resolved method to HEAD", 0 - log_method_head_len equ $ - log_method_head - 1 - - log_method_get db "Resolved method to GET", 0 - log_method_get_len equ $ - log_method_get - 1 - - log_path_resolved db "Resolved path to ", 0 - - log_dotfile_blocked db "Dotfile access blocked: ", 0 - - log_replying_with_code db "Replying to request with status code ", 0 - - log_sent_bytes_p1 db "Replying to request with ", 0 - log_sent_bytes_p2 db " bytes (body)", 0 - - log_process_reaped db "Process reaped, current count: ", 0 - - log_chroot_failed_p1 db "Failed to chroot into ", 0 - log_chroot_failed_p2 db ", continuing anyways...", 0 - - log_chroot_succeeded db "Successfully chroot-ed into ", 0 - - log_errordoc_paths_rebuilt db "Errordoc paths rebuilt", 0 - log_errordoc_paths_rebuilt_len equ $ - log_errordoc_paths_rebuilt - 1 - - log_nobody_failed db "Failed to drop privileges to nobody, continuing anyways...", 0 - log_nobody_failed_len equ $ - log_nobody_failed - 1 - - log_nobody_succeeded db "Successfully dropped privileges to nobody", 0 - log_nobody_succeeded_len equ $ - log_nobody_succeeded - 1 - - log_success_sighandler_p1 db "Successfully registered the ", 0 - log_success_sighandler_p2 db " signal handler", 0 - - log_fail_sighandler_p1 db "Failed to register the ", 0 - log_fail_sighandler_p2 db ", continuing anyways...", 0 - - log_sighanlder_sigterm db "SIGTERM", 0 - log_sighanlder_sigint db "SIGINT", 0 - log_sighanlder_sigchld db "SIGCHLD", 0 - - log_process_started_p1 db "Main process started by UID ", 0 - log_process_started_p2 db " with PID ", 0 - - log_config_header db "Loaded config:", 0 - log_config_docroot db " DOCUMENT_ROOT: ", 0 - log_config_index db " INDEX_FILE: ", 0 - log_config_bindaddr db " BIND_ADDRESS: ", 0 - log_config_port db " PORT: ", 0 - log_config_maxreqs db " MAX_REQUESTS: ", 0 - log_config_maxage db " MAX_AGE: ", 0 - log_config_lingerto db " LINGER_TIMEOUT: ", 0 - log_config_servername db " SERVER_NAME: ", 0 - log_config_logfile db " LOG_FILE: ", 0 - log_config_loglevel db " LOG_LEVEL: ", 0 - log_config_servedots db " SERVE_DOTS: ", 0 - log_config_usexri db " USE_X_REAL_IP: ", 0 - log_config_usechroot db " USE_CHROOT: ", 0 - log_config_noperms db " DROP_PRIVILEGES: ", 0 - log_config_authrealm db " AUTH_REALM: ", 0 - log_config_authuser db " AUTH_USER: ", 0 - log_config_authpass db " AUTH_PASSWORD: ", 0 - log_config_authpass_set db "********", 0 ; shown if password is set - log_config_err400 db " ERRORDOC_400: ", 0 - log_config_err401 db " ERRORDOC_401: ", 0 - log_config_err403 db " ERRORDOC_403: ", 0 - log_config_err404 db " ERRORDOC_404: ", 0 - log_config_err405 db " ERRORDOC_405: ", 0 - - ; CLI / arguments / help - log_arg_not_recognized_p1 db "Argument '", 0 - log_arg_not_recognized_p1_len equ $ - log_arg_not_recognized_p1 - 1 - - log_arg_not_recognized_p2 db "' is not recognized by NASMServer.", 0xa, \ - "Run nasmserver -h to see the list of available flags and arguments.", 0 - log_arg_not_recognized_p2_len equ $ - log_arg_not_recognized_p2 - 1 - - log_flag_e_error db "Missing value after '-e'. Usage: -e ", 0 - log_flag_e_error_len equ $ - log_flag_e_error - 1 - - log_help_text db "Usage: nasmserver [-h] [-e ]", 0xa, \ - " -h show this help", 0xa, \ - " -v show the current version", 0xa, \ - " -e path to the .env config file", 0xa, 0 - log_help_text_len equ $ - log_help_text - 1 - - log_version db "Server version: ", 0 - log_version_len equ $ - log_version - 1 + str_prefix_dbg db "* ", 0 + str_prefix_dbg_len equ $ - str_prefix_dbg - 1 section .bss @@ -278,12 +72,12 @@ section .bss ; Clobbers: rax, rdi, rsi, rdx, rcx %macro LOG_INFO 2 ; check if we should log or not - cmp byte [rel log_level], 0 ; log lvl none = skip + cmp byte [rel str_level], 0 ; log lvl none = skip je %%end %%log: PRINT_TIMESTAMP - PRINT log_prefix_info, log_prefix_info_len + PRINT str_prefix_info, str_prefix_info_len PRINTN %1, %2 %%end: @@ -297,12 +91,12 @@ section .bss ; Clobbers: rax, rdi, rsi, rdx, rcx %macro LOG_WARNING 2 ; check if we should log or not - cmp byte [rel log_level], 0 ; log lvl none = skip + cmp byte [rel str_level], 0 ; log lvl none = skip je %%end %%log: PRINT_TIMESTAMP - PRINT log_prefix_warning, log_prefix_warning_len + PRINT str_prefix_warning, str_prefix_warning_len PRINTN %1, %2 %%end: @@ -316,12 +110,12 @@ section .bss ; Clobbers: rax, rdi, rsi, rdx, rcx %macro LOG_ERR 2 ; check if we should log or not - cmp byte [rel log_level], 0 ; log lvl none = skip + cmp byte [rel str_level], 0 ; log lvl none = skip je %%end %%log: PRINT_TIMESTAMP - PRINTF 2, log_prefix_err, log_prefix_err_len + PRINTF 2, str_prefix_err, str_prefix_err_len PRINTF 2, %1, %2 PRINTF 2, sysutils_newline, 1 @@ -336,16 +130,16 @@ section .bss ; Clobbers: rax, rdi, rsi, rdx, rcx %macro LOG_DEBUG 2 ; check if we should log or not - cmp byte [rel log_level], 2 ; log lvl none = skip + cmp byte [rel str_level], 2 ; log lvl none = skip jne %%end %%log: - PRINTF 2, log_prefix_dbg, log_prefix_dbg_len + PRINTF 2, str_prefix_dbg, str_prefix_dbg_len STRLEN current_pid_str, rcx PRINTF 2, current_pid_str, rcx - PRINTF 2, log_two_dots, log_two_dots_len - PRINTF 2, log_space, log_space_len + PRINTF 2, str_two_dots, str_two_dots_len + PRINTF 2, str_space, str_space_len PRINTF 2, %1, %2 PRINTF 2, sysutils_newline, 1 @@ -361,20 +155,20 @@ section .bss ; Clobbers: rax, rbx, rdi, rsi, rdx, rcx, r9 %macro LOG_PORT 0 ; check if we should log or not - cmp byte [rel log_level], 0 ; log lvl none = skip + cmp byte [rel str_level], 0 ; log lvl none = skip je %%end %%log: ; this mess prints the port log PRINT_TIMESTAMP - PRINT log_prefix_info, log_prefix_info_len - PRINT log_listening_on, log_listening_on_len + PRINT str_prefix_info, str_prefix_info_len + PRINT str_listening_on, str_listening_on_len STRLEN bind_addr_str, r9 PRINT bind_addr_str, r9 ; x.x.x.x - PRINT log_two_dots, log_two_dots_len ; ":" + PRINT str_two_dots, str_two_dots_len ; ":" ; port int to ascii movzx rbx, word [rel port] @@ -403,10 +197,10 @@ section .bss %macro LOG_REQUEST_CLFE 1 ; check if we should log or not - cmp qword [rel log_file], 1 + cmp qword [rel str_file], 1 jne %%pt1 ; log to file = log - cmp byte [rel log_level], 0 ; not to file + log lvl none = skip + cmp byte [rel str_level], 0 ; not to file + log lvl none = skip je %%end @@ -418,12 +212,12 @@ section .bss lea r10, [rel real_ip] STRLEN r10, rcx APPEND r8, r10, rcx - APPEND r8, log_space, log_space_len + APPEND r8, str_space, str_space_len %%pt2: ; pt. 2: identity, not supported APPEND r8, clfe_missing, clfe_missing_len - APPEND r8, log_space, log_space_len + APPEND r8, str_space, str_space_len %%pt3: ; pt. 3: auth @@ -434,13 +228,13 @@ section .bss je %%no_auth APPEND r8, r10, rcx - APPEND r8, log_space, log_space_len + APPEND r8, str_space, str_space_len jmp %%pt4 %%no_auth: APPEND r8, clfe_missing, clfe_missing_len - APPEND r8, log_space, log_space_len + APPEND r8, str_space, str_space_len %%pt4: ; pt. 4: timestamp @@ -473,10 +267,10 @@ section .bss APPEND r8, rs_buf, rcx APPEND r8, clfe_end_ts, clfe_end_ts_len - APPEND r8, log_space, log_space_len + APPEND r8, str_space, str_space_len %%pt5: - APPEND r8, log_quotation_mark, log_quotation_mark_len + APPEND r8, str_quotation_mark, str_quotation_mark_len lea r10, [rel request] xor r9, r9 @@ -502,8 +296,8 @@ section .bss %%req_print: APPEND r8, r10, r9 - APPEND r8, log_quotation_mark, log_quotation_mark_len - APPEND r8, log_space, log_space_len + APPEND r8, str_quotation_mark, str_quotation_mark_len + APPEND r8, str_space, str_space_len %%pt6: ; pt. 6: status code @@ -513,7 +307,7 @@ section .bss ITOA r10, status_buf, r9 APPEND r8, status_buf, r9 - APPEND r8, log_space, log_space_len + APPEND r8, str_space, str_space_len %%pt7: ; pt. 7: size @@ -523,17 +317,17 @@ section .bss je %%no_len APPEND r8, itoa_buf, rcx - APPEND r8, log_space, log_space_len + APPEND r8, str_space, str_space_len jmp %%pt8 %%no_len: APPEND r8, clfe_nobytes, clfe_nobytes_len - APPEND r8, log_space, log_space_len + APPEND r8, str_space, str_space_len %%pt8: ; pt. 8: "referer" - APPEND r8, log_quotation_mark, log_quotation_mark_len + APPEND r8, str_quotation_mark, str_quotation_mark_len STRLEN referer, rcx @@ -541,19 +335,19 @@ section .bss je %%no_referer APPEND r8, referer, rcx - APPEND r8, log_quotation_mark, log_quotation_mark_len - APPEND r8, log_space, log_space_len + APPEND r8, str_quotation_mark, str_quotation_mark_len + APPEND r8, str_space, str_space_len jmp %%pt9 %%no_referer: APPEND r8, clfe_missing, clfe_missing_len - APPEND r8, log_quotation_mark, log_quotation_mark_len - APPEND r8, log_space, log_space_len + APPEND r8, str_quotation_mark, str_quotation_mark_len + APPEND r8, str_space, str_space_len %%pt9: ; pt. 9: user agent - APPEND r8, log_quotation_mark, log_quotation_mark_len + APPEND r8, str_quotation_mark, str_quotation_mark_len STRLEN user_agent, rcx @@ -561,13 +355,13 @@ section .bss je %%no_ua APPEND r8, user_agent, rcx - APPEND r8, log_quotation_mark, log_quotation_mark_len + APPEND r8, str_quotation_mark, str_quotation_mark_len jmp %%done %%no_ua: APPEND r8, clfe_missing, clfe_missing_len - APPEND r8, log_quotation_mark, log_quotation_mark_len + APPEND r8, str_quotation_mark, str_quotation_mark_len %%done: APPEND r8, sysutils_newline, 1 diff --git a/program.asm b/program.asm index 53bc4d0..6504a70 100644 --- a/program.asm +++ b/program.asm @@ -1,5 +1,7 @@ ; program.asm - HTTP/1.0 server entry point +%include "./labels/strings.asm" + %include "./macros/envutils.asm" %include "./macros/fileutils.asm" %include "./macros/httputils.asm" @@ -113,11 +115,11 @@ _start: call pre_serve - cmp byte [rel log_level], 0 + cmp byte [rel str_level], 0 je .start_server ; skip the log if log lvl is none LF - PRINTN log_started_nasmserver, log_started_nasmserver_len + PRINTN str_started_nasmserver, str_started_nasmserver_len .start_server: ; start listening for incoming connections @@ -171,7 +173,7 @@ _start: mov rdi, r14 syscall - LOG_WARNING log_too_many_concurrent, log_too_many_concurrent_len + LOG_WARNING str_too_many_concurrent, str_too_many_concurrent_len jmp .wait @@ -255,13 +257,13 @@ _start: jmp .forbidden ; in case i add a new code and forgot to implement it here .get: - LOG_DEBUG log_method_get, log_method_get_len + LOG_DEBUG str_method_get, str_method_get_len mov byte [rel request_type], 0 jmp .auth_check .head: - LOG_DEBUG log_method_head, log_method_head_len + LOG_DEBUG str_method_head, str_method_head_len mov byte [rel request_type], 1 @@ -575,9 +577,9 @@ _start: AAPPEND r12, crlf AAPPEND r12, www_authenticate_header ; [...] Realm= - AAPPEND r12, log_quotation_mark ; " + AAPPEND r12, str_quotation_mark ; " AAPPEND r12, auth_realm ; Config realm name - AAPPEND r12, log_quotation_mark ; " + AAPPEND r12, str_quotation_mark ; " AAPPEND r12, crlf jmp .header_date @@ -760,7 +762,7 @@ _start: mov rdi, r14 syscall - call .log_request + call .str_request call dbg_child_exit @@ -803,32 +805,32 @@ _start: .reap_done: ret ; return point for .reap_loop -.log_request: +.str_request: ; parse other headers for the logs PARSE_UA_HEADER request, 8192, user_agent, 1024 PARSE_REFERER_HEADER request, 8192, referer, 1024 cmp byte [rel use_xri], 1 - jne .log_req ; check if we need to use the X-Real-IP header + jne .str_req ; check if we need to use the X-Real-IP header PARSE_XRI_HEADER request, 8192, real_ip, 39 cmp byte [rel real_ip], 0 - jne .log_req + jne .str_req mov rsi, client_ip_str mov rdi, real_ip mov rcx, 16 rep movsb -.log_req: - mov r15, qword [rel log_file] +.str_req: + mov r15, qword [rel str_file] LOG_REQUEST_CLFE r15 ret .shutdown: - LOG_INFO log_stopping, log_stopping_len + LOG_INFO str_stopping, str_stopping_len ; wait for all children to finish call .reap_loop @@ -841,5 +843,5 @@ _start: EXIT 0 .fail_accept: - LOG_ERR log_fail_accept, log_fail_accept_len + LOG_ERR str_fail_accept, str_fail_accept_len jmp .wait ; child exits From 367883721d76ac7c04574d3bd969e705fd428576 Mon Sep 17 00:00:00 2001 From: douxxtech Date: Sun, 14 Jun 2026 23:50:41 +0200 Subject: [PATCH 2/3] moved stuff to bss --- macros/sysutils.asm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/macros/sysutils.asm b/macros/sysutils.asm index 622036b..4521e61 100644 --- a/macros/sysutils.asm +++ b/macros/sysutils.asm @@ -2,11 +2,12 @@ section .data sysutils_newline db 0xa + sysutils_ts_fmt db "%H:%M:%S", 0 ; strftime format - sysutils_ts_fmt db "%H:%M:%S", 0 ; strftime format - sysutils_ts_buf db 0, 0, 0, 0, 0, 0, 0, 0, 0 ; "HH:MM:SS\0" - sysutils_timespec dq 0, 0 ; tv_sec, tv_nsec - sysutils_tm_buf times 64 db 0 ; struct tm +section .bss + sysutils_ts_buf resb 9 + sysutils_timespec resq 2 + sysutils_tm_buf resb 64 ; PRINT buffer, length ; Writes a buffer to stdout. From 99c90403dd5aa76265e3a6c33717c8d7194ce48b Mon Sep 17 00:00:00 2001 From: douxxtech Date: Sun, 14 Jun 2026 23:51:50 +0200 Subject: [PATCH 3/3] fixed formatting --- macros/logutils.asm | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/macros/logutils.asm b/macros/logutils.asm index 65fa63c..ad0796f 100644 --- a/macros/logutils.asm +++ b/macros/logutils.asm @@ -4,22 +4,22 @@ extern localtime_r extern strftime section .data - ts_fmt db "%H:%M:%S ", 0 ; trailing space included - timespec dq 0, 0 ; tv_sec, tv_nsec (struct timespec) + ts_fmt db "%H:%M:%S ", 0 ; trailing space included + timespec dq 0, 0 ; tv_sec, tv_nsec (struct timespec) - rs_fmt db "%d/%b/%Y:%H:%M:%S %z", 0 + rs_fmt db "%d/%b/%Y:%H:%M:%S %z", 0 - str_prefix_info db "[INFO] ", 0 - str_prefix_info_len equ $ - str_prefix_info - 1 + str_prefix_info db "[INFO] ", 0 + str_prefix_info_len equ $ - str_prefix_info - 1 - str_prefix_warning db "[WARNING] ", 0 - str_prefix_warning_len equ $ - str_prefix_warning - 1 + str_prefix_warning db "[WARNING] ", 0 + str_prefix_warning_len equ $ - str_prefix_warning - 1 - str_prefix_err db "[ERROR] ", 0 - str_prefix_err_len equ $ - str_prefix_err - 1 + str_prefix_err db "[ERROR] ", 0 + str_prefix_err_len equ $ - str_prefix_err - 1 - str_prefix_dbg db "* ", 0 - str_prefix_dbg_len equ $ - str_prefix_dbg - 1 + str_prefix_dbg db "* ", 0 + str_prefix_dbg_len equ $ - str_prefix_dbg - 1 section .bss