Skip to content

Commit

Permalink
Merge pull request #1065 from openziti/add-identity-from-url-cert-key…
Browse files Browse the repository at this point in the history
…-PATH_MAX

FILENAME_MAX -> PATH_MAX
  • Loading branch information
dovholuknf authored Dec 11, 2024
2 parents 6d7450b + 077987f commit 8e12b50
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/ziti-tunnel-cbs/ziti_tunnel_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ static int update_file(const char *path, char *content, size_t content_len) {
CHECK_UV("check exiting config", uv_fs_stat(NULL, &fs_req, path, NULL));
uint64_t mode = fs_req.statbuf.st_mode;

char backup[FILENAME_MAX];
char backup[PATH_MAX];
snprintf(backup, sizeof(backup), "%s.bak", path);
CHECK_UV("create backup", uv_fs_rename(NULL, &fs_req, path, backup, NULL));

Expand Down
2 changes: 1 addition & 1 deletion programs/ziti-edge-tunnel/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ void set_identifier_from_identities() {
for(int idx = 0; tnl_status.Identities[idx]; idx++) {
tunnel_identity *tnl_id = tnl_status.Identities[idx];
if (tnl_id->Identifier == NULL && tnl_id->FingerPrint != NULL) {
char identifier[FILENAME_MAX];
char identifier[PATH_MAX];
snprintf(identifier, sizeof(identifier), "%s%c%s.json", config_dir, PATH_SEP, tnl_id->FingerPrint);
tnl_id->Identifier = strdup(identifier);
}
Expand Down
20 changes: 10 additions & 10 deletions programs/ziti-edge-tunnel/process_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ bool process_tunnel_commands(const tunnel_command *tnl_cmd, command_cb cb, void
break;
}

char new_identifier_without_ext[FILENAME_MAX] = {0};
char new_identifier_with_ext[FILENAME_MAX] = {0};
char new_identifier_path[FILENAME_MAX] = {0};
char new_identifier_without_ext[PATH_MAX] = {0};
char new_identifier_with_ext[PATH_MAX] = {0};
char new_identifier_path[PATH_MAX] = {0};
if(is_jwt) {
if (tunnel_add_identity_cmd.jwtFileName == NULL) {
result.error = "identity filename not provided";
Expand All @@ -312,15 +312,15 @@ bool process_tunnel_commands(const tunnel_command *tnl_cmd, command_cb cb, void
}

size_t length = len_without_extension(tunnel_add_identity_cmd.jwtFileName, ".jwt");
if ((strlen(config_file) + length + 6) > FILENAME_MAX - 1) {
ZITI_LOG(ERROR, "failed to create file %s%c%s.json, The length of the file name is longer than %d", config_file, PATH_SEP, tunnel_add_identity_cmd.jwtFileName, FILENAME_MAX);
if ((strlen(config_file) + length + 6) > PATH_MAX - 1) {
ZITI_LOG(ERROR, "failed to create file %s%c%s.json, The length of the file name is longer than %d", config_file, PATH_SEP, tunnel_add_identity_cmd.jwtFileName, PATH_MAX);
result.error = "invalid file name";
result.success = false;
free_tunnel_add_identity(&tunnel_add_identity_cmd);
break;
}
if (tunnel_add_identity_cmd.alias != NULL) {
snprintf(new_identifier_without_ext, FILENAME_MAX, "%s", tunnel_add_identity_cmd.alias);
snprintf(new_identifier_without_ext, PATH_MAX, "%s", tunnel_add_identity_cmd.alias);
} else {
strncpy(new_identifier_without_ext, tunnel_add_identity_cmd.jwtFileName, length);
}
Expand All @@ -337,18 +337,18 @@ bool process_tunnel_commands(const tunnel_command *tnl_cmd, command_cb cb, void
free_tunnel_add_identity(&tunnel_add_identity_cmd);
break;
}
snprintf(new_identifier_without_ext, FILENAME_MAX, "%s", tunnel_add_identity_cmd.alias);
snprintf(new_identifier_without_ext, PATH_MAX, "%s", tunnel_add_identity_cmd.alias);
} else if (is_url) {
snprintf(new_identifier_without_ext, FILENAME_MAX, "%s", tunnel_add_identity_cmd.alias);
snprintf(new_identifier_without_ext, PATH_MAX, "%s", tunnel_add_identity_cmd.alias);
} else {
result.error = "programming error. this case should not be hit. please file an issue";
result.success = false;
free_tunnel_add_identity(&tunnel_add_identity_cmd);
break;
}

snprintf(new_identifier_with_ext, FILENAME_MAX, "%s.json", new_identifier_without_ext);
snprintf(new_identifier_path, FILENAME_MAX, "%s%c%s", config_dir, PATH_SEP, new_identifier_with_ext);
snprintf(new_identifier_with_ext, PATH_MAX, "%s.json", new_identifier_without_ext);
snprintf(new_identifier_path, PATH_MAX, "%s%c%s", config_dir, PATH_SEP, new_identifier_with_ext);
normalize_identifier(new_identifier_path);

struct stat file_exists;
Expand Down
4 changes: 2 additions & 2 deletions programs/ziti-edge-tunnel/windows-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ VOID WINAPI SvcMain( DWORD dwArgc, LPTSTR *lpszArgv )

// Perform service-specific initialization and work.
char *appdata = getenv("APPDATA");
char* config_dir = calloc(FILENAME_MAX, sizeof(char));
snprintf(config_dir, FILENAME_MAX, "%s%cNetFoundry", appdata, PATH_SEP);
char* config_dir = calloc(PATH_MAX, sizeof(char));
snprintf(config_dir, PATH_MAX, "%s%cNetFoundry", appdata, PATH_SEP);
scm_service_init(config_dir);
free(config_dir);

Expand Down
22 changes: 11 additions & 11 deletions programs/ziti-edge-tunnel/windows/log_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#if _WIN32
#include <windows.h>
#define mkdir(path, mode) CreateDirectory(path, NULL)
#define realpath(rel, abs) _fullpath(abs, rel, FILENAME_MAX)
#define realpath(rel, abs) _fullpath(abs, rel, PATH_MAX)
#endif

static bool open_log(char* log_filename);
Expand All @@ -49,7 +49,7 @@ static const char* log_filename_base = "ziti-tunneler.log";
static int rotation_count = 7;

static uint8_t mkdir_p(const char *path) {
char actual_path[FILENAME_MAX];
char actual_path[PATH_MAX];
char *cur_path = realpath(path, actual_path);
char *p = cur_path;
struct stat info;
Expand All @@ -68,11 +68,11 @@ static uint8_t mkdir_p(const char *path) {
}

static char* get_log_path() {
char process_dir[FILENAME_MAX]; //create string buffer to hold path
char process_full_path[FILENAME_MAX];
char process_dir[PATH_MAX]; //create string buffer to hold path
char process_full_path[PATH_MAX];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
get_process_path(process_full_path, FILENAME_MAX);
get_process_path(process_full_path, PATH_MAX);
_splitpath_s(process_full_path, drive, sizeof(drive), dir, sizeof(dir), NULL, 0, NULL, 0);
_makepath_s(process_dir, sizeof(process_dir), drive, dir, NULL, NULL);

Expand All @@ -82,11 +82,11 @@ static char* get_log_path() {
exit(0);
}

char* log_path = calloc(FILENAME_MAX, sizeof(char));
char* log_path = calloc(PATH_MAX, sizeof(char));
if(process_dir[strlen(process_dir)-1] != PATH_SEP) {
snprintf(log_path, FILENAME_MAX, "%s%clogs%cservice", process_dir, PATH_SEP, PATH_SEP);
snprintf(log_path, PATH_MAX, "%s%clogs%cservice", process_dir, PATH_SEP, PATH_SEP);
} else {
snprintf(log_path, FILENAME_MAX, "%slogs%cservice", process_dir, PATH_SEP);
snprintf(log_path, PATH_MAX, "%slogs%cservice", process_dir, PATH_SEP);
}
mkdir_p(log_path);

Expand All @@ -100,8 +100,8 @@ static char* get_log_path() {

char* get_base_filename() {
char* log_path = get_log_path();
char* temp_log_filename = calloc(FILENAME_MAX, sizeof(char));
snprintf(temp_log_filename, FILENAME_MAX, "%s%c%s", log_path, PATH_SEP, log_filename_base);
char* temp_log_filename = calloc(PATH_MAX, sizeof(char));
snprintf(temp_log_filename, PATH_MAX, "%s%c%s", log_path, PATH_SEP, log_filename_base);
free(log_path);
return temp_log_filename;
}
Expand All @@ -112,7 +112,7 @@ static char* create_log_filename() {
char time_val[32];
strftime(time_val, sizeof(time_val), "%Y%m%d0000", start_time);

char* temp_log_filename = calloc(FILENAME_MAX, sizeof(char));
char* temp_log_filename = calloc(PATH_MAX, sizeof(char));
sprintf(temp_log_filename, "%s.%s.log", base_log_filename, time_val);
free(base_log_filename);
return temp_log_filename;
Expand Down
20 changes: 10 additions & 10 deletions programs/ziti-edge-tunnel/ziti-edge-tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static tunneler_context initialize_tunneler(netif_driver tun, uv_loop_t* ziti_lo
#if _WIN32
static void move_config_from_previous_windows_backup(uv_loop_t *loop);
#define LAST_CHAR_IPC_CMD '\n'
#define realpath(rel, abs) _fullpath(abs, rel, FILENAME_MAX)
#define realpath(rel, abs) _fullpath(abs, rel, PATH_MAX)
#else
#define LAST_CHAR_IPC_CMD '\0'
#endif
Expand Down Expand Up @@ -1338,9 +1338,9 @@ static void run(int argc, char *argv[]) {
return;
}
if(config_file == NULL) {
config_file = calloc(FILENAME_MAX + 1, sizeof(char));
config_file = calloc(PATH_MAX + 1, sizeof(char));
}
snprintf(config_file, FILENAME_MAX - 1, "%s%c%s", config_dir, PATH_SEP, "config.json");
snprintf(config_file, PATH_MAX - 1, "%s%c%s", config_dir, PATH_SEP, "config.json");
normalize_identifier(config_file);

load_tunnel_status_from_file(global_loop_ref, config_file);
Expand Down Expand Up @@ -2608,8 +2608,8 @@ void scm_service_init(char *config_path) {
log_init(global_loop_ref, INFO, ziti_log_writer);
started_by_scm = true;
if (config_path != NULL) {
config_dir = calloc(FILENAME_MAX, sizeof(char));
strncpy_s(config_dir, FILENAME_MAX - 1, config_path, FILENAME_MAX - 1);
config_dir = calloc(PATH_MAX, sizeof(char));
strncpy_s(config_dir, PATH_MAX - 1, config_path, PATH_MAX - 1);
}
}

Expand Down Expand Up @@ -2669,7 +2669,7 @@ static void move_config_from_previous_windows_backup(uv_loop_t *loop) {
char* system_drive = getenv("SystemDrive");

for (int i =0; backup_folders[i]; i++) {
char* config_dir_bkp = calloc(FILENAME_MAX, sizeof(char));
char* config_dir_bkp = calloc(PATH_MAX, sizeof(char));
sprintf(config_dir_bkp, "%s\\%s", system_drive, backup_folders[i]);
uv_fs_t fs;
int rc = uv_fs_access(loop, &fs, config_dir_bkp, 0, NULL);
Expand All @@ -2691,10 +2691,10 @@ static void move_config_from_previous_windows_backup(uv_loop_t *loop) {
uv_dirent_t file;
while (uv_fs_scandir_next(&fs, &file) == 0) {
if (file.type == UV_DIRENT_FILE) {
char old_file[FILENAME_MAX];
snprintf(old_file, FILENAME_MAX, "%s\\%s", config_dir_bkp, file.name);
char new_file[FILENAME_MAX];
snprintf(new_file, FILENAME_MAX, "%s\\%s", config_dir, file.name);
char old_file[PATH_MAX];
snprintf(old_file, PATH_MAX, "%s\\%s", config_dir_bkp, file.name);
char new_file[PATH_MAX];
snprintf(new_file, PATH_MAX, "%s\\%s", config_dir, file.name);
uv_fs_t fs_cpy;
rc = uv_fs_copyfile(loop, &fs_cpy, old_file, new_file, 0, NULL);
if (rc == 0) {
Expand Down

0 comments on commit 8e12b50

Please sign in to comment.