From f83721e1c52dc4dbb2fd1ad53897090ef25c75c7 Mon Sep 17 00:00:00 2001
From: Shreenidhi Shedi <sshedi@vmware.com>
Date: Sat, 18 Mar 2023 01:15:03 +0530
Subject: [PATCH] src/core/ngx_file.c: recursively chown the directories
Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
---
src/core/ngx_file.c | 48 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index 63ada85..5314852 100644
|
a
|
b
|
|
| 8 | 8 | #include <ngx_config.h> |
| 9 | 9 | #include <ngx_core.h> |
| 10 | 10 | |
| | 11 | #include <fts.h> |
| 11 | 12 | |
| 12 | 13 | static ngx_int_t ngx_test_full_name(ngx_str_t *name); |
| 13 | 14 | |
| … |
… |
ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot)
|
| 593 | 594 | return NGX_OK; |
| 594 | 595 | } |
| 595 | 596 | |
| | 597 | ngx_int_t |
| | 598 | recursive_chown(const char *dirname, ngx_log_t *log, ngx_uid_t user) |
| | 599 | { |
| | 600 | FTS *ftsp; |
| | 601 | char *paths[] = {(char *)dirname, NULL}; |
| | 602 | |
| | 603 | ftsp = fts_open(paths, FTS_PHYSICAL, NULL); |
| | 604 | if(ftsp == NULL) { |
| | 605 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
| | 606 | "fts_open(%s) failed", dirname); |
| | 607 | return NGX_ERROR; |
| | 608 | } |
| | 609 | |
| | 610 | while (1) { |
| | 611 | FTSENT *ent = fts_read(ftsp); |
| | 612 | if (!ent) { |
| | 613 | if (!errno) { |
| | 614 | break; |
| | 615 | } |
| | 616 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
| | 617 | "fts_read failed"); |
| | 618 | return NGX_ERROR; |
| | 619 | } |
| | 620 | |
| | 621 | if (chown(ent->fts_path, user, -1) < 0) { |
| | 622 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
| | 623 | "chown(\"%s\", %d) failed", |
| | 624 | dirname, user); |
| | 625 | return NGX_ERROR; |
| | 626 | } |
| | 627 | } |
| | 628 | |
| | 629 | if (fts_close(ftsp) < 0) { |
| | 630 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
| | 631 | "fts_close failed"); |
| | 632 | return NGX_ERROR; |
| | 633 | } |
| | 634 | |
| | 635 | return NGX_OK; |
| | 636 | } |
| 596 | 637 | |
| 597 | 638 | ngx_int_t |
| 598 | 639 | ngx_create_paths(ngx_cycle_t *cycle, ngx_uid_t user) |
| … |
… |
ngx_create_paths(ngx_cycle_t *cycle, ngx_uid_t user)
|
| 635 | 676 | path[i]->name.data, user); |
| 636 | 677 | return NGX_ERROR; |
| 637 | 678 | } |
| | 679 | |
| | 680 | if (recursive_chown((const char *) path[i]->name.data, cycle->log, user)) { |
| | 681 | ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
| | 682 | "recursive_chown(\"%s\", %d) failed", |
| | 683 | path[i]->name.data, user); |
| | 684 | return NGX_ERROR; |
| | 685 | } |
| 638 | 686 | } |
| 639 | 687 | |
| 640 | 688 | if ((fi.st_mode & (S_IRUSR|S_IWUSR|S_IXUSR)) |