Ravenports generated: 15 Jan 2020 17:51
[ravenports.git] / bucket_CD / autoselect-ssl
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               autoselect-ssl
4 VERSION=                1
5 KEYWORDS=               security
6 VARIANTS=               standard
7 SDESC[standard]=        Dynamic links to SSL program variants
8 HOMEPAGE=               none
9 CONTACT=                nobody
10
11 DOWNLOAD_GROUPS=        none
12 SPKGS[standard]=        single
13
14 OPTIONS_AVAILABLE=      none
15 OPTIONS_STANDARD=       none
16
17 LICENSE=                ISCL:single
18 LICENSE_FILE=           ISCL:{{FILESDIR}}/LICENSE_ISC
19 LICENSE_SCHEME=         solo
20
21 do-extract:
22         @${MKDIR} ${WRKSRC}
23         ${CP} ${FILESDIR}/Makefile ${WRKSRC}/
24         ${CP} ${FILESDIR}/autoselect.c.in ${WRKSRC}/
25
26 [FILE:761:descriptions/desc.single]
27 This package provides:
28   bin/openssl
29   bin/c_rehash
30   bin/nc
31   bin/ocspcheck
32
33 There can be up to 4 variants of SSL installed on a system:
34  openssl, libressl, openssl-devel, and libressl-devel
35
36 These selector programs will exec one of variants based on the ravenadm's
37 set SSL default and the SSL_VARIANT environment variable.
38
39 The environment variable has the highest priority.  If SSL_VARIANT is
40 set, the search will be limited to /raven/bin/ssl_${SSL_VARIANT}/${ARG0}.
41 If that doesn't exist, an appropriate error will be produced instead.
42
43 Without the environment directive, the SSL default of the ravenadm profile
44 is checked first, and then this order: openssl, libressl, openssl-devel,
45 libressl-devel.  The program will exec the first variant that it finds.
46
47
48 [FILE:39:manifests/plist.single]
49 bin/
50  c_rehash
51  nc
52  ocspcheck
53  openssl
54
55
56 [FILE:742:files/LICENSE_ISC]
57 Copyright (c) 2019, The Ravenports Project.
58
59 Permission to use, copy, modify, and/or distribute this software for any
60 purpose with or without fee is hereby granted, provided that the above
61 copyright notice and this permission notice appear in all copies.
62
63 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
64 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
65 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
66 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
67 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
68 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
69 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
70
71
72 [FILE:350:files/Makefile]
73 all: generic
74
75 autoselect.c: autoselect.c.in
76         sed -e "s|%%SSL_VARIANT%%|${SSL_VARIANT}|" \
77             -e "s|%%PREFIX%%|${PREFIX}|g" ${.ALLSRC} > ${.TARGET}
78
79 generic: autoselect.c
80         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
81
82 install:
83 .for prog in openssl c_rehash nc ocspcheck
84         ${BSD_INSTALL_PROGRAM} generic ${DESTDIR}${PREFIX}/bin/${prog}
85 .endfor
86
87
88 [FILE:2691:files/autoselect.c.in]
89 /*
90  * This program runs one of the four SSL variants supported by ravenports.
91  * The first priority is the variant specified by SSL_VARIANT environment
92  * variable.  The second priority is the SSL default defined by the
93  * ravenadm profile that builds this file.  The remaining priority is:
94  *   openssl
95  *   libressl
96  *   openssl-devel
97  *   libressl-devel
98  *
99  * If no SSL variant is installed, an error message will be displayed,
100  * otherwise the requested program will be executed.
101  */
102
103 #include <stdio.h>
104 #include <stdlib.h>
105 #include <string.h>
106 #include <unistd.h>
107
108 int
109 main(int argc, char **argv)
110 {
111         int x;
112         char *override;
113         char *ALPHA   = "openssl";
114         char *BRAVO   = "libressl";
115         char *CHARLIE = "openssl-devel";
116         char *DELTA   = "libressl-devel";
117         char *ZULU    = "%%SSL_VARIANT%%";
118         char *sslver  = NULL;
119         char *cmd;
120         char recommand[1024];
121
122         /*
123          * Get the last path element of the program name being executed
124          */
125         cmd = strrchr(argv[0], '/');
126         if (cmd != NULL)
127                 cmd++;
128         else
129                 cmd = argv[0];
130
131         override = getenv("SSL_VARIANT");
132         if (override != NULL) {
133                 if (strcmp (override, ALPHA) == 0) {
134                         sslver = ALPHA;
135                 } else if (strcmp (override, BRAVO) == 0) {
136                         sslver = BRAVO;
137                 } else if (strcmp (override, CHARLIE) == 0) {
138                         sslver = CHARLIE;
139                 } else if (strcmp (override, DELTA) == 0) {
140                         sslver = DELTA;
141                 } else {
142                         printf ("Invalid SSL_VARIANT value: %s\n",
143                                 override);
144                         exit(1);
145                 }
146                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
147                         sslver, cmd);
148         }
149
150         if (sslver == NULL) {
151                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
152                         ZULU, cmd);
153                 if (access(recommand, F_OK) != -1) { sslver = ZULU; };
154         }
155         if (sslver == NULL && ZULU != ALPHA) {
156                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
157                         ALPHA, cmd);
158                 if (access(recommand, F_OK) != -1) { sslver = ALPHA; };
159         }
160         if (sslver == NULL && ZULU != BRAVO) {
161                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
162                         BRAVO, cmd);
163                 if (access(recommand, F_OK) != -1) { sslver = BRAVO; };
164         }
165         if (sslver == NULL && ZULU != CHARLIE) {
166                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
167                         CHARLIE, cmd);
168                 if (access(recommand, F_OK) != -1) { sslver = CHARLIE; };
169         }
170         if (sslver == NULL && ZULU != DELTA) {
171                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
172                         DELTA, cmd);
173                 if (access(recommand, F_OK) != -1) { sslver = DELTA; };
174         }
175         if (sslver == NULL) {
176                 printf ("No version of %s is installed.\n", cmd);
177                 exit(1);
178         }
179
180         argv[0] = recommand;
181         execv(recommand, argv);
182
183         /*
184          * Execution failed, so write out an error message
185          */
186         printf ("Command execution failed: %s\n", recommand);
187         printf ("               arguments:");
188         for (x = 1; x < argc; x++)
189                 printf (" %s", argv[x]);
190         printf ("\n");
191         exit (1);
192 }
193