config.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * saop: smtp authentication over pop3
  3. * Copyright (C) 2007 Juan José Gutiérrez de Quevedo <juanjo@iteisa.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. * @author Juan José Gutiérrez de Quevedo <juanjo@iteisa.com>
  19. */
  20. #include "config.h"
  21. void read_config(char *file,struct config_t *config)
  22. {
  23. char line[1024]={0};
  24. FILE *f;
  25. unsigned long i,j;
  26. if(NULL==(f=fopen(file,"r")))
  27. {
  28. printf("No config file found, continuing with defaults.\n");
  29. return;
  30. }
  31. while(!feof(f))
  32. {
  33. fgets(line,sizeof(line),f);
  34. if(!feof(f)&&'#'!=line[0]&&'\0'!=line[0]&&'\r'!=line[0]&&'\n'!=line[0])
  35. {
  36. for(i=0,j=0;i<strlen(line);i++)
  37. if(!isspace(line[i])&&'\r'!=line[i]&&'\n'!=line[i])
  38. line[j++]=line[i];
  39. line[j]='\0';
  40. #define PROCESS_CONFIG_OPTION_STR(x) if(!cmp(line,#x "=")) strncpy(config->x,line+strlen(#x "="),sizeof(config->x)); else
  41. #define PROCESS_CONFIG_OPTION_INT(x) if(!cmp(line,#x "=")) config->x=atoi(line+strlen(#x "=")); else
  42. #define PROCESS_CONFIG_OPTION_BOOL(x) if(!cmp(line,#x "=")) config->x=cmp(line+strlen(#x "="),"true")?0:1; else
  43. #ifndef WIN32
  44. PROCESS_CONFIG_OPTION_BOOL(background)
  45. PROCESS_CONFIG_OPTION_BOOL(drop_privileges)
  46. PROCESS_CONFIG_OPTION_STR(user)
  47. PROCESS_CONFIG_OPTION_STR(group)
  48. PROCESS_CONFIG_OPTION_STR(chroot)
  49. #endif /* WIN32 */
  50. PROCESS_CONFIG_OPTION_INT(listen_port)
  51. PROCESS_CONFIG_OPTION_STR(smtp_server)
  52. PROCESS_CONFIG_OPTION_INT(smtp_port)
  53. PROCESS_CONFIG_OPTION_STR(auth_server)
  54. PROCESS_CONFIG_OPTION_INT(auth_port)
  55. PROCESS_CONFIG_OPTION_STR(auth_file)
  56. PROCESS_CONFIG_OPTION_STR(local_domains)
  57. PROCESS_CONFIG_OPTION_STR(auth_method)
  58. printf("Option line %s not recognized\n",line); /* keep in mind this line comes after an else, so it won't get executed normally */
  59. }
  60. }
  61. fclose(f);
  62. }