1 /* version.c: versioning functions
2 *
3 * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. The name "Carnegie Mellon University" must not be used to
18 * endorse or promote products derived from this software without
19 * prior written permission. For permission or any legal
20 * details, please contact
21 * Carnegie Mellon University
22 * Center for Technology Transfer and Enterprise Creation
23 * 4615 Forbes Avenue
24 * Suite 302
25 * Pittsburgh, PA 15213
26 * (412) 268-7393, fax: (412) 268-7395
27 * innovation@andrew.cmu.edu
28 *
29 * 4. Redistributions of any form whatsoever must retain the following
30 * acknowledgment:
31 * "This product includes software developed by Computing Services
32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
33 *
34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41 */
42
43 #include <config.h>
44
45 #include <sasl/sasl.h>
46 #include <sys/utsname.h>
47 #ifdef HAVE_KRB
48 #include <krb.h>
49 #endif
50 #ifdef HAVE_UCDSNMP
51 #include <ucd-snmp/version.h>
52 #endif
53
54 #include <string.h>
55 #include "version.h"
56 #include "map.h"
57 #include "cyr_lock.h"
58 #include "nonblock.h"
59 #include "idle.h"
60
61 #ifdef USE_SIEVE
62 #include "sieve/sieve_interface.h"
63 #endif
64
65 static char id_resp_command[MAXIDVALUELEN];
66 static char id_resp_arguments[MAXIDVALUELEN] = "";
67
68 /* EXTRA_IDENT is a hack to add some version information for which compile
69 * was used to build this version (at CMU, but we don't care what you do with
70 * it).
71 */
72
73 #ifdef EXTRA_IDENT
74 #define CYRUS_VERSION PACKAGE_VERSION "-" EXTRA_IDENT
75 #else
76 #define CYRUS_VERSION PACKAGE_VERSION
77 #endif
78
cyrus_version(void)79 EXPORTED const char *cyrus_version(void)
80 {
81 return CYRUS_VERSION;
82 }
83
84 /*
85 * Grab the command line args for the ID response.
86 */
id_getcmdline(int argc,char ** argv)87 EXPORTED void id_getcmdline(int argc, char **argv)
88 {
89 snprintf(id_resp_command, MAXIDVALUELEN, "%s", *argv);
90 while (--argc > 0) {
91 snprintf(id_resp_arguments + strlen(id_resp_arguments),
92 MAXIDVALUELEN - strlen(id_resp_arguments),
93 "%s%s", *++argv, (argc > 1) ? " " : "");
94 }
95 }
96
97 /*
98 * Output the ID response.
99 * We do NOT close the parameter list so other stuff can be added later.
100 */
id_response(struct protstream * pout)101 EXPORTED void id_response(struct protstream *pout)
102 {
103 struct utsname os;
104 const char *sasl_imp;
105 int sasl_ver;
106 char env_buf[MAXIDVALUELEN+1];
107
108 prot_printf(pout, "* ID ("
109 "\"name\" \"Cyrus IMAPD\""
110 " \"version\" \"%s\""
111 " \"vendor\" \"Project Cyrus\""
112 " \"support-url\" \"https://www.cyrusimap.org\"",
113 CYRUS_VERSION);
114
115 /* add the os info */
116 if (uname(&os) != -1)
117 prot_printf(pout,
118 " \"os\" \"%s\""
119 " \"os-version\" \"%s\"",
120 os.sysname, os.release);
121
122 #ifdef ID_SAVE_CMDLINE
123 /* add the command line info */
124 prot_printf(pout, " \"command\" \"%s\"", id_resp_command);
125 if (strlen(id_resp_arguments)) {
126 prot_printf(pout, " \"arguments\" \"%s\"", id_resp_arguments);
127 } else {
128 prot_printf(pout, " \"arguments\" NIL");
129 }
130 #endif
131
132 /* SASL information */
133 snprintf(env_buf, MAXIDVALUELEN,"Built w/Cyrus SASL %d.%d.%d",
134 SASL_VERSION_MAJOR, SASL_VERSION_MINOR, SASL_VERSION_STEP);
135
136 sasl_version(&sasl_imp, &sasl_ver);
137 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
138 "; Running w/%s %d.%d.%d", sasl_imp,
139 (sasl_ver & 0xFF000000) >> 24,
140 (sasl_ver & 0x00FF0000) >> 16,
141 (sasl_ver & 0x0000FFFF));
142
143 /* add the environment info */
144 #ifdef DB_VERSION_STRING
145 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
146 "; Built w/%s", DB_VERSION_STRING);
147 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
148 "; Running w/%s", db_version(NULL, NULL, NULL));
149 #endif
150 #ifdef HAVE_SSL
151 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
152 "; Built w/%s", OPENSSL_VERSION_TEXT);
153 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
154 "; Running w/%s", SSLeay_version(SSLEAY_VERSION));
155 #ifdef EGD_SOCKET
156 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
157 " (with EGD)");
158 #endif
159 #endif
160 #ifdef HAVE_ZLIB
161 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
162 "; Built w/zlib %s", ZLIB_VERSION);
163 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
164 "; Running w/zlib %s", zlibVersion());
165 #endif
166 #ifdef USE_SIEVE
167 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
168 "; %s", SIEVE_VERSION);
169 #endif
170 #ifdef HAVE_LIBWRAP
171 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
172 "; TCP Wrappers");
173 #endif
174 #ifdef HAVE_UCDSNMP
175 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
176 "; UCD-SNMP %s", VersionInfo);
177 #endif
178 #ifdef HAVE_NETSNMP
179 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
180 "; NET-SNMP");
181 #endif
182 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
183 "; mmap = %s", map_method_desc);
184 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
185 "; lock = %s", lock_method_desc);
186 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
187 "; nonblock = %s", nonblock_method_desc);
188 #ifdef HAVE_KRB
189 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
190 " (%s)", krb4_version);
191 #endif
192 if (idle_method_desc)
193 snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
194 "; idle = %s", idle_method_desc);
195
196 prot_printf(pout, " \"environment\" \"%s\"", env_buf);
197 }
198