1 /* zxidsimple.c - Shell script helper CGI binary for SAML 2 SP
2 * Copyright (c) 2007 Symlabs (symlabs@symlabs.com), All Rights Reserved.
3 * Author: Sampo Kellomaki (sampo@iki.fi)
4 * This is confidential unpublished proprietary source code of the author.
5 * NO WARRANTY, not even implied warranties. Contains trade secrets.
6 * Distribution prohibited unless authorized in writing.
7 * Licensed under Apache License 2.0, see file COPYING.
8 * $Id: zxidsimple.c,v 1.7 2007-06-21 23:32:32 sampo Exp $
9 *
10 * 16.1.2007, created --Sampo
11 *
12 * See also: http://hoohoo.ncsa.uiuc.edu/cgi/interface.html (CGI specification)
13 * README-zxid, section 10 "zxid_simple() API"
14 * zxidhlo.sh
15 */
16
17 #include <string.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20
21 #include <zx/zxid.h>
22 #include <zx/c/zxidvers.h>
23
24 char* help =
25 "zxidsimple - SAML 2.0 SP CGI - R" ZXID_REL "\n\
26 SAML 2.0 is a standard for federated identity and Sinlg Sign-On.\n\
27 Copyright (c) 2010 Sampo Kellomaki (sampo@iki.fi), All Rights Reserved.\n\
28 Copyright (c) 2007 Symlabs (symlabs@symlabs.com), All Rights Reserved.\n\
29 Author: Sampo Kellomaki (sampo@iki.fi)\n\
30 NO WARRANTY, not even implied warranties. Licensed under Apache License v2.0\n\
31 See http://www.apache.org/licenses/LICENSE-2.0\n\
32 Send well researched bug reports to the author. Home: zxid.org\n\
33 \n\
34 Usage: zxidsimple [options] -o ldif CONF AUTO_FLAGS <cgi-input\n\
35 -o ldif In the successful login case LDIF fragment with SSO attributes\n\
36 is written to specified file.\n\
37 CONF Configuration string such as\n\
38 \"PATH=/var/zxid/&URL=https://sp1.zxidsp.org:8443/zxidhlo.sh\"\n\
39 AUTO_FLAGS Usually 255 for full autmation\n\
40 cgi-input The stdin should contain CGI input or /dev/null. The latter\n\
41 case causes $QUERY_STRING to be automatically consulted.\n\
42 -h This help message\n\
43 -- End of options\n\
44 Exit value: 0 means successful SSO (the ldif file was written), shell script\n\
45 should show protected page\n\
46 1 means protocol interaction was output. Shell script should exit.\n\
47 other exit values are errors.\n";
48
49 /* ============== M A I N ============== */
50
51 /* Called by: */
main(int argc,char ** argv)52 int main(int argc, char** argv)
53 {
54 FILE* f;
55 char* out = 0;
56 char* res;
57 int auto_flags;
58 --argc; ++argv;
59 if (argc == 4 && argv[0][0] == '-' && argv[0][1] == 'o') {
60 out = argv[1];
61 argc -= 2;
62 argv += 2;
63 }
64 if (argc != 2 || argv[1][0] == '-') { fprintf(stderr, "%s", help); exit(3); }
65
66 auto_flags = atoi(argv[1]);
67 auto_flags &= ~ZXID_AUTO_EXIT;
68 res = zxid_simple(argv[0], 0, auto_flags);
69 if (res && res[0] == 'd') {
70 if (out) {
71 f = fopen(out, "w");
72 if (!f) {
73 perror("-o specified LDIF file");
74 exit(2);
75 }
76 fprintf(f, "%s", res);
77 fclose(f);
78 }
79 exit(0);
80 }
81 printf("%s", res);
82 return 1;
83 }
84
85 /* EOF -- zxidsimple.c */
86