00001 #ifndef _AccessList_h_
00002 #define _AccessList_h_
00003 #include <ctype.h>
00004 #include <stdio.h>
00005 #include <netdb.h>
00006 #include <sys/param.h>
00007
00008 #include <sys/socket.h>
00009 #include <netinet/in.h>
00010 #include <arpa/inet.h>
00011
00012 #include <iostream>
00013 #include <fstream>
00014 #include <string>
00015 #include <vector>
00016
00017 #include "config.h"
00018 #include "Debug.h"
00019 #include "Error.h"
00020
00021 #include "NewsgroupFilter.h"
00022 #include "Lexer.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 class Authentication {
00037 public:
00038
00039
00040
00041
00042 Authentication () : defAuth("none"){};
00043
00044
00045
00046
00047 void set (const std::string &AuthString);
00048
00049
00050
00051
00052
00053
00054 const std::string& getType (void);
00055
00056
00057
00058
00059 const std::string& getField(int nr);
00060
00061
00062
00063
00064 int getNrOfFields (void);
00065
00066
00067
00068
00069
00070
00071
00072 void modifyField (unsigned int nr, const char *v);
00073
00074
00075
00076
00077
00078
00079
00080
00081 void modify (unsigned int start, Authentication &source);
00082
00083
00084
00085
00086
00087 void appendField (const char *v);
00088
00089
00090
00091
00092 void printParameters (std::ostream *pOut) const;
00093
00094
00095
00096
00097
00098 int typeEqual (const std::string &v);
00099
00100 private:
00101 std::vector<std::string> fields;
00102 string defAuth;
00103 };
00104
00111 class AccessEntry {
00112 public:
00113 char hostname[MAXHOSTNAMELEN];
00114
00115 enum {
00116 af_read = 0x1,
00117 af_post = 0x2,
00118 af_debug = 0x4,
00119 af_authentication = 0x8,
00120 };
00121
00122 unsigned int access_flags;
00123
00124 NewsgroupFilter list;
00125 NewsgroupFilter read;
00126 NewsgroupFilter postTo;
00127 Authentication authentication;
00128 string PAMServicename;
00129
00130 AccessEntry() {
00131 init();
00132 } void init() {
00133 hostname[0] = '\0';
00134 access_flags = 0x0;
00135 PAMServicename = PAM_DEFAULT_SERVICENAME;
00136 }
00137
00138 void clear() {
00139 init();
00140 }
00141 void modifyAccessFlags (const std::string &flags);
00142 friend std::ostream & operator<<(std::ostream & os,
00143 const AccessEntry & ae);
00144
00145
00146
00147
00148
00149
00150 void printParameters (std::ostream *pOut);
00151
00152
00153
00154
00155
00156
00157
00158 void printAccessFlags (std::ostream *pOut) const;
00159 };
00160
00167 class AccessList {
00168 private:
00169 std::vector < AccessEntry > vector;
00170
00171 public:
00172 AccessList() {
00173 } AccessEntry *client(const char *name, struct in_addr addr);
00174 void init() {
00175 vector.clear();
00176 }
00177 void read(Lexer & lex);
00178 void readClient(Lexer & lex, const char *address);
00179
00180
00181
00182
00183
00184
00185 void printParameters (std::ostream *pOut);
00186 };
00187
00188
00189
00190 inline const std::string& Authentication::getType (void)
00191 {
00192 if (fields.size() == 0) {
00193 return defAuth;
00194 } else {
00195 return fields[0];
00196 }
00197 }
00198
00199 inline const std::string& Authentication::getField(int nr)
00200 {
00201 return fields[nr];
00202 }
00203 inline int Authentication::getNrOfFields (void)
00204 {
00205 return fields.size();
00206 }
00207 inline void AccessEntry::printAccessFlags (std::ostream *pOut) const
00208 {
00209 if (access_flags == 0x0) {
00210 *pOut << " none";
00211 }
00212 if (access_flags & af_read) {
00213 *pOut << " read";
00214 }
00215 if (access_flags & af_post) {
00216 *pOut << " post";
00217 }
00218 if (access_flags & af_debug) {
00219 *pOut << " debug";
00220 }
00221 }
00222 inline void Authentication::modifyField (unsigned int nr, const char *v)
00223 {
00224 if (nr >= fields.size())
00225 throw ("bounding error");
00226
00227 fields[nr] += v;
00228 }
00229
00230 inline void Authentication::appendField (const char *v)
00231 {
00232 fields.push_back (v);
00233 }
00234 #endif