@@ -763,19 +763,24 @@ static TYPE_FD open_sock(void)
763763 set_close_on_exec (fd );
764764
765765#else /* WIN32 */
766+ SECURITY_ATTRIBUTES pipe_sa ;
767+ SECURITY_DESCRIPTOR pipe_sd ;
768+
769+ init_pipe_security (& pipe_sa , & pipe_sd );
766770
767771 fd = CreateNamedPipe (
768- pipefn , /* pipe name */
769- PIPE_ACCESS_DUPLEX | /* read/write access */
770- FILE_FLAG_OVERLAPPED , /* async IO */
771- PIPE_TYPE_BYTE |
772- PIPE_READMODE_BYTE |
773- PIPE_WAIT ,
774- PIPE_UNLIMITED_INSTANCES , /* max. instances */
775- BUF_LEN , /* output buffer size */
776- BUF_LEN , /* input buffer size */
777- 0 , /* client time-out */
778- NULL ); /* FIXME: default security attributes */
772+ pipefn , /* pipe name */
773+ PIPE_ACCESS_DUPLEX /* read/write access */
774+ | FILE_FLAG_OVERLAPPED , /* async IO */
775+ PIPE_TYPE_BYTE
776+ | PIPE_READMODE_BYTE
777+ | PIPE_REJECT_REMOTE_CLIENTS /* local host only */
778+ | PIPE_WAIT ,
779+ PIPE_UNLIMITED_INSTANCES , /* max. instances */
780+ BUF_LEN , /* output buffer size */
781+ BUF_LEN , /* input buffer size */
782+ 0 , /* client time-out */
783+ & pipe_sa ); /* default security attributes */
779784
780785 if (INVALID_FD (fd )) {
781786 fatal_with_errno (EXIT_FAILURE ,
@@ -998,25 +1003,30 @@ static TYPE_FD conn_add(TYPE_FD sockfd)
9981003#else /* WIN32 */
9991004
10001005 conn_t * conn , * tmp , * last ;
1006+ SECURITY_ATTRIBUTES pipe_sa ;
1007+ SECURITY_DESCRIPTOR pipe_sd ;
10011008
10021009 /* We have detected a connection on the opened pipe. So we start
10031010 * by saving its handle and creating a new pipe for future connection */
10041011 conn = xcalloc (1 , sizeof (* conn ));
10051012 conn -> fd = sockfd ;
10061013
1014+ init_pipe_security (& pipe_sa , & pipe_sd );
1015+
10071016 /* sock is the handle of the connection pending pipe */
10081017 acc = CreateNamedPipe (
1009- pipefn , /* pipe name */
1010- PIPE_ACCESS_DUPLEX | /* read/write access */
1011- FILE_FLAG_OVERLAPPED , /* async IO */
1012- PIPE_TYPE_BYTE |
1013- PIPE_READMODE_BYTE |
1014- PIPE_WAIT ,
1015- PIPE_UNLIMITED_INSTANCES , /* max. instances */
1016- BUF_LEN , /* output buffer size */
1017- BUF_LEN , /* input buffer size */
1018- 0 , /* client time-out */
1019- NULL ); /* FIXME: default security attribute */
1018+ pipefn , /* pipe name */
1019+ PIPE_ACCESS_DUPLEX /* read/write access */
1020+ | FILE_FLAG_OVERLAPPED , /* async IO */
1021+ PIPE_TYPE_BYTE
1022+ | PIPE_READMODE_BYTE
1023+ | PIPE_REJECT_REMOTE_CLIENTS /* local host only */
1024+ | PIPE_WAIT ,
1025+ PIPE_UNLIMITED_INSTANCES , /* max. instances */
1026+ BUF_LEN , /* output buffer size */
1027+ BUF_LEN , /* input buffer size */
1028+ 0 , /* client time-out */
1029+ & pipe_sa ); /* default security attribute */
10201030
10211031 if (INVALID_FD (acc )) {
10221032 fatal_with_errno (EXIT_FAILURE ,
@@ -2352,20 +2362,19 @@ static void help(const char *arg_progname)
23522362
23532363 nut_report_config_flags ();
23542364
2355- printf ("\n%s" , suggest_doc_links (arg_progname , "upsmon .conf" ));
2365+ printf ("\n%s" , suggest_doc_links (arg_progname , "upssched .conf" ));
23562366
23572367 exit (EXIT_SUCCESS );
23582368}
23592369
23602370int main (int argc , char * * argv )
23612371{
2362- int opt_ret , argn = 0 ;
2372+ int opt_ret ;
23632373
23642374 /* Here this is a global variable, used also in start_daemon() */
23652375 prog = getprogname_argv0_default (argc > 0 ? argv [0 ] : NULL , "upssched" );
23662376
23672377 while ((opt_ret = getopt (argc , argv , optstring )) != -1 ) {
2368- argn ++ ;
23692378 switch (opt_ret ) {
23702379 case 'D' :
23712380 nut_debug_level_args ++ ;
@@ -2411,9 +2420,9 @@ int main(int argc, char **argv)
24112420
24122421 ups_name = getenv ("UPSNAME" );
24132422 notify_type = getenv ("NOTIFYTYPE" );
2414- upsdebugx (2 , "Remaining argn =%d of argc=%d" , argn , argc );
2415- if (argc > argn + 1 && * argv [argn + 1 ])
2416- notify_msg = argv [argn + 1 ];
2423+ upsdebugx (2 , "Handled optind =%d CLI tokens of argc=%d" , optind - 1 , argc );
2424+ if (argc > optind && * argv [optind ])
2425+ notify_msg = argv [optind ];
24172426
24182427 if ((!list_timers ) && ((!ups_name ) || (!notify_type ))) {
24192428 printf ("Error: environment variables UPSNAME and NOTIFYTYPE must be set.\n" );
0 commit comments