Configuration.H 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // Configuration.H -- News Configuration Class
  3. //
  4. // Copyright 2003-2004 Michael Sweet
  5. // Copyright 2002 Greg Ercolano
  6. //
  7. // This program is free software; you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public Licensse as published by
  9. // the Free Software Foundation; either version 2 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program; if not, write to the Free Software
  19. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. //
  21. #ifndef CONFIGURATION_H
  22. #define CONFIGURATION_H
  23. #include <sys/types.h>
  24. #include "everything.H"
  25. // Log levels...
  26. enum
  27. {
  28. L_ERROR, // Show error messages
  29. L_INFO, // Show error + info messages
  30. L_DEBUG // Show error + info + debug messages
  31. };
  32. // This class holds all of the global configuration information...
  33. class Configuration
  34. {
  35. int hostnamelookups; // do hostname lookups?
  36. int norecurse_msgdir; // when searching for groups, don't recurse into msg dirs
  37. int msgmod_dirs; // Use modulus msg dirs, eg. 100/{100,101,102..199}
  38. struct sockaddr_in listen; // Listen address
  39. string errorlog; // Log file
  40. int loglevel; // Log level
  41. FILE *log; // Stream for logging
  42. ino_t log_ino; // Inode # for log (detects rotation)
  43. long maxlogsize; // max log size in bytes (0=unlimited)
  44. unsigned maxclients; // maximum number of child processes
  45. string sendmail; // sendmail command
  46. string servername; // news server hostname
  47. string spamfilter; // spam filter command
  48. string spooldir; // spool directory
  49. unsigned timeout; // #secs timeout after inactivity
  50. string user; // user to run as
  51. uid_t uid; // user ID
  52. gid_t gid; // group ID
  53. bool bad_user; // true means username was not found
  54. string auth_user; // auth username
  55. string auth_pass; // auth password
  56. unsigned auth_sleep; // #secs to sleep if auth fails
  57. int auth_flags; // authentication flags
  58. int auth_protect; // authentication protection flags
  59. int lookup_user(const char *name);
  60. int OpenLogAppend();
  61. bool WasLogRotated();
  62. void FixNewsLogDir(const char* newslogdir);
  63. public:
  64. Configuration();
  65. // Load config data from a file...
  66. void Load(const char *conffile);
  67. // Log a message to the current log file...
  68. void LogMessage(int level, const char *message, ...);
  69. // Log settings to current log file...
  70. void LogSelf(int loglevel);
  71. // Get/set the current LogFile option...
  72. void ErrorLog(const char *f) { errorlog = f; }
  73. const char *ErrorLog() { return (errorlog.c_str()); }
  74. // Get/set the current HostnameLookups option...
  75. void HostnameLookups(int h) { hostnamelookups = h; }
  76. int HostnameLookups() { return (hostnamelookups); }
  77. // Get/set no recurse msg dir flag
  78. int NoRecurseMsgDir() const { return(norecurse_msgdir); }
  79. void NoRecurseMsgDir(int val) { norecurse_msgdir = val; }
  80. // Get/set use message modulus dirs flag
  81. int MsgModDirs() const { return(msgmod_dirs); }
  82. void MsgModDirs(int val) { msgmod_dirs = val; }
  83. // Get/set the current Listen/Port option...
  84. void Listen(const char *l);
  85. void Listen(int p);
  86. struct sockaddr_in *Listen() { return (&listen); }
  87. // Get/set the current LogLevel option...
  88. void LogLevel(int l) { loglevel = l; }
  89. int LogLevel() { return(loglevel); }
  90. // Get/set the current MaxClients option...
  91. void MaxClients(unsigned val) { maxclients = val; }
  92. unsigned MaxClients() { return (maxclients); }
  93. // Get/set the current MaxLogSize option...
  94. void MaxLogSize(long val) { maxlogsize = val; }
  95. void MaxLogSize(const char *val);
  96. long MaxLogSize() { return (maxlogsize); }
  97. // Get/set the current ServerName option...
  98. void ServerName(const char *h) { servername = h; };
  99. const char *ServerName() { return (servername.c_str()); }
  100. // Get/set the current Sendmail option...
  101. void SendMail(const char *c) { sendmail = c; };
  102. const char *SendMail() { return (sendmail.c_str()); }
  103. // Get/set the current SpamFilter option...
  104. void SpamFilter(const char *d) { spamfilter = d; };
  105. const char *SpamFilter() { return (spamfilter.c_str()); }
  106. // Get/set the current SpoolDir option...
  107. void SpoolDir(const char *d) { spooldir = d; };
  108. const char *SpoolDir() { return (spooldir.c_str()); }
  109. // Get/set the current Timeout option...
  110. void Timeout(unsigned val) { timeout = val; }
  111. unsigned Timeout() { return (timeout); }
  112. // Get/set the current User option...
  113. void User(const char *u) { user = u; lookup_user(u); };
  114. const char *User() { return (user.c_str()); }
  115. // Get the current user/group ID
  116. uid_t UID() const { return (uid); }
  117. gid_t GID() const { return (gid); }
  118. bool BadUser() const { return (bad_user); }
  119. // Is authorization needed (enabled)?
  120. int IsAuthNeeded() const
  121. {
  122. return(auth_flags & AUTH_NOAUTH ? 0 : 1);
  123. }
  124. // Are we authorized to do an operation?
  125. int IsAuthAllowed(int op_flag) const
  126. {
  127. //// fprintf(stderr, "AUTH_FLAGS=%d AUTH_PROT=%d USER=%s PASS=%s\n",
  128. //// auth_flags, auth_protect, auth_user.c_str(), auth_pass.c_str());
  129. // Authenticated if OK or NONE (no authentication needed)
  130. if ( auth_flags & AUTH_NOAUTH ) return(1); // everything allowed? OK
  131. if ( ( auth_protect & op_flag ) == 0 ) return(1); // this op not protected? OK
  132. if ( ( auth_flags & op_flag ) == op_flag ) return(1); // this op authenticated? OK
  133. return(0); // deny
  134. }
  135. int AuthLogin(const string&, const string&);
  136. // Log related methods
  137. string OldLogFilename();
  138. int LogUnlock();
  139. int LogLock();
  140. int Rotate(bool force);
  141. void DateStampedMessage(FILE *fp, const char *msg);
  142. void InitLog();
  143. };
  144. extern Configuration G_conf;
  145. #endif /*!CONFIGURATION_H*/