patch-pop3_session_c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. $OpenBSD: patch-pop3_session_c,v 1.1.1.1 2004/11/08 21:57:05 naddy Exp $
  2. --- pop3_session.c.orig Sun Aug 17 19:44:55 2003
  3. +++ pop3_session.c Fri Aug 27 01:45:07 2004
  4. @@ -35,6 +35,7 @@
  5. extern const char * ssl_certfile;
  6. extern const char * ssl_keyfile;
  7. +extern const char * group_name;
  8. extern const char * local_mbox;
  9. extern char real_username[MAXLINE+1];
  10. extern char real_maildrop[MAXLINE+1];
  11. @@ -45,8 +46,17 @@ extern const char * mailspool;
  12. int authenticate(char * username, char * password);
  13. void show_uidl(int fd, char * line);
  14. -static void do_remove_lock(void) {
  15. +static void do_remove_lock(int fd) {
  16. do_cleanup();
  17. + if (remove_lock(mdl)) {
  18. + syslog(LOG_ERR,"unable to unlink lock file %s : %m",mdl);
  19. + write_line(fd,"unable to unlink lock file - see syslog\r\n");
  20. + exit(EXIT_FAILURE);
  21. + }
  22. +}
  23. +
  24. +static void cleanup_before_exit(void) {
  25. + do_cleanup();
  26. remove_lock(mdl);
  27. }
  28. @@ -64,8 +74,9 @@ static void print_capa(int fd) {
  29. static void sig_handler(int signo) {
  30. - remove_lock(mdl);
  31. syslog(LOG_INFO,"%s: %u", "caught signal",signo);
  32. + if (remove_lock(mdl))
  33. + syslog(LOG_ERR,"unable to unlink lock file for user %s : %m",mdl);
  34. exit(EXIT_FAILURE);
  35. }
  36. @@ -227,21 +238,21 @@ void pop3_session(int fd) {
  37. mdl = maildrop;
  38. - g_inf = getgrnam("mail");
  39. + g_inf = getgrnam(group_name);
  40. if (g_inf==NULL) {
  41. - syslog(LOG_ERR,"%s","group 'mail' not found");
  42. - write_line(fd,"-ERR [SYS/TEMP] group 'mail' not found\r\n");
  43. + syslog(LOG_ERR,"group '%s' not found",group_name);
  44. + write_line(fd,"-ERR [SYS/TEMP] group not found\r\n");
  45. exit(EXIT_FAILURE);
  46. }
  47. if (setegid(g_inf->gr_gid)!=0 && real_username[0] == 0) {
  48. syslog(LOG_ERR,"%s: %u: %s","setegid() failed",g_inf->gr_gid,strerror(errno));
  49. - write_line(fd,"-ERR [SYS/TEMP] failed to join 'mail' group (setegid)\r\n");
  50. + write_line(fd,"-ERR [SYS/TEMP] failed to join group (setegid)\r\n");
  51. exit(EXIT_FAILURE);
  52. }
  53. if (setgid(g_inf->gr_gid)!=0 && real_username[0] == 0) {
  54. syslog(LOG_ERR,"%s: %u: %s","setgid() failed",g_inf->gr_gid,strerror(errno));
  55. - write_line(fd,"-ERR [SYS/TEMP] failed to join 'mail' group (setgid)\r\n");
  56. + write_line(fd,"-ERR [SYS/TEMP] failed to join group (setgid)\r\n");
  57. exit(EXIT_FAILURE);
  58. }
  59. @@ -258,18 +269,18 @@ void pop3_session(int fd) {
  60. if (setuid(u_inf->pw_uid)!=0) {
  61. syslog(LOG_ERR,"%s: %u: %s","setuid() failed",u_inf->pw_uid,strerror(errno));
  62. write_line(fd,"-ERR [SYS/TEMP] failed to set user identity\r\n");
  63. - do_remove_lock();
  64. + do_remove_lock(fd);
  65. exit(EXIT_FAILURE);
  66. }
  67. if (seteuid(u_inf->pw_uid)!=0) {
  68. syslog(LOG_ERR,"%s: %u: %s","seteuid() failed",u_inf->pw_uid,strerror(errno));
  69. write_line(fd,"-ERR [SYS/TEMP] failed to set effective user identity\r\n");
  70. - do_remove_lock();
  71. + do_remove_lock(fd);
  72. exit(EXIT_FAILURE);
  73. }
  74. - if (atexit(do_remove_lock)!=0) {
  75. + if (atexit(cleanup_before_exit)!=0) {
  76. syslog(LOG_WARNING,"%s: %s","atexit() failed; lock files may fail to expire",strerror(errno));
  77. }
  78. @@ -278,7 +289,7 @@ void pop3_session(int fd) {
  79. if (process_mails(maildrop)==0) {
  80. write_line(fd,"-ERR [SYS/PERM] failed to scan maildrop contents\r\n");
  81. do_cleanup();
  82. - do_remove_lock();
  83. + do_remove_lock(fd);
  84. exit(EXIT_FAILURE);
  85. }
  86. @@ -334,5 +345,8 @@ void pop3_session(int fd) {
  87. do_update(maildrop);
  88. }
  89. do_cleanup();
  90. - remove_lock(maildrop);
  91. + if (remove_lock(maildrop)) {
  92. + syslog(LOG_ERR,"unable to unlink lock file %s : %m",maildrop);
  93. + exit(EXIT_FAILURE);
  94. + }
  95. }