Virtual machine Management Terminal User Interface
修订版 | ff22ffee441b73747ecf7b6646aea23d5226069e (tree) |
---|---|
时间 | 2023-04-02 21:42:16 |
作者 | Koine Yuusuke(koinec) <koinec@user...> |
Commiter | Koine Yuusuke(koinec) |
WorkBackuup
@@ -40,6 +40,7 @@ | ||
40 | 40 | #define SHELL_DEFAULT_PATH_LEN 7 |
41 | 41 | #define OPENSSH_DEFAULT_PATH "/usr/bin/ssh" |
42 | 42 | #define SUDO_DEFAULT_PATH "/usr/local/bin/sudo" |
43 | +#define SUDO_DEFAULT_PATH_LEN 19 | |
43 | 44 | #define VNCVIEWER_DEFAULT_PATH "/usr/local/bin/vncviewer" |
44 | 45 | #define XTERMINAL_DEFAULT_PATH "/usr/local/bin/xterm" |
45 | 46 | #define VMBHYVE_DEFAULT_PATH "/usr/local/sbin/vm" |
@@ -47,11 +47,11 @@ int | ||
47 | 47 | i_len = snprintf( p_hvcon->sudo.str_cmdline, VMTUI_SUDO_MAXLEN_CMDLINE, |
48 | 48 | "echo %s | sudo -S -p \"\" %s ", |
49 | 49 | p_hvisor->sudo.str_password, |
50 | - p_hvisor->sudo.str_option ); | |
50 | + p_hvisor->sudo.option.str_option ); | |
51 | 51 | } |
52 | 52 | else { |
53 | 53 | i_len = snprintf( p_hvcon->sudo.str_cmdline, VMTUI_SUDO_MAXLEN_CMDLINE, |
54 | - "sudo %s ", p_hvisor->sudo.str_option ); | |
54 | + "sudo %s ", p_hvisor->sudo.option.str_option ); | |
55 | 55 | } |
56 | 56 | |
57 | 57 | p_hvcon->sudo.sz_len = (size_t)i_len; |
@@ -371,8 +371,10 @@ int | ||
371 | 371 | p_hvisor->sudo.path.i_len = strnlen( pstr_path, VMTUI_CMDINFO_MAXLEN_PATH ); |
372 | 372 | strncpy( p_hvisor->sudo.path.str_path, pstr_path, VMTUI_CMDINFO_MAXLEN_PATH ); |
373 | 373 | } |
374 | - if( NULL != pstr_option ) | |
375 | - { strncpy( p_hvisor->sudo.str_option, pstr_option, VMTUI_SUDO_MAXLEN_OPTION ); } | |
374 | + if( NULL != pstr_option ) { | |
375 | + p_hvisor->sudo.option.i_len = strnlen( pstr_option, VMTUI_CMDINFO_MAXLEN_OPTION ); | |
376 | + strncpy( p_hvisor->sudo.option.str_option, pstr_option, VMTUI_CMDINFO_MAXLEN_OPTION ); | |
377 | + } | |
376 | 378 | if( NULL != pstr_password ) |
377 | 379 | { strncpy( p_hvisor->sudo.str_password, pstr_password, VMTUI_SUDO_MAXLEN_PASSWORD ); } |
378 | 380 |
@@ -467,8 +467,9 @@ int | ||
467 | 467 | |
468 | 468 | gt_local_sudo.t_sudo.path.i_len = strnlen( SUDO_DEFAULT_PATH, VMTUI_CMDINFO_MAXLEN_PATH - 1 ); |
469 | 469 | strncpy( gt_local_sudo.t_sudo.path.str_path, SUDO_DEFAULT_PATH, VMTUI_CMDINFO_MAXLEN_PATH ); |
470 | - gt_local_sudo.t_sudo.str_password[0] = '\0'; | |
471 | - gt_local_sudo.t_sudo.str_option[0] = '\0'; | |
470 | + gt_local_sudo.t_sudo.str_password[0] = '\0'; | |
471 | + gt_local_sudo.t_sudo.option.i_len = 0; | |
472 | + gt_local_sudo.t_sudo.option.str_option[0] = '\0'; | |
472 | 473 | //gt_local_sudo.t_cmd.sz_len = 0; |
473 | 474 | //gt_local_sudo.t_cmd.str_cmdline[0] = '\0'; |
474 | 475 |
@@ -269,8 +269,16 @@ int | ||
269 | 269 | } |
270 | 270 | } |
271 | 271 | else if( !strncmp( pstr_key, SETFILE_KEY_GLOBAL_SUDO_OPTION, i_keylen )) { |
272 | - strncpy( gt_local_sudo.t_sudo.str_option, pstr_val, VMTUI_SUDO_MAXLEN_OPTION ); | |
273 | - i_ret++; | |
272 | + i_len = strnlen( pstr_val, VMTUI_CMDINFO_MAXLEN_OPTION ); | |
273 | + if( i_len < VMTUI_CMDINFO_MAXLEN_OPTION ) { | |
274 | + gt_local_sudo.t_sudo.option.i_len = i_len; | |
275 | + strncpy( gt_local_sudo.t_sudo.option.str_option, pstr_val, VMTUI_CMDINFO_MAXLEN_OPTION ); | |
276 | + i_ret++; | |
277 | + } | |
278 | + else { | |
279 | + ErrInfo_Warn( "Can't set sudo command option because of over length.", | |
280 | + 0x00, 0x00, 0x00, 0x00, i_len, 0x00, pstr_val ); | |
281 | + } | |
274 | 282 | } |
275 | 283 | else if( !strncmp( pstr_key, SETFILE_KEY_GLOBAL_SUDO_PASSWORD, i_keylen )) { |
276 | 284 | strncpy( gt_local_sudo.t_sudo.str_password, pstr_val, VMTUI_SUDO_MAXLEN_PASSWORD ); |
@@ -402,8 +410,12 @@ int | ||
402 | 410 | } |
403 | 411 | |
404 | 412 | else if( !strncmp( pstr_key, SETFILE_KEY_SERVER_SUDO_OPTION, i_keylen )) { |
405 | - strncpy( p_hvtmp->sudo.str_option, pstr_val, VMTUI_SUDO_MAXLEN_OPTION ); | |
406 | - i_ret++; | |
413 | + i_len = strnlen( pstr_val, VMTUI_CMDINFO_MAXLEN_OPTION ); | |
414 | + if( i_len < VMTUI_CMDINFO_MAXLEN_OPTION ) { | |
415 | + strncpy( p_hvtmp->sudo.option.str_option, pstr_val, VMTUI_CMDINFO_MAXLEN_OPTION ); | |
416 | + p_hvtmp->sudo.option.i_len = i_len; | |
417 | + i_ret++; | |
418 | + } | |
407 | 419 | } |
408 | 420 | |
409 | 421 | else if( !strncmp( pstr_key, SETFILE_KEY_SERVER_SUDO_PASSWORD, i_keylen )) { |
@@ -420,17 +432,6 @@ int | ||
420 | 432 | } |
421 | 433 | } |
422 | 434 | |
423 | - /* | |
424 | - else if( !strncmp( pstr_key, SETFILE_KEY_SERVER_SSH_CMDOPTION, i_keylen )) { | |
425 | - i_len = strnlen( pstr_val, VMTUI_CMDINFO_MAXLEN_OPTION ); | |
426 | - if( i_len < VMTUI_CMDINFO_MAXLEN_OPTION ) { | |
427 | - strncpy( p_hvtmp->sshcmd.option.str_option, pstr_val, VMTUI_CMDINFO_MAXLEN_OPTION ); | |
428 | - p_hvtmp->sshcmd.option.i_len = i_len; | |
429 | - i_ret++; | |
430 | - } | |
431 | - } | |
432 | - */ | |
433 | - | |
434 | 435 | return i_ret; |
435 | 436 | } |
436 | 437 |
@@ -501,7 +502,7 @@ int | ||
501 | 502 | i_err = HvCtl_SetSudoInfo( |
502 | 503 | i_hvisor, |
503 | 504 | p_hvtmp->sudo.path.str_path, |
504 | - p_hvtmp->sudo.str_option, | |
505 | + p_hvtmp->sudo.option.str_option, | |
505 | 506 | p_hvtmp->sudo.str_password ); |
506 | 507 | if( 0x00 != i_err ) { |
507 | 508 | ErrInfo_Warn( "Can't Regist HVisor Sudo Info.", |
@@ -554,8 +555,10 @@ int | ||
554 | 555 | gt_local_sudo.t_sudo.path.i_len = p_hvisor->sudo.path.i_len; |
555 | 556 | strncpy( gt_local_sudo.t_sudo.path.str_path, |
556 | 557 | p_hvisor->sudo.path.str_path, VMTUI_CMDINFO_MAXLEN_PATH ); |
557 | - strncpy( gt_local_sudo.t_sudo.str_option, | |
558 | - p_hvisor->sudo.str_option, VMTUI_SUDO_MAXLEN_OPTION ); | |
558 | + | |
559 | + gt_local_sudo.t_sudo.option.i_len = p_hvisor->sudo.option.i_len; | |
560 | + strncpy( gt_local_sudo.t_sudo.option.str_option, | |
561 | + p_hvisor->sudo.option.str_option, VMTUI_SUDO_MAXLEN_OPTION ); | |
559 | 562 | |
560 | 563 | if( HVISOR_OPTION_SUDO_PASSWORD & p_hvisor->dw_option ) { |
561 | 564 | gt_local_sudo.b_flag |= LOCALEXEC_SUDO_FLAG_USEPASSWORD; |
@@ -113,7 +113,7 @@ void | ||
113 | 113 | gt_xterminal.option.i_len = 0; |
114 | 114 | |
115 | 115 | gt_local_sudo.b_flag = LOCALEXEC_SUDO_FLAG_NONE; |
116 | - gt_local_sudo.t_sudo.str_option[0] = '\0'; | |
116 | + gt_local_sudo.t_sudo.option.str_option[0] = '\0'; | |
117 | 117 | gt_local_sudo.t_sudo.str_password[0] = '\0'; |
118 | 118 | |
119 | 119 | SettingFile_SetSettingFilePath( "./testfile", "test_vmtui.conf" ); |
@@ -144,7 +144,8 @@ void | ||
144 | 144 | CU_ASSERT( gt_local_sudo.b_flag & LOCALEXEC_SUDO_FLAG_USEPASSWORD ); |
145 | 145 | CU_ASSERT( gt_local_sudo.t_sudo.path.i_len == 13 ); |
146 | 146 | CU_ASSERT_STRING_EQUAL( gt_local_sudo.t_sudo.path.str_path, "/usr/bin/sudo" ); |
147 | - CU_ASSERT_STRING_EQUAL( gt_local_sudo.t_sudo.str_option, "-opt3" ); | |
147 | + CU_ASSERT( gt_local_sudo.t_sudo.option.i_len == 5 ); | |
148 | + CU_ASSERT_STRING_EQUAL( gt_local_sudo.t_sudo.option.str_option, "-opt3" ); | |
148 | 149 | CU_ASSERT_STRING_EQUAL( gt_local_sudo.t_sudo.str_password, "testpass" ); |
149 | 150 | |
150 | 151 | // Test HyperVisor Section ==== |
@@ -168,8 +169,10 @@ void | ||
168 | 169 | CU_ASSERT( p_hvisor->sshcmd.option.i_len == 0 ); |
169 | 170 | CU_ASSERT_STRING_EQUAL( p_hvisor->sshcmd.option.str_option, "" ); |
170 | 171 | |
172 | + CU_ASSERT( p_hvisor->sudo.path.i_len == 0 ); | |
171 | 173 | CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.path.str_path, "" ); |
172 | - CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.str_option, "" ); | |
174 | + CU_ASSERT( p_hvisor->sudo.option.i_len == 0 ); | |
175 | + CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.option.str_option, "" ); | |
173 | 176 | CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.str_password, "" ); |
174 | 177 | |
175 | 178 | CU_ASSERT( p_hvisor->dw_type == (HVISOR_TYPE_BHYVE_DIRECTBHYVE) ); |
@@ -200,8 +203,10 @@ void | ||
200 | 203 | CU_ASSERT( p_hvisor->dw_option & HVISOR_OPTION_SUDO ); |
201 | 204 | CU_ASSERT( p_hvisor->dw_option & HVISOR_OPTION_SUDO_PASSWORD ); |
202 | 205 | |
206 | + CU_ASSERT( p_hvisor->sudo.path.i_len == 10 ); | |
203 | 207 | CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.path.str_path, "/test/sudo" ); |
204 | - CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.str_option, "-a -b" ); | |
208 | + CU_ASSERT( p_hvisor->sudo.option.i_len == 5 ); | |
209 | + CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.option.str_option, "-a -b" ); | |
205 | 210 | CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.str_password, "password2" ); |
206 | 211 | i_cnt++; |
207 | 212 | } |
@@ -226,8 +231,10 @@ void | ||
226 | 231 | CU_ASSERT( p_hvisor->dw_option & HVISOR_OPTION_SUDO ); |
227 | 232 | CU_ASSERT( ! (p_hvisor->dw_option & HVISOR_OPTION_SUDO_PASSWORD) ); |
228 | 233 | |
234 | + CU_ASSERT( p_hvisor->sudo.path.i_len == SUDO_DEFAULT_PATH_LEN ); | |
229 | 235 | CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.path.str_path, SUDO_DEFAULT_PATH ); |
230 | - CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.str_option, "" ); | |
236 | + CU_ASSERT( p_hvisor->sudo.option.i_len == 0 ); | |
237 | + CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.option.str_option, "" ); | |
231 | 238 | CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.str_password, "" ); |
232 | 239 | i_cnt++; |
233 | 240 | } |
@@ -232,9 +232,9 @@ int | ||
232 | 232 | TextBuf_AppendLine( <_hvisor.t_textbuf, " sudo Command Settings", 0, NULL ); |
233 | 233 | |
234 | 234 | // sudo options - |
235 | - if( '\0' != p_hvisor->sudo.str_option[0] ) { | |
235 | + if( '\0' != p_hvisor->sudo.option.str_option[0] ) { | |
236 | 236 | snprintf( str_temp, sizeof( str_temp ), " %-20s: %-40s", |
237 | - "sudo option", p_hvisor->sudo.str_option ); | |
237 | + "sudo option", p_hvisor->sudo.option.str_option ); | |
238 | 238 | } else { |
239 | 239 | snprintf( str_temp, sizeof( str_temp ), " %-20s: %-40s", |
240 | 240 | "sudo option", "(no setting)" ); |
@@ -92,12 +92,15 @@ typedef struct { | ||
92 | 92 | #define VMTUI_SUDO_MAXLEN_PASSWORD 64 |
93 | 93 | |
94 | 94 | typedef struct { |
95 | - char str_option[VMTUI_SUDO_MAXLEN_OPTION]; | |
96 | 95 | char str_password[VMTUI_SUDO_MAXLEN_PASSWORD]; |
97 | 96 | struct { |
98 | 97 | char str_path[VMTUI_CMDINFO_MAXLEN_PATH]; |
99 | 98 | int i_len; |
100 | 99 | } path; |
100 | + struct { | |
101 | + char str_option[VMTUI_CMDINFO_MAXLEN_OPTION]; | |
102 | + int i_len; | |
103 | + } option; | |
101 | 104 | } SuDo_Info; |
102 | 105 | |
103 | 106 | typedef struct { |