/[anubis]/anubis/src/authmode.c
ViewVC logotype

Diff of /anubis/src/authmode.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by polak, Sat Nov 22 12:04:34 2003 UTC revision 1.4 by gray, Sat Nov 22 14:23:21 2003 UTC
# Line 252  asmtp_init(enum asmtp_state state) Line 252  asmtp_init(enum asmtp_state state)
252  }  }
253    
254  static enum asmtp_state  static enum asmtp_state
255  asmtp_ehlo (enum asmtp_state state)  asmtp_ehlo (enum asmtp_state state, ANUBIS_USER *usr)
256  {  {
257          char *command = NULL;          char *command = NULL;
258          size_t s = 0;          size_t s = 0;
259          char *mech;          char *mech;
260          char *init_input;          char *init_input;
         char *user;  
261                    
262          recvline_ptr(SERVER, remote_client, &command, &s);          recvline_ptr(SERVER, remote_client, &command, &s);
263    
# Line 266  asmtp_ehlo (enum asmtp_state state) Line 265  asmtp_ehlo (enum asmtp_state state)
265          case KW_AUTH:          case KW_AUTH:
266                  mech = get_command_arg ();                  mech = get_command_arg ();
267                  init_input = get_command_arg ();                  init_input = get_command_arg ();
268                  if (anubis_auth_gsasl (mech, init_input, &user) == 0) {                  if (anubis_auth_gsasl (mech, init_input, usr) == 0)
                         strncpy(session.client, user, sizeof(session.client));  
269                          state = state_auth;                          state = state_auth;
                 }  
270                  break;                  break;
271                                    
272          case KW_QUIT:          case KW_QUIT:
# Line 295  asmtp_ehlo (enum asmtp_state state) Line 292  asmtp_ehlo (enum asmtp_state state)
292  }  }
293    
294  static int  static int
295  anubis_smtp ()  anubis_smtp (ANUBIS_USER *usr)
296  {  {
297          enum asmtp_state state;          enum asmtp_state state;
298    
# Line 308  anubis_smtp () Line 305  anubis_smtp ()
305                          break;                          break;
306                                                    
307                  case state_ehlo:                  case state_ehlo:
308                          state = asmtp_ehlo (state);                          state = asmtp_ehlo (state, usr);
309                          break;                          break;
310                                                    
311                  case state_quit:                  case state_quit:
# Line 338  int Line 335  int
335  anubis_get_db_record(char *username, ANUBIS_USER *usr)  anubis_get_db_record(char *username, ANUBIS_USER *usr)
336  {  {
337          void *db;          void *db;
         static ANUBIS_USER cache_usr;  
338          int rc;          int rc;
339    
340          if (cache_usr.smtp_authid == 0          if (!anubis_dbtype
341              || strcmp(username, cache_usr.smtp_authid)) {              || anubis_db_open(anubis_dbtype,
342                  anubis_db_free_record(&cache_usr);                                anubis_dbarg, anubis_db_rdonly,
343                                                          &db) != ANUBIS_DB_SUCCESS)
344                  if (!anubis_dbtype                  return ANUBIS_DB_FAIL;
                     || anubis_db_open(anubis_dbtype,  
                                       anubis_dbarg, anubis_db_rdonly,  
                                       &db) != ANUBIS_DB_SUCCESS)  
                         return ANUBIS_DB_FAIL;  
345                                    
346                  rc = anubis_db_get_record(db, username, &cache_usr);          rc = anubis_db_get_record(db, username, usr);
347                  switch (rc) {          switch (rc) {
348                  case ANUBIS_DB_SUCCESS:          case ANUBIS_DB_SUCCESS:
349                          info(VERBOSE,                  info(VERBOSE,
350                               _("Found record for %s"), username);                       _("Found record for %s"), username);
351                          break;                  break;
352                                                    
353                  case ANUBIS_DB_FAIL:          case ANUBIS_DB_FAIL:
354                          memset(&cache_usr, 0, sizeof cache_usr);                  anubis_error(SOFT,
                         anubis_error(SOFT,  
355                           _("Cannot retrieve data from the SASL database: %s"),                           _("Cannot retrieve data from the SASL database: %s"),
356                                       anubis_db_strerror(db));                               anubis_db_strerror(db));
357                          break;                  break;
358                                                    
359                  case ANUBIS_DB_NOT_FOUND:          case ANUBIS_DB_NOT_FOUND:
360                          memset(&cache_usr, 0, sizeof cache_usr);                  info(VERBOSE, _("Record for %s not found"),
361                          info(VERBOSE, _("Record for %s not found"),                       username);
362                               username);                  break;
363                          break;          }
                 }  
364                                    
365                  anubis_db_close(&db);          anubis_db_close(&db);
         } else  
                 rc = ANUBIS_DB_SUCCESS;  
   
         if (rc == ANUBIS_DB_SUCCESS)  
                 *usr = cache_usr;  
366          return rc;          return rc;
367  }  }
368    
# Line 393  anubis_authenticate_mode (int sd_client, Line 378  anubis_authenticate_mode (int sd_client,
378          remote_client = (void *)sd_client;          remote_client = (void *)sd_client;
379          remote_server = (void *)sd_client;          remote_server = (void *)sd_client;
380          alarm(900);          alarm(900);
381          if (anubis_smtp ())          if (anubis_smtp (&usr))
382                  return EXIT_FAILURE;                  return EXIT_FAILURE;
383    
         if (anubis_get_db_record(session.client, &usr) != ANUBIS_DB_SUCCESS)  
                 return EXIT_FAILURE; /* Shouldn't happen */  
   
384          if (usr.username)          if (usr.username)
385                  strncpy(session.client, usr.username, sizeof session.client);                  strncpy(session.client, usr.username, sizeof session.client);
386                    else
387                    strncpy(session.client, usr.smtp_authid, sizeof session.client);
388          parse_transmap(&rc,          parse_transmap(&rc,
389                         session.client,                         session.client,
390                         inet_ntoa(addr->sin_addr),                         inet_ntoa(addr->sin_addr),

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26