2 * shib-target.h -- top-level header file for the SHIB Common Target Library
4 * Created by: Derek Atkins <derek@ihtfp.com>
13 # include <saml/saml.h>
14 # include <shib/shib.h>
17 #include <shib-target/shibrpc.h>
26 typedef SOCKET ShibSocket;
27 typedef u_short ShibSockName;
28 #define SHIB_SHAR_SOCKET 12345 /* shar portnumber */
32 typedef int ShibSocket;
33 typedef char * ShibSockName;
34 #define SHIB_SHAR_SOCKET "/tmp/shar-socket"
40 /* Create an RPC Client handle for the _connected_ socket sock, attaching
41 * the RPC program and version.
43 * returns a CLIENT on success, or NULL on error. The caller can
44 * call clnt_pcreateerror ("<string>") to output an error message from
47 CLIENT * shibrpc_client_create (ShibSocket sock, u_long program, u_long version);
51 /* Create a new socket and put it into sock.
53 * Returns 0 on success, non-zero on error
55 int shib_sock_create (ShibSocket *sock);
58 * bind the socket s to the "port" name.
60 * Returns 0 on success; non-zero on error.
62 * SIDE EFFECT: On error, the socket is closed!
64 int shib_sock_bind (ShibSocket s, ShibSockName name);
67 * connect the socket s to the "port" name on the local host.
69 * Returns 0 on success; non-zero on error.
71 int shib_sock_connect (ShibSocket s, ShibSockName name);
74 * accept a connection. Returns 0 on success, non-zero on failure.
76 int shib_sock_accept (ShibSocket listener, ShibSocket* s);
81 void shib_sock_close (ShibSocket s, ShibSockName name);
85 /* application names */
86 #define SHIBTARGET_GENERAL "general"
87 #define SHIBTARGET_SHAR "shar"
88 #define SHIBTARGET_SHIRE "shire"
89 #define SHIBTARGET_RM "rm"
90 #define SHIBTARGET_POLICIES "policies"
92 /* configuration tags */
93 #define SHIBTARGET_TAG_LOGGER "logger"
94 #define SHIBTARGET_TAG_SCHEMAS "schemadir"
95 #define SHIBTARGET_TAG_CERTFILE "certfile"
96 #define SHIBTARGET_TAG_KEYFILE "keyfile"
97 #define SHIBTARGET_TAG_KEYPASS "keypass"
98 #define SHIBTARGET_TAG_CALIST "calist"
100 #define SHIBTARGET_TAG_AATIMEOUT "AATimeout"
101 #define SHIBTARGET_TAG_AACONNECTTO "AAConnectTimeout"
102 #define SHIBTARGET_TAG_SAMLCOMPAT "SAMLCompat"
104 #define SHIBTARGET_TAG_AAP "aap-uri"
105 #define SHIBTARGET_TAG_SITES "sitesFile"
107 #define SHIBTARGET_TAG_DEFAULTLIFE "defaultLife"
109 #define SHIBTARGET_TAG_CACHETYPE "cacheType"
110 #define SHIBTARGET_TAG_CACHECLEAN "cacheClean"
111 #define SHIBTARGET_TAG_CACHETIMEOUT "cacheTimeout"
113 #define SHIBTARGET_TAG_REQATTRS "requestAttributes"
115 /* initialize and finalize the target library (return 0 on success, 1 on failure) */
116 int shib_target_initialize (const char* application, const char* ini_file);
117 void shib_target_finalize (void);
118 ShibSockName shib_target_sockname(void);
124 namespace shibtarget {
129 Resource(const char* resource_url);
130 Resource(std::string resource_url);
133 const char* getResource() const;
134 const char* getURL() const;
135 bool equals(Resource*) const;
136 saml::Iterator<saml::SAMLAttribute*> getDesignators() const;
139 ResourcePriv *m_priv;
142 class RPCHandleInternal;
146 RPCHandle(ShibSockName shar, u_long program, u_long version);
149 CLIENT * connect(void); /* locks the HANDLE and returns the CLIENT */
150 void release(void); /* unlocks the HANDLE */
151 void disconnect(void); /* disconnects */
154 RPCHandleInternal *m_priv;
157 class ShibTargetException : public std::exception
160 explicit ShibTargetException() { m_code = SHIBRPC_OK; }
161 explicit ShibTargetException(ShibRpcStatus code, const char* msg,
162 const XMLCh* origin = NULL)
163 { m_code = code; if (msg) m_msg=msg; if (origin) m_origin = origin; }
164 explicit ShibTargetException(ShibRpcStatus code, const std::string& msg,
165 const XMLCh* origin = NULL) : m_msg(msg)
166 { m_code=code; if(origin) m_origin = origin; }
167 virtual ~ShibTargetException() throw () {}
168 virtual const char* what() const throw () { return (m_msg.c_str()); }
169 virtual ShibRpcStatus which() const throw () { return (m_code); }
170 virtual const XMLCh* where() const throw () { return m_origin.c_str(); }
173 ShibRpcStatus m_code;
175 saml::xstring m_origin;
182 RPCError() { init(0, "", NULL); }
183 RPCError(ShibRpcError* error);
184 RPCError(int s, char const* st, const XMLCh* orig = NULL) { init (s,st,orig); }
185 RPCError(ShibTargetException &exp) { init(exp.which(), exp.what(), exp.where()); }
191 // Return a set of strings that corresponds to the type, text, and desc
192 const char* getType();
193 const char* getText();
194 const char* getDesc();
195 const char* getOriginErrorURL();
196 const char* getOriginContactName();
197 const char* getOriginContactEmail();
201 void init(int stat, char const* msg, const XMLCh* origin);
202 RPCErrorPriv* m_priv;
217 SHIRE(RPCHandle *rpc, SHIREConfig config, std::string shire_url);
220 RPCError* sessionIsValid(const char* cookie, const char* ip, const char* url);
221 RPCError* sessionCreate(const char* post, const char* ip,
222 std::string &cookie);
237 RM(RPCHandle *rpc, RMConfig config);
240 RPCError* getAssertions(const char* cookie, const char* ip,
242 std::vector<saml::SAMLAssertion*> &assertions,
243 saml::SAMLAuthenticationStatement **statement = NULL);
244 static void serialize(saml::SAMLAssertion &assertion, std::string &result);
245 static saml::Iterator<saml::SAMLAttribute*> getAttributes(saml::SAMLAssertion &assertion);
253 ShibINI (std::string& file, bool case_sensitive = true) { init(file,case_sensitive); }
254 ShibINI (const char *file, bool case_sensitive = true) {
255 std::string f = file;
256 init(f, case_sensitive);
262 const std::string get (const std::string& header, const std::string& tag);
263 const std::string get (const char* header, const char* tag) {
264 std::string h = header, t = tag;
268 const std::string operator() (const std::string& header, const std::string& tag) {
269 return get(header,tag);
271 const std::string operator() (const char* header, const char* tag) {
272 std::string h = header, t = tag;
276 bool exists(const std::string& header);
277 bool exists(const std::string& header, const std::string& tag);
279 bool exists(const char* header) {
280 std::string s = header;
283 bool exists(const char* header, const char* tag) {
284 std::string h = header, t = tag;
288 // Special method to look for a tag in one header and maybe in the
289 // 'SHIBTARGET_GENERAL' header
290 bool get_tag(std::string& header, std::string& tag, bool try_general,
291 std::string* result);
293 bool get_tag(std::string& header, const char* tag, bool try_general,
294 std::string* result) {
296 return get_tag (header,t,try_general,result);
299 bool get_tag(const char* header, const char* tag, bool try_general,
300 std::string* result) {
301 std::string h = header, t = tag;
302 return get_tag (h,t,try_general,result);
305 // Dump out the inifile to the output stream
306 void dump(std::ostream& os);
310 // The begin() functions reset the iterator and return the first element
311 // (or 0 if there are no elements.)
312 // The next() functions return the next element, or 0 if there are no
316 // for (const foo* current = begin(); current; current = next()) {
320 // NOTE: Holding an Iterator will lock the INI file and cause it to
321 // stop updating itself. You should destroy the iterator as soon as
322 // you are done with it.
324 // ALSO NOTE: the string* returned from the Iterator is only valid
325 // while you hold the iterator. You should copy the de-reference
326 // of the pointer to your own copy if you want to keep the string.
330 virtual ~Iterator() = 0;
331 virtual const std::string* begin() = 0;
332 virtual const std::string* next() = 0;
335 Iterator* header_iterator();
336 Iterator* tag_iterator(const std::string& header);
338 static bool boolean(std::string& value);
342 void init(std::string& file, bool case_sensitive);
351 void insert (const std::string& key, const std::string& value) { m_map[key] = value; }
352 void insert (const std::string& key, const char* value) {
353 std::string v = value;
356 void insert (const char* key, const std::string& value) {
360 void insert (const char* key, const char* value) {
361 std::string k = key, v = value;
364 void insert (RPCError& e);
366 void clear () { m_map.clear(); }
368 std::string run (std::istream& s) const;
369 std::string run (const std::string& input) const;
370 std::string run (const char* input) const {
371 std::string i = input;
377 std::map<std::string,std::string> m_map;
380 class ShibTargetConfig
383 static void preinit();
384 static ShibTargetConfig& init(const char* app_name, const char* inifile);
385 static ShibTargetConfig& getConfig();
386 virtual void init() = 0;
387 virtual void shutdown() = 0;
388 virtual ~ShibTargetConfig();
389 virtual ShibINI& getINI() = 0;
390 virtual saml::Iterator<const XMLCh*> getPolicies() = 0;
392 ShibSockName m_SocketName;
398 #endif /* SHIB_TARGET_H */