summaryrefslogtreecommitdiff
path: root/src/usr.bin
diff options
context:
space:
mode:
authorjsing <>2014-08-30 15:59:43 +0000
committerjsing <>2014-08-30 15:59:43 +0000
commit9c7115b7ab2fa3c3ee53653676df013b71fd364d (patch)
tree99e0f0d46331bff9808ea0119c92b52e9ce8221f /src/usr.bin
parent3016f0d916cff2fa5c93e769e25ded6c34e7fb73 (diff)
downloadopenbsd-9c7115b7ab2fa3c3ee53653676df013b71fd364d.tar.gz
openbsd-9c7115b7ab2fa3c3ee53653676df013b71fd364d.tar.bz2
openbsd-9c7115b7ab2fa3c3ee53653676df013b71fd364d.zip
Convert openssl(1) version to new option/usage handling.
Diffstat (limited to 'src/usr.bin')
-rw-r--r--src/usr.bin/openssl/version.c124
1 files changed, 90 insertions, 34 deletions
diff --git a/src/usr.bin/openssl/version.c b/src/usr.bin/openssl/version.c
index afad0c3e11..ee4792b249 100644
--- a/src/usr.bin/openssl/version.c
+++ b/src/usr.bin/openssl/version.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: version.c,v 1.1 2014/08/26 17:47:25 jsing Exp $ */ 1/* $OpenBSD: version.c,v 1.2 2014/08/30 15:59:43 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -135,40 +135,97 @@
135#include <openssl/rc4.h> 135#include <openssl/rc4.h>
136#endif 136#endif
137 137
138static struct {
139 int cflags;
140 int date;
141 int dir;
142 int options;
143 int platform;
144 int version;
145} version_config;
146
147static int
148version_all_opts(struct option *opt, char *arg)
149{
150 version_config.cflags = 1;
151 version_config.date = 1;
152 version_config.dir= 1;
153 version_config.options = 1;
154 version_config.platform = 1;
155 version_config.version = 1;
156
157 return (0);
158}
159
160static struct option version_options[] = {
161 {
162 .name = "a",
163 .desc = "All information (same as setting all other flags)",
164 .type = OPTION_FUNC,
165 .func = version_all_opts,
166 },
167 {
168 .name = "b",
169 .desc = "Date the current version of OpenSSL was built",
170 .type = OPTION_FLAG,
171 .opt.flag = &version_config.date,
172 },
173 {
174 .name = "d",
175 .desc = "OPENSSLDIR value",
176 .type = OPTION_FLAG,
177 .opt.flag = &version_config.dir,
178 },
179 {
180 .name = "f",
181 .desc = "Compilation flags",
182 .type = OPTION_FLAG,
183 .opt.flag = &version_config.cflags,
184 },
185 {
186 .name = "o",
187 .desc = "Option information",
188 .type = OPTION_FLAG,
189 .opt.flag = &version_config.options,
190 },
191 {
192 .name = "p",
193 .desc = "Platform settings",
194 .type = OPTION_FLAG,
195 .opt.flag = &version_config.platform,
196 },
197 {
198 .name = "v",
199 .desc = "Current OpenSSL version",
200 .type = OPTION_FLAG,
201 .opt.flag = &version_config.version,
202 },
203 {},
204};
205
206static void
207version_usage(void)
208{
209 fprintf(stderr, "usage: version [-abdfopv]\n");
210 options_usage(version_options);
211}
212
138int version_main(int, char **); 213int version_main(int, char **);
139 214
140int 215int
141version_main(int argc, char **argv) 216version_main(int argc, char **argv)
142{ 217{
143 int i, ret = 0; 218 memset(&version_config, 0, sizeof(version_config));
144 int cflags = 0, version = 0, date = 0, options = 0, platform = 0,
145 dir = 0;
146 219
147 if (argc == 1) 220 if (options_parse(argc, argv, version_options, NULL) != 0) {
148 version = 1; 221 version_usage();
149 for (i = 1; i < argc; i++) { 222 return (1);
150 if (strcmp(argv[i], "-v") == 0)
151 version = 1;
152 else if (strcmp(argv[i], "-b") == 0)
153 date = 1;
154 else if (strcmp(argv[i], "-f") == 0)
155 cflags = 1;
156 else if (strcmp(argv[i], "-o") == 0)
157 options = 1;
158 else if (strcmp(argv[i], "-p") == 0)
159 platform = 1;
160 else if (strcmp(argv[i], "-d") == 0)
161 dir = 1;
162 else if (strcmp(argv[i], "-a") == 0)
163 date = version = cflags = options = platform = dir = 1;
164 else {
165 BIO_printf(bio_err, "usage:version -[avbofpd]\n");
166 ret = 1;
167 goto end;
168 }
169 } 223 }
170 224
171 if (version) { 225 if (argc == 1)
226 version_config.version = 1;
227
228 if (version_config.version) {
172 if (SSLeay() == SSLEAY_VERSION_NUMBER) { 229 if (SSLeay() == SSLEAY_VERSION_NUMBER) {
173 printf("%s\n", SSLeay_version(SSLEAY_VERSION)); 230 printf("%s\n", SSLeay_version(SSLEAY_VERSION));
174 } else { 231 } else {
@@ -177,11 +234,11 @@ version_main(int argc, char **argv)
177 SSLeay_version(SSLEAY_VERSION)); 234 SSLeay_version(SSLEAY_VERSION));
178 } 235 }
179 } 236 }
180 if (date) 237 if (version_config.date)
181 printf("%s\n", SSLeay_version(SSLEAY_BUILT_ON)); 238 printf("%s\n", SSLeay_version(SSLEAY_BUILT_ON));
182 if (platform) 239 if (version_config.platform)
183 printf("%s\n", SSLeay_version(SSLEAY_PLATFORM)); 240 printf("%s\n", SSLeay_version(SSLEAY_PLATFORM));
184 if (options) { 241 if (version_config.options) {
185 printf("options: "); 242 printf("options: ");
186 printf("%s ", BN_options()); 243 printf("%s ", BN_options());
187#ifndef OPENSSL_NO_RC4 244#ifndef OPENSSL_NO_RC4
@@ -198,11 +255,10 @@ version_main(int argc, char **argv)
198#endif 255#endif
199 printf("\n"); 256 printf("\n");
200 } 257 }
201 if (cflags) 258 if (version_config.cflags)
202 printf("%s\n", SSLeay_version(SSLEAY_CFLAGS)); 259 printf("%s\n", SSLeay_version(SSLEAY_CFLAGS));
203 if (dir) 260 if (version_config.dir)
204 printf("%s\n", SSLeay_version(SSLEAY_DIR)); 261 printf("%s\n", SSLeay_version(SSLEAY_DIR));
205end:
206 262
207 return (ret); 263 return (0);
208} 264}