Download | Plain Text | No Line Numbers


  1. /*
  2.  * Copyright (c) 2016 Manuel Mausz
  3.  */
  4.  
  5. /* uncomment the line below to use nbdm or gdbm instead of BerkDB */
  6. //#define USE_NDBM
  7.  
  8. #define _GNU_SOURCE
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <fcntl.h>
  13.  
  14. #if defined(USE_NDBM)
  15. # include <ndbm.h>
  16. #else
  17. # define DB_DBM_HSEARCH 1 /* use the dbm interface */
  18. # define HAVE_DBM /* for BerkDB 5.0 and later */
  19. # include <db.h>
  20. #endif
  21.  
  22. int main()
  23. {
  24. char *user = getenv("SMTPAUTHUSER");
  25. if (user == NULL || strlen(user) == 0)
  26. return 0;
  27.  
  28. char *dbfile = getenv("LOCKUSERDB");
  29. if (dbfile == NULL)
  30. dbfile = "control/lockedusers";
  31.  
  32. DBM *dbm = dbm_open(dbfile, O_RDONLY, 0600);
  33. if (dbm == NULL)
  34. {
  35. perror("Unable to open database");
  36. return 0;
  37. }
  38.  
  39. datum key = { .dptr = user, .dsize = strlen(user) };
  40. datum data = dbm_fetch(dbm, key);
  41. if (data.dptr != NULL)
  42. {
  43. puts("E550 YOUR ACCOUNT HAS BEEN LOCKED - PLEASE CONTACT YOUR POSTMASTER");
  44. fprintf(stderr, "block: smtp user %s has been blocked\n", user);
  45. }
  46.  
  47. (void)dbm_close(dbm);
  48. return 0;
  49. }
  50.