Browse Source

add an example for the windows version
add lots of debug, and also debug to file
fix a small bug when no localdomains are found


git-svn-id: file:///home/ps/projects/saop@13 8c280a3b-b034-0410-b168-b83d87712a00

ps 14 years ago
parent
commit
aa44aca5c7
6 changed files with 69 additions and 7 deletions
  1. 3 0
      auth.c
  2. 28 0
      docs/saop.cfg.example
  3. 30 3
      saop.c
  4. 4 0
      utils.c
  5. 3 3
      utils.h
  6. 1 1
      win32-service.c

+ 3 - 0
auth.c

@@ -1,5 +1,8 @@
 #include "auth.h"
 
+#ifdef DEBUG
+extern FILE *fsaopdebug;
+#endif /* DEBUG */
 int authenticate_with_pop3(char *user,char *pass,char *server,unsigned long port)
 {
   int fd;

+ 28 - 0
docs/saop.cfg.example

@@ -0,0 +1,28 @@
+#default config file
+#default values are the commented ones
+
+#address to listen at
+#listen_port = 25
+
+#real smtp server
+#smtp_server = localhost
+
+#port of the real smtp server
+#smtp_port = 2525
+
+#auth server against to which authenticate
+#auth_server = localhost
+
+#port of the auth server (110 for pop3, 143 for imap)
+#auth_port = 110
+
+#file to use for authentication in case of "file" auth_method
+#on windows, paths are relative to the exe's file
+#auth_file = saop_users
+
+#local domains file list
+#local_domains = localdomains
+
+#authentication method to use
+#valid values are one of "pop3", "imap4" or "file" (without the quotes)
+#auth_method = pop3

+ 30 - 3
saop.c

@@ -33,11 +33,13 @@ void handle_quit(int);
 
 struct
 {
+  #ifndef WIN32
   unsigned char background;
   unsigned char drop_privileges;
   char user[512];
   char group[512];
   char chroot[512];
+  #endif /* WIN32 */
   unsigned short listen_port;
   char smtp_server[512];
   unsigned short smtp_port;
@@ -47,9 +49,17 @@ struct
   char local_domains[512];
   char auth_method[512];
 }
-config={1,1,"nobody","nobody","/etc/saop/chroot",25,"localhost",2525,"localhost",110,"/etc/saop/users","/etc/saop/localdomains","pop3"}; /* default config */
+#ifdef WIN32
+config={25,"localhost",2525,"localhost",110,"saop_users","localdomains","pop3"}; /* win32 default config */
+#else
+config={1,1,"nobody","nobody","/etc/saop/chroot",25,"localhost",2525,"localhost",110,"/etc/saop/users","/etc/saop/localdomains","pop3"}; /* unix default config */
+#endif /* WIN32 */
 
+/* global vars */
 char **localdomains;
+#ifdef DEBUG
+FILE *fsaopdebug;
+#endif /* DEBUG */
 
 int
 #ifdef WIN32
@@ -66,11 +76,24 @@ main
   struct passwd *pwd;
   struct group *grp;
   #endif /* WIN32 */
+  #ifdef WIN32
+  char *tmppath=NULL,*tmppath2=NULL;
+  #endif /* WIN32 */
 
   /* configure detach mode for pthreads */
   pthread_attr_init(&thread_attr);
   pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_DETACHED);
 
+  #ifdef WIN32
+  /* first chdir to our binary's dir */
+  condfree(tmppath);
+  if(NULL==(tmppath=(char *)malloc(2048))) { perror("Error reserving memory"); exit(-1); }
+  if(0==GetModuleFileName(NULL,tmppath,2048)) { condfree(tmppath); perror("Error getting module path"); exit(-1); }
+  if(NULL==(tmppath2=strrchr(tmppath,'\\'))) { condfree(tmppath); perror("Something is wrong with our path"); exit(-1); }
+  *tmppath2='\0';
+  if(-1==chdir(tmppath)) { condfree(tmppath); perror("Error changing to exe's directory"); exit(-1); }
+  condfree(tmppath);
+  #endif /* WIN32 */
   #ifndef WIN32
   signal(SIGINT,handle_quit);
   signal(SIGTERM,handle_quit);
@@ -213,7 +236,9 @@ void *handle_connection(void *p_outside)
       }
       else if(!cmp(line,"rcpt to:"))
       {
-        if(!authenticated)
+        if(NULL==localdomains)
+          debug("No localdomains defined, can't receive emails");
+        else if(!authenticated)
         {
           tmpchar=strchr(line,'@');
           if(NULL!=tmpchar)
@@ -338,11 +363,13 @@ void read_config(char *file)
       #define PROCESS_CONFIG_OPTION_STR(x) if(!cmp(line,#x "=")) strncpy(config.x,line+strlen(#x "="),sizeof(config.x)); else
       #define PROCESS_CONFIG_OPTION_INT(x) if(!cmp(line,#x "=")) config.x=atoi(line+strlen(#x "=")); else
       #define PROCESS_CONFIG_OPTION_BOOL(x) if(!cmp(line,#x "=")) config.x=cmp(line+strlen(#x "="),"true")?0:1; else
+      #ifndef WIN32
       PROCESS_CONFIG_OPTION_BOOL(background)
       PROCESS_CONFIG_OPTION_BOOL(drop_privileges)
       PROCESS_CONFIG_OPTION_STR(user)
       PROCESS_CONFIG_OPTION_STR(group)
       PROCESS_CONFIG_OPTION_STR(chroot)
+      #endif /* WIN32 */
       PROCESS_CONFIG_OPTION_INT(listen_port)
       PROCESS_CONFIG_OPTION_STR(smtp_server)
       PROCESS_CONFIG_OPTION_INT(smtp_port)
@@ -369,7 +396,7 @@ void read_localdomains(char *file)
   debug("Opening file to localdomains");
   if(NULL==(f=fopen(file,"r")))
   {
-    printf("No localdomains file, continuing with an empty locals. This will probably render this program completely useless.\n");
+    debug("No localdomains file, continuing with an empty locals. This will probably render this program completely useless.");
     return;
   }
 

+ 4 - 0
utils.c

@@ -1,5 +1,9 @@
 #include "utils.h"
 
+#ifdef DEBUG
+extern FILE *fsaopdebug;
+#endif /* DEBUG */
+
 /**
  * reads a string as safely as possible.
  *

+ 3 - 3
utils.h

@@ -24,7 +24,7 @@
 #endif /* MSG_NOSIGNAL */
 
 /* utility macros */
-#define cmp(x,y) (NULL==x||strncasecmp(x,y,strlen(y)))
+#define cmp(x,y) (NULL==x||NULL==y||strncasecmp(x,y,strlen(y)))
 #define write_string(x,y) do { debug(y); debug("Writing string " #y " to socket " #x); send(x,y,strlen(y),MSG_NOSIGNAL); send(x,"\r\n",2,MSG_NOSIGNAL); } while(0)
 #define condfree(x) do { debug("Freeing memory block " #x); if(NULL!=x) free(x); x=NULL; } while(0)
 #ifndef WIN32
@@ -38,9 +38,9 @@
 #define MAX(x,y) (((x)>(y))?(x):(y))
 #define free_and_read_string(x,y) do { condfree(x); x=read_string(y); } while(0)
 #ifdef DEBUG
-  #define debug(x) do { fprintf(stderr,"%s\n",x); fflush(stderr); } while(0)
+  #define debug(x) do { if(NULL==fsaopdebug) { fsaopdebug=fopen("c:\\saop.log","a"); } if(NULL!=fsaopdebug) { fprintf(fsaopdebug,"%s\n",x); fflush(fsaopdebug); } fprintf(stderr,"%s\n",x); fflush(stderr); } while(0)
 #else
-  #define debug(x)
+  #define debug(x) do {} while(0)
 #endif /* DEBUG */
 
 char *read_string(int);

+ 1 - 1
win32-service.c

@@ -21,7 +21,7 @@
 #include <windows.h>
 
 #define SERVICE_NAME "saop: smtp authentication over pop3"
-#define SERVICE_DESCRIPTION_TEXT "A proxy for SMTP that adds LOGIN authentication to the underlying server and that uses pop3, imap4 or a file for authentication"
+#define SERVICE_DESCRIPTION_TEXT "Adds LOGIN authentication to an SMTP server. Users are authenticated against a pop3 server, an imap4 server or a file"
 
 /* macros */
 #define ChangeServiceStatus(x,y,z) y.dwCurrentState=z; SetServiceStatus(x,&y);