Ravenports generated: 30 Dec 2022 02:48
[ravenports.git] / bucket_CD / autoselect-ssl
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               autoselect-ssl
4 VERSION=                2
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:779: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 5 variants of SSL installed on a system:
34  openssl10, openssl11, openssl30, libressl, 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: openssl30, libressl, openssl11,
45 libressl-devel, openssl10.  The program will exec the first variant that
46 it finds.
47
48
49 [FILE:39:manifests/plist.single]
50 bin/
51  c_rehash
52  nc
53  ocspcheck
54  openssl
55
56
57 [FILE:742:files/LICENSE_ISC]
58 Copyright (c) 2019, The Ravenports Project.
59
60 Permission to use, copy, modify, and/or distribute this software for any
61 purpose with or without fee is hereby granted, provided that the above
62 copyright notice and this permission notice appear in all copies.
63
64 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
65 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
66 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
67 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
68 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
69 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
70 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
71
72
73 [FILE:350:files/Makefile]
74 all: generic
75
76 autoselect.c: autoselect.c.in
77         sed -e "s|%%SSL_VARIANT%%|${SSL_VARIANT}|" \
78             -e "s|%%PREFIX%%|${PREFIX}|g" ${.ALLSRC} > ${.TARGET}
79
80 generic: autoselect.c
81         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
82
83 install:
84 .for prog in openssl c_rehash nc ocspcheck
85         ${BSD_INSTALL_PROGRAM} generic ${DESTDIR}${PREFIX}/bin/${prog}
86 .endfor
87
88
89 [FILE:2961:files/autoselect.c.in]
90 /*
91  * This program runs one of the five SSL variants supported by ravenports.
92  * The first priority is the variant specified by SSL_VARIANT environment
93  * variable.  The second priority is the SSL default defined by the
94  * ravenadm profile that builds this file.  The remaining priority is:
95  *   openssl30
96  *   libressl
97  *   openssl11
98  *   libressl-devel
99  *   openssl10
100  *
101  * If no SSL variant is installed, an error message will be displayed,
102  * otherwise the requested program will be executed.
103  */
104
105 #include <stdio.h>
106 #include <stdlib.h>
107 #include <string.h>
108 #include <unistd.h>
109
110 int
111 main(int argc, char **argv)
112 {
113         int x;
114         char *override;
115         char *ALPHA   = "openssl30";
116         char *BRAVO   = "libressl";
117         char *CHARLIE = "openssl11";
118         char *DELTA   = "libressl-devel";
119         char *ECHO    = "openssl10";
120         char *ZULU    = "%%SSL_VARIANT%%";
121         char *sslver  = NULL;
122         char *cmd;
123         char recommand[1024];
124
125         /*
126          * Get the last path element of the program name being executed
127          */
128         cmd = strrchr(argv[0], '/');
129         if (cmd != NULL)
130                 cmd++;
131         else
132                 cmd = argv[0];
133
134         override = getenv("SSL_VARIANT");
135         if (override != NULL) {
136                 if (strcmp (override, ALPHA) == 0) {
137                         sslver = ALPHA;
138                 } else if (strcmp (override, BRAVO) == 0) {
139                         sslver = BRAVO;
140                 } else if (strcmp (override, CHARLIE) == 0) {
141                         sslver = CHARLIE;
142                 } else if (strcmp (override, DELTA) == 0) {
143                         sslver = DELTA;
144                 } else if (strcmp (override, ECHO) == 0) {
145                         sslver = ECHO;
146                 } else {
147                         printf ("Invalid SSL_VARIANT value: %s\n",
148                                 override);
149                         exit(1);
150                 }
151                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
152                         sslver, cmd);
153         }
154
155         if (sslver == NULL) {
156                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
157                         ZULU, cmd);
158                 if (access(recommand, F_OK) != -1) { sslver = ZULU; };
159         }
160         if (sslver == NULL && ZULU != ALPHA) {
161                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
162                         ALPHA, cmd);
163                 if (access(recommand, F_OK) != -1) { sslver = ALPHA; };
164         }
165         if (sslver == NULL && ZULU != BRAVO) {
166                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
167                         BRAVO, cmd);
168                 if (access(recommand, F_OK) != -1) { sslver = BRAVO; };
169         }
170         if (sslver == NULL && ZULU != CHARLIE) {
171                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
172                         CHARLIE, cmd);
173                 if (access(recommand, F_OK) != -1) { sslver = CHARLIE; };
174         }
175         if (sslver == NULL && ZULU != DELTA) {
176                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
177                         DELTA, cmd);
178                 if (access(recommand, F_OK) != -1) { sslver = DELTA; };
179         }
180         if (sslver == NULL && ZULU != ECHO) {
181                 snprintf(recommand, 1024, "%%PREFIX%%/%s/bin/%s",
182                         ECHO, cmd);
183                 if (access(recommand, F_OK) != -1) { sslver = ECHO; };
184         }
185         if (sslver == NULL) {
186                 printf ("No version of %s is installed.\n", cmd);
187                 exit(1);
188         }
189
190         argv[0] = recommand;
191         execv(recommand, argv);
192
193         /*
194          * Execution failed, so write out an error message
195          */
196         printf ("Command execution failed: %s\n", recommand);
197         printf ("               arguments:");
198         for (x = 1; x < argc; x++)
199                 printf (" %s", argv[x]);
200         printf ("\n");
201         exit (1);
202 }
203