3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
#include "ink_config.h"
30
#include "ParseRules.h"
33
/***************************************************************************
35
* An Inktomi Traffic Server plugin license key should look like:
39
* XXXXX is a 5 digit alphanumeric id used by plugin vendors to
40
* assign to their customers.
42
* EEEE is the hex encoding of the expiration date. It's the number
43
* of days from January 1, 1970. If a plugin has no expiration date,
44
* 0000 can be used instead.
46
* DDDDDD is the INK_MD5 encoding of some combination of the following
47
* strings: "Inktomi Traffic Server", "Plugin Name", "XXXXXEEEE".
50
***************************************************************************/
53
PluginDB::CheckLicenseResultStr[] = {
61
PluginDB::license_custid_len = 5;
63
PluginDB::license_expire_len = 4;
65
PluginDB::license_digest_len = 6;
67
PluginDB::license_total_len = PluginDB::license_custid_len +
68
PluginDB::license_expire_len + PluginDB::license_digest_len;
70
PluginDB::PluginDB(const char *plugin_db_file)
72
info_table = ink_hash_table_create(InkHashTableKeyType_String);
73
ReadPluginDB(plugin_db_file);
76
PluginDB::~PluginDB(void)
78
ink_hash_table_destroy_and_free_values(info_table);
82
PluginDB::ReadPluginDB(const char *plugin_db_file)
84
FILE *pdb = fopen(plugin_db_file, "r");
86
Warning("unable to open plugin.db file '%s': %d, %s", plugin_db_file, errno, strerror(errno));
93
PluginDB::PluginInfo * pinfo = new PluginDB::PluginInfo();
95
while (fgets(line, sizeof(line) - 1, pdb) != NULL) {
97
while (*p && ParseRules::is_wslfcr(*p)) {
100
if ((*p == '\0') || (*p == '#')) {
103
// We have a non-comment and non-blank line
105
// Nullify the newline character
111
if (plugin_obj[0] != '\0' && (pinfo->name[0] != '\0' || pinfo->license[0] != '\0')) {
112
ink_hash_table_insert(info_table, (InkHashTableKey) plugin_obj, (InkHashTableValue) pinfo);
113
plugin_obj[0] = '\0';
114
pinfo = new PluginDB::PluginInfo();
117
for (i = 0; p[i] != '\0' && p[i] != ']' && i < 255; i++) {
118
pinfo->name[i] = p[i];
120
pinfo->name[i] = '\0';
123
if (strstr(p, "Object=")) {
124
p = p + sizeof("Object=") - 1;
125
for (i = 0; p[i] != '\0' && i < 255; i++) {
126
plugin_obj[i] = p[i];
128
plugin_obj[i] = '\0';
129
} else if (strstr(p, "License=")) {
130
p = p + sizeof("License=") - 1;
131
for (i = 0; p[i] != '\0' && i < 255; i++) {
132
pinfo->license[i] = p[i];
134
pinfo->license[i] = '\0';
139
if (plugin_obj[0] != '\0' && (pinfo->name[0] != '\0' || pinfo->license[0] != '\0')) {
140
ink_hash_table_insert(info_table, (InkHashTableKey) plugin_obj, (InkHashTableValue) pinfo);
147
PluginDB::CheckLicenseResult PluginDB::CheckLicense(const char *plugin_obj)
154
expire_str[PluginDB::license_expire_len + 1];
159
PluginDB::PluginInfo * pinfo;
164
ht_entry = ink_hash_table_lookup_entry(info_table,
165
(InkHashTableKey) plugin_obj);
166
if (ht_entry != NULL) {
167
pinfo = (PluginDB::PluginInfo *) ink_hash_table_entry_value(info_table, ht_entry);
169
return PluginDB::license_missing;
172
if (strlen(pinfo->license) != PluginDB::license_total_len) {
173
return PluginDB::license_invalid;
176
snprintf(buffer, sizeof(buffer), "Inktomi Traffic Server %s ", pinfo->name);
177
strncat(buffer, pinfo->license, PluginDB::license_custid_len + PluginDB::license_expire_len);
179
ink_code_incr_md5_init(&md5_context);
180
ink_code_incr_md5_update(&md5_context, buffer, strlen(buffer));
181
ink_code_incr_md5_final(buffer_md5, &md5_context);
182
// coverity[uninit_use_in_call]
183
ink_code_md5_stringify(buffer_md5_str, sizeof(buffer_md5_str), buffer_md5);
185
if (strncmp(buffer_md5_str,
186
pinfo->license + PluginDB::license_custid_len
187
+ PluginDB::license_expire_len, PluginDB::license_digest_len) != 0) {
188
return PluginDB::license_invalid;
191
strncpy(expire_str, pinfo->license + PluginDB::license_custid_len, PluginDB::license_expire_len);
192
expire_str[PluginDB::license_expire_len] = '\0';
194
expire_days = strtoul(expire_str, &end_ptr, 16);
196
if (expire_days != 0) {
198
time_now = time(NULL);
199
if ((unsigned long) time_now > expire_days * (60 * 60 * 24)) {
200
return PluginDB::license_expired;
204
return PluginDB::license_ok;