1 // Copyright (c) 1999-2018 David Muse
2 // See the file COPYING for more information
3 
4 #include <rudiments/charstring.h>
5 #include <rudiments/stdio.h>
6 #include <rudiments/file.h>
7 #include <rudiments/process.h>
8 #include <rudiments/sys.h>
9 
version(int argc,const char ** argv)10 static void version(int argc, const char **argv) {
11 
12 	if (argc!=2 || (charstring::compare(argv[1],"-version") &&
13 			charstring::compare(argv[1],"--version"))) {
14 		return;
15 	}
16 
17 	stdoutput.printf("%s %s\n\n",argv[0],SQLR_VERSION);
18 	stdoutput.printf("Rudiments version: %s\n",sys::getRudimentsVersion());
19 #if defined(__DATE__) && defined(__TIME__)
20 	stdoutput.printf("Compiled: %s %s\n",__DATE__,__TIME__);
21 #endif
22 	stdoutput.write("\n"
23 		"Copyright (c) 1999-2018 David Muse\n"
24 		"This is free software; see the source for copying "
25 		"conditions.  There is NO\n"
26 		"warranty; not even for MERCHANTABILITY or "
27 		"FITNESS FOR A PARTICULAR PURPOSE.\n"
28 		"\n"
29 		"Written by David Muse.\n");
30 
31 	process::exit(0);
32 }
33 
34 static void helpmessage(const char *progname);
35 
help(int argc,const char ** argv)36 static void help(int argc, const char **argv) {
37 
38 	if (argc!=2 || (charstring::compare(argv[1],"-help") &&
39 			charstring::compare(argv[1],"--help"))) {
40 		return;
41 	}
42 
43 	// strip off any leading directories
44 	char	*progname=file::basename(argv[0]);
45 
46 	// strip off any libtool prefixes
47 	if (!charstring::compare(progname,"lt-",3)) {
48 		char	*tmp=charstring::duplicate(progname+3);
49 		delete[] progname;
50 		progname=tmp;
51 	}
52 
53 	helpmessage(progname);
54 
55 	delete[] progname;
56 
57 	process::exit(0);
58 }
59 
60 #define CONNECTIONOPTIONS \
61 "Connection options:\n" \
62 "	-host host		Host name or IP address of the server to\n" \
63 "				connect to.\n" \
64 "\n" \
65 "	-port port		Port to connect to.\n" \
66 "\n" \
67 "	-socket socket		Local unix socket file name to connect to.\n" \
68 "				Can be used instead of host/port for making\n" \
69 "				connections to local servers.\n" \
70 "\n" \
71 "	-user user		User name to auth with.\n" \
72 "\n" \
73 "	-password password	Password to auth with.\n" \
74 "\n" \
75 "Alternate connection options:\n" \
76 "	-config config		Override the default configuration with the\n" \
77 "				specified configuration.\n" \
78 "\n" \
79 "	-id instanceid		Derive connection info and credentials from the\n" \
80 "				specified instance, as defined in the\n" \
81 "				configuration.\n" \
82 "\n" \
83 "\n" \
84 "	-krb			Use Kerberos authentication and encryption.\n" \
85 "\n" \
86 "	-krbservice svc		Use the specified kerberos service.\n" \
87 "\n" \
88 "	-krbmech mech		Use the specified kerberos mechanism.\n" \
89 "\n" \
90 "	-krbflags flags		Use the specified kerberos flags,\n" \
91 "				comma-separated.\n" \
92 "\n" \
93 "\n" \
94 "	-tls			Use TLS/SSL authentication and encrpyiton.\n" \
95 "\n" \
96 "	-tlsversion version	Use the specified TLS/SSL version.\n" \
97 "\n" \
98 "	-tlscert file		Use the specified certificate chain file.\n" \
99 "				This file should contain the client's\n" \
100 "				certificate, private key, and signing\n" \
101 "				certificates, as appropriate.\n" \
102 "				On Windows systems, this must be a .pfx file.\n" \
103 "				On non-Windows systems, a variety of file\n" \
104 "				formats are supported.\n" \
105 "\n" \
106 "	-tlspassword pwd	Use the specified password to acess the private\n" \
107 "				key in the file specified by -tlscert.\n" \
108 "\n" \
109 "	-tlsciphers \"list\"	Allow the specified list of ciphers.  The\n" \
110 "				list should be quoted and the ciphers should be\n" \
111 "				separated by spaces.\n" \
112 "\n" \
113 "	-tlsvalidate (no|ca|ca+host|ca+domain)\n" \
114 "				Certificate validation option.\n" \
115 "				\"no\" - Don't validate the server's certificate.\n" \
116 "				\"ca\" - Validate that the server's certificate\n" \
117 "				was signed by a trusted certificate authority.\n" \
118 "				\"ca+host\" - Perform \"ca\" validation and also\n" \
119 "				validate that one of the subject alternate names\n" \
120 "				(or common name if no SANs are present) in the \n" \
121 "				certificate matches the host parameter.\n" \
122 "				(Falls back to \"ca\" validation when a unix\n" \
123 "				socket is used.)\n" \
124 "				\"ca+domain\" - Perform \"ca\" validation and also\n" \
125 "				validate that the domain name of one of the\n" \
126 "				subject alternate naames (or common name if no\n" \
127 "				SANs are present) in the certificate matches\n" \
128 "				the domain name of the host parameter.\n" \
129 "				(Falls back to \"ca\" validation when a unix\n" \
130 "				socket is used.)\n" \
131 "\n" \
132 "	-tlsca file		Use the specified certificate authority file\n" \
133 "				when validating the server's certificate.  Or,\n" \
134 "				if \"file\" is a directory, then use all\n" \
135 "				certificate authority files found in that\n" \
136 "				directory when validating the server's\n" \
137 "				certifictate.\n" \
138 "\n" \
139 "	-tlsdepth depth 	Set the maximum certificate chain validation\n" \
140 "				depth to the specified depth.\n" \
141 "\n"
142 
143 #define CONFIG \
144 "	-config config		Override the default configuration with the\n" \
145 "				specified configuration.\n" \
146 "\n"
147 
148 #define CONFIGID \
149 CONFIG \
150 "	-id instanceid		Id of an instance, as defined in the\n" \
151 "				configuration.\n" \
152 "\n"
153 
154 #define LOCALSTATEDIR \
155 "	-localstatedir dir 	Override the default directory for keeping\n" \
156 "				pid files, sockets, and other working or\n" \
157 "				stateful files with the specified\n" \
158 "				directory.\n" \
159 "\n"
160 
161 #define SERVEROPTIONS \
162 CONFIGID \
163 LOCALSTATEDIR
164 
165 #define DISABLECRASHHANDLER \
166 "	-disable-crash-handler	Disable the built-in crash handler.\n" \
167 "				Useful for debugging.\n" \
168 "\n"
169 
170 #define BACKTRACE \
171 "	-backtrace dir		Generate a backtrace in the specified\n" \
172 "				directory on abnormal termination.\n" \
173 "				Useful for debugging.\n" \
174 "\n"
175 
176 #define BACKTRACECHILDREN \
177 "	-backtrace dir		Instructs the program to spawn\n" \
178 "				sqlr-connection processes with the same\n" \
179 "				backtrace option and argument.\n" \
180 "\n"
181