local.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "common.h"
  2. #include "send.h"
  3. static void
  4. mboxfile(dest *dp, String *user, String *path, char *file)
  5. {
  6. char *cp;
  7. mboxpath(s_to_c(user), s_to_c(dp->addr), path, 0);
  8. cp = strrchr(s_to_c(path), '/');
  9. if(cp)
  10. path->ptr = cp+1;
  11. else
  12. path->ptr = path->base;
  13. s_append(path, file);
  14. }
  15. /*
  16. * Check forwarding requests
  17. */
  18. extern dest*
  19. expand_local(dest *dp)
  20. {
  21. Biobuf *fp;
  22. String *file, *line, *s;
  23. dest *rv;
  24. int forwardok;
  25. char *user;
  26. /* short circuit obvious security problems */
  27. if(strstr(s_to_c(dp->addr), "/../")){
  28. dp->status = d_unknown;
  29. return 0;
  30. }
  31. /* isolate user's name if part of a path */
  32. user = strrchr(s_to_c(dp->addr), '!');
  33. if(user)
  34. user++;
  35. else
  36. user = s_to_c(dp->addr);
  37. /* if no replacement string, plug in user's name */
  38. if(dp->repl1 == 0){
  39. dp->repl1 = s_new();
  40. mboxname(user, dp->repl1);
  41. }
  42. s = unescapespecial(s_clone(dp->repl1));
  43. /*
  44. * if this is the descendant of a `forward' file, don't
  45. * look for a forward.
  46. */
  47. forwardok = 1;
  48. for(rv = dp->parent; rv; rv = rv->parent)
  49. if(rv->status == d_cat){
  50. forwardok = 0;
  51. break;
  52. }
  53. file = s_new();
  54. if(forwardok){
  55. /*
  56. * look for `forward' file for forwarding address(es)
  57. */
  58. mboxfile(dp, s, file, "forward");
  59. fp = sysopen(s_to_c(file), "r", 0);
  60. if (fp != 0) {
  61. line = s_new();
  62. for(;;){
  63. if(s_read_line(fp, line) == nil)
  64. break;
  65. if(*(line->ptr - 1) != '\n')
  66. break;
  67. if(*(line->ptr - 2) == '\\')
  68. *(line->ptr-2) = ' ';
  69. *(line->ptr-1) = ' ';
  70. }
  71. sysclose(fp);
  72. if(debug)
  73. fprint(2, "forward = %s\n", s_to_c(line));
  74. rv = s_to_dest(s_restart(line), dp);
  75. s_free(line);
  76. if(rv){
  77. s_free(file);
  78. s_free(s);
  79. return rv;
  80. }
  81. }
  82. }
  83. /*
  84. * look for a 'pipe' file. This won't work if there are
  85. * special characters in the account name since the file
  86. * name passes through a shell. tdb.
  87. */
  88. mboxfile(dp, dp->repl1, s_reset(file), "pipeto");
  89. if(sysexist(s_to_c(file))){
  90. if(debug)
  91. fprint(2, "found a pipeto file\n");
  92. dp->status = d_pipeto;
  93. line = s_new();
  94. s_append(line, "upasname='");
  95. s_append(line, user);
  96. s_append(line, "' ");
  97. s_append(line, s_to_c(file));
  98. s_append(line, " ");
  99. s_append(line, s_to_c(dp->addr));
  100. s_append(line, " ");
  101. s_append(line, s_to_c(dp->repl1));
  102. s_free(dp->repl1);
  103. dp->repl1 = line;
  104. s_free(file);
  105. s_free(s);
  106. return dp;
  107. }
  108. /*
  109. * see if the mailbox directory exists
  110. */
  111. mboxfile(dp, s, s_reset(file), ".");
  112. if(sysexist(s_to_c(file)))
  113. dp->status = d_cat;
  114. else
  115. dp->status = d_unknown;
  116. s_free(file);
  117. s_free(s);
  118. return 0;
  119. }