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.

65 lines
2.3 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. diff --git a/plugins/cgi/cgi_plugin.c b/plugins/cgi/cgi_plugin.c
  12. index d032db17c..30e1cc528 100644
  13. --- a/plugins/cgi/cgi_plugin.c
  14. +++ b/plugins/cgi/cgi_plugin.c
  15. @@ -15,6 +15,7 @@ struct uwsgi_cgi {
  16. struct uwsgi_string_list *loadlib;
  17. struct uwsgi_string_list *cgi_safe;
  18. int optimize;
  19. + int dontresolve;
  20. int from_docroot;
  21. int has_mountpoints;
  22. struct uwsgi_dyn_dict *default_cgi;
  23. @@ -75,6 +76,8 @@ struct uwsgi_option uwsgi_cgi_options[] = {
  24. {"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},
  25. + {"cgi-dontresolve", no_argument, 0 , "call symbolic link directly instead of the real path", uwsgi_opt_true,&uc.dontresolve, 0},
  26. +
  27. {0, 0, 0, 0, 0, 0, 0},
  28. };
  29. @@ -475,6 +478,7 @@ static int uwsgi_cgi_request(struct wsgi_request *wsgi_req) {
  30. char full_path[PATH_MAX];
  31. char tmp_path[PATH_MAX];
  32. + char symbolic_path[PATH_MAX];
  33. struct stat cgi_stat;
  34. int need_free = 0;
  35. int is_a_file = 0;
  36. @@ -533,6 +537,10 @@ static int uwsgi_cgi_request(struct wsgi_request *wsgi_req) {
  37. uwsgi_404(wsgi_req);
  38. return UWSGI_OK;
  39. }
  40. + if (uc.dontresolve) {
  41. + full_path_len = strlen(full_path);
  42. + memcpy(symbolic_path, full_path, full_path_len+1);
  43. + }
  44. full_path_len = strlen(tmp_path);
  45. // add +1 to copy the null byte
  46. @@ -639,6 +647,11 @@ static int uwsgi_cgi_request(struct wsgi_request *wsgi_req) {
  47. }
  48. }
  49. + if (uc.dontresolve) {
  50. + full_path_len = strlen(symbolic_path);
  51. + memcpy(full_path, symbolic_path, full_path_len+1);
  52. + }
  53. +
  54. int ret = uwsgi_cgi_run(wsgi_req, docroot, docroot_len, full_path, helper, path_info, script_name, is_a_file, discard_base);
  55. if (need_free) free(docroot);
  56. return ret;