You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB

  1. From f259999d824b921a8a443e73d8c2b9e2d2170413 Mon Sep 17 00:00:00 2001
  2. From: Ansuel Smith <ansuelsmth@gmail.com>
  3. Date: Tue, 8 Oct 2019 02:10:43 +0200
  4. Subject: [PATCH] plugins/cgi: adds dontresolve option
  5. This option permit to call the simbolic link instead of the file the simbolic link points.
  6. All the security check are still done as the simbolic path is passed at the end after all the checks are passed. This is useful if some cgi app are used for multiple function based on the name they are called by.
  7. Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
  8. ---
  9. plugins/cgi/cgi_plugin.c | 13 +++++++++++++
  10. 1 file changed, 13 insertions(+)
  11. --- a/plugins/cgi/cgi_plugin.c
  12. +++ b/plugins/cgi/cgi_plugin.c
  13. @@ -15,6 +15,7 @@ struct uwsgi_cgi {
  14. struct uwsgi_string_list *loadlib;
  15. struct uwsgi_string_list *cgi_safe;
  16. int optimize;
  17. + int dontresolve;
  18. int from_docroot;
  19. int has_mountpoints;
  20. struct uwsgi_dyn_dict *default_cgi;
  21. @@ -75,6 +76,8 @@ struct uwsgi_option uwsgi_cgi_options[]
  22. {"cgi-safe", required_argument, 0, "skip security checks if the cgi file is under the specified path", uwsgi_opt_add_string_list, &uc.cgi_safe, 0},
  23. + {"cgi-dontresolve", no_argument, 0 , "call symbolic link directly instead of the real path", uwsgi_opt_true,&uc.dontresolve, 0},
  24. +
  25. {0, 0, 0, 0, 0, 0, 0},
  26. };
  27. @@ -475,6 +478,7 @@ static int uwsgi_cgi_request(struct wsgi
  28. char full_path[PATH_MAX];
  29. char tmp_path[PATH_MAX];
  30. + char symbolic_path[PATH_MAX];
  31. struct stat cgi_stat;
  32. int need_free = 0;
  33. int is_a_file = 0;
  34. @@ -533,6 +537,10 @@ static int uwsgi_cgi_request(struct wsgi
  35. uwsgi_404(wsgi_req);
  36. return UWSGI_OK;
  37. }
  38. + if (uc.dontresolve) {
  39. + full_path_len = strlen(full_path);
  40. + memcpy(symbolic_path, full_path, full_path_len+1);
  41. + }
  42. full_path_len = strlen(tmp_path);
  43. // add +1 to copy the null byte
  44. @@ -639,6 +647,11 @@ static int uwsgi_cgi_request(struct wsgi
  45. }
  46. }
  47. + if (uc.dontresolve) {
  48. + full_path_len = strlen(symbolic_path);
  49. + memcpy(full_path, symbolic_path, full_path_len+1);
  50. + }
  51. +
  52. int ret = uwsgi_cgi_run(wsgi_req, docroot, docroot_len, full_path, helper, path_info, script_name, is_a_file, discard_base);
  53. if (need_free) free(docroot);
  54. return ret;