7272
7373static char opt_socket_path [SOCKET_PATH_LEN ] = "/tmp/.ydotool_socket" ;
7474static char opt_socket_perm [16 ] = "0600" ;
75+ static char opt_socket_own [16 ] = "" ;
7576
7677static void show_help () {
7778 puts (
@@ -80,7 +81,8 @@ static void show_help() {
8081 "\n"
8182 "Options:\n"
8283 " -p, --socket-path=PATH Custom socket path\n"
83- " -P, --socket-perm=PERM Socket permission\n"
84+ " -P, --socket-perm=PERM Socket permission (default 0600)\n"
85+ " -o, --socket-own=UID:GID Socket ownership\n"
8486 " -m, --mouse-off Disable mouse (EV_REL)\n"
8587 " -k, --keyboard-off Disable keyboard (EV_KEY)\n"
8688 " -T, --touch-on Enable touchscreen (EV_ABS)\n"
@@ -186,6 +188,7 @@ int main(int argc, char **argv) {
186188 {"help" , no_argument , 0 , 'h' },
187189 {"version" , no_argument , 0 , 'V' },
188190 {"socket-perm" , required_argument , 0 , 'P' },
191+ {"socket-own" , required_argument , 0 , 'o' },
189192 {"socket-path" , required_argument , 0 , 'p' },
190193 {"mouse-off" , no_argument , 0 , 'm' },
191194 {"keyboard-off" , no_argument , 0 , 'k' },
@@ -195,7 +198,7 @@ int main(int argc, char **argv) {
195198 /* getopt_long stores the option index here. */
196199 int option_index = 0 ;
197200
198- c = getopt_long (argc , argv , "hVp:P:mkT" ,
201+ c = getopt_long (argc , argv , "hVp:P:o: mkT" ,
199202 long_options , & option_index );
200203
201204 /* Detect the end of the options. */
@@ -220,6 +223,10 @@ int main(int argc, char **argv) {
220223 strncpy (opt_socket_perm , optarg , sizeof (opt_socket_perm )- 1 );
221224 break ;
222225
226+ case 'o' :
227+ strncpy (opt_socket_own , optarg , sizeof (opt_socket_perm )- 1 );
228+ break ;
229+
223230 case 'm' :
224231 opt_ui_setup &= ~ENABLE_REL ;
225232 break ;
@@ -314,7 +321,34 @@ int main(int argc, char **argv) {
314321 exit (2 );
315322 }
316323
317- chmod (opt_socket_path , strtol (opt_socket_perm , NULL , 8 ));
324+
325+ if (chmod (opt_socket_path , strtol (opt_socket_perm , NULL , 8 ))) {
326+ perror ("failed to change socket permission" );
327+ exit (2 );
328+ }
329+
330+ printf ("Socket permission: %s\n" , opt_socket_perm );
331+
332+ if (opt_socket_own [0 ]) {
333+ char * gid_pos = strchr (opt_socket_own , ':' );
334+
335+ if (!gid_pos ) {
336+ puts ("invalid ownership specification" );
337+ exit (2 );
338+ }
339+
340+ gid_pos ++ ;
341+
342+ uid_t uid = strtol (opt_socket_own , NULL , 10 );
343+ gid_t gid = strtol (gid_pos , NULL , 10 );
344+
345+ if (chown (opt_socket_path , uid , gid )) {
346+ perror ("failed to change socket ownership" );
347+ exit (2 );
348+ }
349+
350+ printf ("Socket ownership: UID=%d, GID=%d\n" , uid , gid );
351+ }
318352
319353 uinput_setup (fd_ui , opt_ui_setup );
320354
0 commit comments