2 * shib-common.h -- top-level header file for the SHIB Common Target Library
4 * Created by: Derek Atkins <derek@ihtfp.com>
20 #error "Need to define ShibSocket"
21 typedef in_port_t ShibSockName;
22 #define SHIB_SHAR_SOCKET 12345 /* shar portnumber */
26 typedef int ShibSocket;
27 typedef char * ShibSockName;
28 #define SHIB_SHAR_SOCKET "/tmp/shar-socket"
34 /* Create an RPC Client handle for the _connected_ socket sock, attaching
35 * the RPC program and version.
37 * returns a CLIENT on success, or NULL on error. The caller can
38 * call clnt_pcreateerror ("<string>") to output an error message from
41 CLIENT * shibrpc_client_create (ShibSocket sock, u_long program, u_long version);
46 /* Create a new socket and put it into sock.
48 * Returns 0 on success, non-zero on error
50 int shib_sock_create (ShibSocket *sock);
53 * bind the socket s to the "port" name.
55 * Returns 0 on success; non-zero on error.
57 * SIDE EFFECT: On error, the socket is closed!
59 int shib_sock_bind (ShibSocket s, ShibSockName name);
62 * connect the socket s to the "port" name on the local host.
64 * Returns 0 on success; non-zero on error.
66 int shib_sock_connect (ShibSocket s, ShibSockName name);
71 /* application names */
72 #define SHIBTARGET_GENERAL "general"
73 #define SHIBTARGET_SHAR "shar"
74 #define SHIBTARGET_SHIRE "shire"
75 #define SHIBTARGET_RM "rm"
77 /* configuration tags */
78 #define SHIBTARGET_TAG_LOGGER "logger"
79 #define SHIBTARGET_TAG_SCHEMAS "schemadir"
80 #define SHIBTARGET_TAG_CERTFILE "certfile"
81 #define SHIBTARGET_TAG_KEYFILE "keyfile"
82 #define SHIBTARGET_TAG_KEYPASS "keypass"
83 #define SHIBTARGET_TAG_CALIST "calist"
85 #define SHIBTARGET_TAG_SITES "sitesFile"
87 /* initialize and finalize the target library (return 0 on success, 1 on failure) */
88 int shib_target_initialize (const char* application, const char* ini_file);
89 void shib_target_finalize (void);
96 #include <saml/saml.h>
97 #include <shib/shib.h>
99 namespace shibtarget {
104 Resource(const char* resource_url);
105 Resource(std::string resource_url);
108 const char* getResource();
109 const char* getURL();
110 bool equals(Resource*);
113 ResourcePriv *m_priv;
121 virtual ~CCacheEntry();
123 virtual saml::Iterator<saml::SAMLAssertion*> getAssertions(Resource& resource) = 0;
124 virtual bool isSessionValid(time_t lifetime, time_t timeout) = 0;
125 virtual const char* getClientAddress() = 0;
127 static CCacheEntry* getInstance(saml::SAMLAuthenticationStatement *s,
128 const char *client_addr);
132 // this should only be called by CCache::insert()
133 virtual void setCache(CCache* cache) = 0;
141 virtual saml::SAMLBinding* getBinding(const XMLCh* bindingProt) = 0;
142 virtual CCacheEntry* find(const char* key) = 0;
143 virtual void insert(const char* key, CCacheEntry* entry) = 0;
144 virtual void remove(const char* key) = 0;
146 static CCache* getInstance();
149 // special function to call over to CCacheEntry::setCache()
150 void setCache(CCacheEntry* entry);
153 extern CCache* g_shibTargetCCache;
155 class RPCHandleInternal;
159 RPCHandle(ShibSockName shar, u_long program, u_long version);
162 CLIENT * connect(void);
163 void disconnect(void);
166 RPCHandleInternal *m_priv;
169 class ShibTargetException : public std::exception
172 explicit ShibTargetException() { m_code = SHIBRPC_OK; m_msg=""; }
173 explicit ShibTargetException(ShibRpcStatus code, const char* msg) { m_code = code; if (msg) m_msg=msg; }
174 explicit ShibTargetException(ShibRpcStatus code, const std::string& msg) : m_msg(msg) { m_code=code; }
175 virtual ~ShibTargetException() throw () {}
176 virtual const char* what() const throw () { return (m_msg.c_str()); }
177 virtual ShibRpcStatus which() const throw () { return (m_code); }
180 ShibRpcStatus m_code;
188 RPCError() { init(0,""); }
189 RPCError(int s, char const* st) { init(s,st); }
190 RPCError(ShibTargetException &exp) { init(exp.which(), exp.what()); }
193 bool isError() { return (status != 0); }
196 // Return a string that corresponds to the "status"
197 const char* toString();
200 std::string error_msg;
201 saml::SAMLException* m_except;
204 void init(int code, char const* msg);
205 RPCErrorPriv* m_priv;
220 SHIRE(RPCHandle *rpc, SHIREConfig config, std::string shire_url);
223 RPCError* sessionIsValid(const char* cookie, const char* ip);
224 RPCError* sessionCreate(const char* post, const char* ip,
225 std::string &cookie);
240 RM(RPCHandle *rpc, RMConfig config);
243 RPCError* getAssertions(const char* cookie, const char* ip,
245 std::vector<saml::SAMLAssertion*> &assertions);
246 static void serialize(saml::SAMLAssertion &assertion, std::string &result);
247 static saml::Iterator<saml::SAMLAttribute*> getAttributes(saml::SAMLAssertion &assertion);
255 ShibINI (std::string& file, bool case_sensitive = true) { init(file,case_sensitive); }
256 ShibINI (const char *file, bool case_sensitive = true) {
257 std::string f = file;
258 init(f, case_sensitive);
264 const std::string& get (const std::string& header, const std::string& tag);
265 const std::string& get (const char* header, const char* tag) {
266 std::string h = header, t = tag;
270 const std::string& operator() (const std::string& header, const std::string& tag) {
271 return get(header,tag);
273 const std::string& operator() (const char* header, const char* tag) {
274 std::string h = header, t = tag;
278 bool exists(const std::string& header);
279 bool exists(const std::string& header, const std::string& tag);
281 bool exists(const char* header) {
282 std::string s = header;
285 bool exists(const char* header, const char* tag) {
286 std::string h = header, t = tag;
290 // Special method to look for a tag in one header and maybe in the
291 // 'SHIBTARGET_GENERAL' header
292 bool get_tag(std::string& header, std::string& tag, bool try_general,
293 std::string* result);
295 bool get_tag(std::string& header, const char* tag, bool try_general,
296 std::string* result) {
298 return get_tag (header,t,try_general,result);
301 bool get_tag(const char* header, const char* tag, bool try_general,
302 std::string* result) {
303 std::string h = header, t = tag;
304 return get_tag (h,t,try_general,result);
307 // Dump out the inifile to the output stream
308 void dump(std::ostream& os);
312 // The begin() functions reset the iterator and return the first element
313 // (or 0 if there are no elements.)
314 // The next() functions return the next element, or 0 if there are no
318 // for (const foo* current = begin(); current; current = next()) {
324 virtual const std::string* begin() = 0;
325 virtual const std::string* next() = 0;
328 Iterator* header_iterator();
329 Iterator* tag_iterator(const std::string& header);
331 static bool boolean(std::string& value);
335 void init(std::string& file, bool case_sensitive);
344 void insert (const std::string& key, const std::string& value) { m_map[key] = value; }
345 void insert (const std::string& key, const char* value) {
346 std::string v = value;
349 void insert (const char* key, const std::string& value) {
353 void insert (const char* key, const char* value) {
354 std::string k = key, v = value;
357 void insert (RPCError& e);
359 void clear () { m_map.clear(); }
361 std::string run (std::istream& s) const;
362 std::string run (const std::string& input) const;
363 std::string run (const char* input) const {
364 std::string i = input;
370 std::map<std::string,std::string> m_map;
373 class ShibTargetConfig
376 static ShibTargetConfig& init(const char* app_name, const char* inifile);
377 virtual void shutdown() = 0;
378 virtual ShibINI& getINI() = 0;
384 #endif /* SHIB_COMMON_H */