Sorry for the first one.
If there's something wrong with style again, please tell me exactly 
what.  I will  edit it again.

-- 
With best regards,
        Gregory Edigarov
--- smtpd.c.orig        Tue May 26 23:11:26 2009
+++ smtpd.c.new Wed May 27 12:04:17 2009
@@ -83,6 +83,52 @@
 
 extern char    **environ;
 
+char    *executable     = "/usr/libexec/smtpd-auth";
+char    *plugin         = "/usr/libexec/smtpd-auth.so";
+
+/*
+ * athenticate through custom executable
+ */ 
+
+int auth_exec (char *executable, char *user, char *passwd)
+{       
+        pid_t a_pid;
+        int r;
+        
+        if( ( a_pid = fork()) == 0) 
+                execl(executable,executable,user,passwd);
+        else
+                r = wait();
+        return r;
+}       
+
+/*        
+ * authenticate using plugin
+ */
+
+int auth_plugin (char *plugin, char *user, char *passwd)
+{
+        void *handle; 
+        int (*smtp_authenticate) (char*, char*); /* plugin must export this 
function */
+        int r;
+        
+        handle = dlopen (plugin,RTLD_NOW);
+        if (!handle) { 
+                /* perhaps should log something before */
+                return 0;
+        }
+        
+        smtp_authenticate = dlsym(handle,"smtp_authenticate");
+        if ((error = dlerror()) != NULL)  {
+                /*  again, should log something */
+                return 0;
+        }
+        
+        r = smtp_authenticate (user,pass);
+        dlclose (handle);
+        return (r);
+}
+
 int __b64_pton(char const *, unsigned char *, size_t);
 
 __dead void
@@ -497,6 +543,25 @@
 
                        req->success = auth_userokay(req->user, NULL,
                            "auth-smtp", req->pass);
+
+               /*
+                * this should be regulated from config 
+                * option would be like: authtype = bsd|exec|plugin   
+                * plugin should go into /etc/mail/plugin/libauth.so 
+                * but this should also be regulated with config parameter 
+                * executable is /usr/libexec/smtpd-auth 
+                */                     
+                        switch (authmode){
+                        case 1:
+                              req->success = auth_userokay(user, NULL, 
"auth-smtp", pass);
+                              break;
+                        case 2:      
+                              req->success = auth_exec(executable,user,pass);
+                              break;
+                        case 3:      
+                              req->success = 
auth_plugin_call(plugin,user,pass);
+                              break;
+                        }
 
                        imsg_compose(ibuf, IMSG_PARENT_AUTHENTICATE, 0, 0,
                            -1, req, sizeof(*req));

Reply via email to