Project

General

Profile

Feature #3018 » ligthttpd_chown.diff

VBKesha, 2020-07-03 13:03

View differences:

new/base.h 2020-07-03 15:55:24.741629100 +0300
86 86
       buffer *server_tag;
87 87
       buffer *dirlist_encoding;
88 88
       buffer *errorfile_prefix;
89

  
89 90
       buffer *socket_perms;
91
       buffer *socket_user;
92
       buffer *socket_group;
90 93

  
91 94
       unsigned short high_precision_timestamps;
92 95
       unsigned short max_keep_alive_requests;
new/configfile.c 2020-07-03 15:55:34.088628647 +0300
283 283
               { "server.http-parseopts",             NULL, T_CONFIG_ARRAY,   T_CONFIG_SCOPE_SERVER     }, /* 82 */
284 284
               { "server.systemd-socket-activation",  NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_SERVER     }, /* 83 */
285 285

  
286
               { "server.socket-user",                    NULL, T_CONFIG_STRING,  T_CONFIG_SCOPE_CONNECTION }, /* 84 */
287
               { "server.socket-group" ,              NULL, T_CONFIG_STRING,  T_CONFIG_SCOPE_CONNECTION }, /* 85 */
286 288
               { NULL,                                NULL, T_CONFIG_UNSET,   T_CONFIG_SCOPE_UNSET      }
287 289
       };
288 290

  
......
356 358
               s->socket_perms = (i == 0 || buffer_string_is_empty(srv->config_storage[0]->socket_perms))
357 359
                 ? buffer_init()
358 360
                 : buffer_init_buffer(srv->config_storage[0]->socket_perms);
361

  
362
               s->socket_user = (i == 0 || buffer_string_is_empty(srv->config_storage[0]->socket_user))
363
                 ? buffer_init()
364
                 : buffer_init_buffer(srv->config_storage[0]->socket_user);
365

  
366
               s->socket_group = (i == 0 || buffer_string_is_empty(srv->config_storage[0]->socket_group))
367
                 ? buffer_init()
368
                 : buffer_init_buffer(srv->config_storage[0]->socket_group);
369

  
359 370
               s->max_keep_alive_requests = 100;
360 371
               s->max_keep_alive_idle = 5;
361 372
               s->max_read_idle = 60;
......
446 457
               cv[77].destination = &(s->stream_response_body);
447 458
               cv[79].destination = &(s->error_intercept);
448 459
               cv[81].destination = s->socket_perms;
460
               cv[84].destination = s->socket_user;
461
               cv[85].destination = s->socket_group;
449 462

  
450 463
               srv->config_storage[i] = s;
451 464

  
......
709 722
       /*PATCH(listen_backlog);*//*(not necessary; used only at startup)*/
710 723
       PATCH(stream_request_body);
711 724
       PATCH(stream_response_body);
725

  
712 726
       PATCH(socket_perms);
727
       PATCH(socket_user);
728
       PATCH(socket_group);
713 729

  
714 730
       PATCH(etag_use_inode);
715 731
       PATCH(etag_use_mtime);
......
803 819
                               con->conf.global_bytes_per_second_cnt_ptr = &s->global_bytes_per_second_cnt;
804 820
                       } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.socket-perms"))) {
805 821
                               PATCH(socket_perms);
822
                       } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.socket-user"))) {
823
                               PATCH(socket_user);
824
                       } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.socket-group"))) {
825
                               PATCH(socket_group);
806 826
                       }
807 827
               }
808 828
       }
new/network.c 2020-07-03 15:55:40.731628325 +0300
21 21
#include <string.h>
22 22
#include <stdlib.h>
23 23

  
24
#include <pwd.h>
25
#include <grp.h>
26

  
27

  
24 28
void
25 29
network_accept_tcp_nagle_disable (const int fd)
26 30
{
......
323 327
               if (0 != m && -1 == chmod(host, m)) {
324 328
                       log_error_write(srv, __FILE__, __LINE__, "sssbss", "chmod(\"", host, "\", ", s->socket_perms, "):", strerror(errno));
325 329
               }
330

  
331
               if ((!buffer_string_is_empty(s->socket_perms)) && (!buffer_string_is_empty(s->socket_perms))){
332
                       struct passwd *pwd;
333
                       struct group  *grp;
334
                       pwd = getpwnam(s->socket_user->ptr);
335
                       if(pwd == NULL){
336
                               log_error_write(srv, __FILE__, __LINE__, "sss", "unable to get uid(", s->socket_user->ptr, ")");
337
                       }
338

  
339
                   grp = getgrnam(s->socket_group->ptr);
340
                       if(grp == NULL){
341
                               log_error_write(srv, __FILE__, __LINE__, "sss", "unable to get gid(", s->socket_group->ptr, ")");
342
                       }
343

  
344

  
345
                       if((pwd != NULL) && (grp != NULL)){
346
                               if(chown(host, pwd->pw_uid, grp->gr_gid) == -1){
347
                                       log_error_write(srv, __FILE__, __LINE__, "ss", "unabe chown socket:", strerror(errno));
348
                               }
349
                       }
350
               }
326 351
       }
327 352

  
353

  
328 354
       if (-1 != stdin_fd) { } else
329 355
       if (-1 == listen(srv_socket->fd, s->listen_backlog)) {
330 356
               log_error_write(srv, __FILE__, __LINE__, "ss", "listen failed: ", strerror(errno));
new/server.c 2020-07-03 15:55:45.879628075 +0300
368 368
                       buffer_free(s->error_handler_404);
369 369
                       buffer_free(s->errorfile_prefix);
370 370
                       buffer_free(s->socket_perms);
371
                       buffer_free(s->socket_user);
372
                       buffer_free(s->socket_group);
371 373
                       array_free(s->mimetypes);
372 374
                       free(s);
373 375
               }
(5-5/5)