• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Virtual machine Management Terminal User Interface


Commit MetaInfo

修订版ff22ffee441b73747ecf7b6646aea23d5226069e (tree)
时间2023-04-02 21:42:16
作者Koine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Log Message

WorkBackuup

更改概述

差异

--- a/src/config.h
+++ b/src/config.h
@@ -40,6 +40,7 @@
4040 #define SHELL_DEFAULT_PATH_LEN 7
4141 #define OPENSSH_DEFAULT_PATH "/usr/bin/ssh"
4242 #define SUDO_DEFAULT_PATH "/usr/local/bin/sudo"
43+#define SUDO_DEFAULT_PATH_LEN 19
4344 #define VNCVIEWER_DEFAULT_PATH "/usr/local/bin/vncviewer"
4445 #define XTERMINAL_DEFAULT_PATH "/usr/local/bin/xterm"
4546 #define VMBHYVE_DEFAULT_PATH "/usr/local/sbin/vm"
--- a/src/hvctl.c
+++ b/src/hvctl.c
@@ -47,11 +47,11 @@ int
4747 i_len = snprintf( p_hvcon->sudo.str_cmdline, VMTUI_SUDO_MAXLEN_CMDLINE,
4848 "echo %s | sudo -S -p \"\" %s ",
4949 p_hvisor->sudo.str_password,
50- p_hvisor->sudo.str_option );
50+ p_hvisor->sudo.option.str_option );
5151 }
5252 else {
5353 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 );
5555 }
5656
5757 p_hvcon->sudo.sz_len = (size_t)i_len;
@@ -371,8 +371,10 @@ int
371371 p_hvisor->sudo.path.i_len = strnlen( pstr_path, VMTUI_CMDINFO_MAXLEN_PATH );
372372 strncpy( p_hvisor->sudo.path.str_path, pstr_path, VMTUI_CMDINFO_MAXLEN_PATH );
373373 }
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+ }
376378 if( NULL != pstr_password )
377379 { strncpy( p_hvisor->sudo.str_password, pstr_password, VMTUI_SUDO_MAXLEN_PASSWORD ); }
378380
--- a/src/localexec.c
+++ b/src/localexec.c
@@ -467,8 +467,9 @@ int
467467
468468 gt_local_sudo.t_sudo.path.i_len = strnlen( SUDO_DEFAULT_PATH, VMTUI_CMDINFO_MAXLEN_PATH - 1 );
469469 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';
472473 //gt_local_sudo.t_cmd.sz_len = 0;
473474 //gt_local_sudo.t_cmd.str_cmdline[0] = '\0';
474475
--- a/src/settingfile.c
+++ b/src/settingfile.c
@@ -269,8 +269,16 @@ int
269269 }
270270 }
271271 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+ }
274282 }
275283 else if( !strncmp( pstr_key, SETFILE_KEY_GLOBAL_SUDO_PASSWORD, i_keylen )) {
276284 strncpy( gt_local_sudo.t_sudo.str_password, pstr_val, VMTUI_SUDO_MAXLEN_PASSWORD );
@@ -402,8 +410,12 @@ int
402410 }
403411
404412 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+ }
407419 }
408420
409421 else if( !strncmp( pstr_key, SETFILE_KEY_SERVER_SUDO_PASSWORD, i_keylen )) {
@@ -420,17 +432,6 @@ int
420432 }
421433 }
422434
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-
434435 return i_ret;
435436 }
436437
@@ -501,7 +502,7 @@ int
501502 i_err = HvCtl_SetSudoInfo(
502503 i_hvisor,
503504 p_hvtmp->sudo.path.str_path,
504- p_hvtmp->sudo.str_option,
505+ p_hvtmp->sudo.option.str_option,
505506 p_hvtmp->sudo.str_password );
506507 if( 0x00 != i_err ) {
507508 ErrInfo_Warn( "Can't Regist HVisor Sudo Info.",
@@ -554,8 +555,10 @@ int
554555 gt_local_sudo.t_sudo.path.i_len = p_hvisor->sudo.path.i_len;
555556 strncpy( gt_local_sudo.t_sudo.path.str_path,
556557 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 );
559562
560563 if( HVISOR_OPTION_SUDO_PASSWORD & p_hvisor->dw_option ) {
561564 gt_local_sudo.b_flag |= LOCALEXEC_SUDO_FLAG_USEPASSWORD;
--- a/src/test_settingfile.c
+++ b/src/test_settingfile.c
@@ -113,7 +113,7 @@ void
113113 gt_xterminal.option.i_len = 0;
114114
115115 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';
117117 gt_local_sudo.t_sudo.str_password[0] = '\0';
118118
119119 SettingFile_SetSettingFilePath( "./testfile", "test_vmtui.conf" );
@@ -144,7 +144,8 @@ void
144144 CU_ASSERT( gt_local_sudo.b_flag & LOCALEXEC_SUDO_FLAG_USEPASSWORD );
145145 CU_ASSERT( gt_local_sudo.t_sudo.path.i_len == 13 );
146146 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" );
148149 CU_ASSERT_STRING_EQUAL( gt_local_sudo.t_sudo.str_password, "testpass" );
149150
150151 // Test HyperVisor Section ====
@@ -168,8 +169,10 @@ void
168169 CU_ASSERT( p_hvisor->sshcmd.option.i_len == 0 );
169170 CU_ASSERT_STRING_EQUAL( p_hvisor->sshcmd.option.str_option, "" );
170171
172+ CU_ASSERT( p_hvisor->sudo.path.i_len == 0 );
171173 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, "" );
173176 CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.str_password, "" );
174177
175178 CU_ASSERT( p_hvisor->dw_type == (HVISOR_TYPE_BHYVE_DIRECTBHYVE) );
@@ -200,8 +203,10 @@ void
200203 CU_ASSERT( p_hvisor->dw_option & HVISOR_OPTION_SUDO );
201204 CU_ASSERT( p_hvisor->dw_option & HVISOR_OPTION_SUDO_PASSWORD );
202205
206+ CU_ASSERT( p_hvisor->sudo.path.i_len == 10 );
203207 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" );
205210 CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.str_password, "password2" );
206211 i_cnt++;
207212 }
@@ -226,8 +231,10 @@ void
226231 CU_ASSERT( p_hvisor->dw_option & HVISOR_OPTION_SUDO );
227232 CU_ASSERT( ! (p_hvisor->dw_option & HVISOR_OPTION_SUDO_PASSWORD) );
228233
234+ CU_ASSERT( p_hvisor->sudo.path.i_len == SUDO_DEFAULT_PATH_LEN );
229235 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, "" );
231238 CU_ASSERT_STRING_EQUAL( p_hvisor->sudo.str_password, "" );
232239 i_cnt++;
233240 }
--- a/src/tuihvisor.c
+++ b/src/tuihvisor.c
@@ -232,9 +232,9 @@ int
232232 TextBuf_AppendLine( &lt_hvisor.t_textbuf, " sudo Command Settings", 0, NULL );
233233
234234 // sudo options -
235- if( '\0' != p_hvisor->sudo.str_option[0] ) {
235+ if( '\0' != p_hvisor->sudo.option.str_option[0] ) {
236236 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 );
238238 } else {
239239 snprintf( str_temp, sizeof( str_temp ), " %-20s: %-40s",
240240 "sudo option", "(no setting)" );
--- a/src/vmtui.h
+++ b/src/vmtui.h
@@ -92,12 +92,15 @@ typedef struct {
9292 #define VMTUI_SUDO_MAXLEN_PASSWORD 64
9393
9494 typedef struct {
95- char str_option[VMTUI_SUDO_MAXLEN_OPTION];
9695 char str_password[VMTUI_SUDO_MAXLEN_PASSWORD];
9796 struct {
9897 char str_path[VMTUI_CMDINFO_MAXLEN_PATH];
9998 int i_len;
10099 } path;
100+ struct {
101+ char str_option[VMTUI_CMDINFO_MAXLEN_OPTION];
102+ int i_len;
103+ } option;
101104 } SuDo_Info;
102105
103106 typedef struct {