Merge pull request #20 from willamowius/master
Fix bugs found by Coverity
| | |
| | | #include <fstream> |
| | | #include <sstream> |
| | | #include <stdlib.h> |
| | | #include <math.h> |
| | | #include "pc-identifiers.h" |
| | | #include "LicenseReader.h" |
| | | #include "base/StringUtils.h" |
| | |
| | | } |
| | | if (has_client_sig) { |
| | | PcSignature str_code; |
| | | strncpy(str_code, client_signature.c_str(), sizeof(str_code)); |
| | | strncpy(str_code, client_signature.c_str(), sizeof(str_code)-1); |
| | | EVENT_TYPE event = validate_pc_signature(str_code); |
| | | if (event != LICENSE_OK) { |
| | | er.addEvent(event, SVRT_ERROR); |
| | |
| | | double secs = difftime( |
| | | seconds_from_epoch(to_date.c_str()), |
| | | time(NULL)); |
| | | license->days_left = (int) secs / 60 * 60 * 24; |
| | | license->days_left = round(secs / (60 * 60 * 24)); |
| | | } |
| | | } |
| | | } |
| | |
| | | FullLicenseInfo::UNUSED_SOFTWARE_VERSION); |
| | | int to_sw_version = ini.GetLongValue(productNamePtr, |
| | | "to_sw_version", FullLicenseInfo::UNUSED_SOFTWARE_VERSION); |
| | | string extra_data = trim_copy( |
| | | ini.GetValue(productNamePtr, "extra_data", "")); |
| | | FullLicenseInfo licInfo(*it, product, license_signature, |
| | | (int) license_version, from_date, to_date, client_signature, |
| | | from_sw_version, to_sw_version); |
| | | from_sw_version, to_sw_version, extra_data); |
| | | licenseInfoOut.push_back(licInfo); |
| | | atLeastOneLicenseComplete = true; |
| | | } else { |
| | |
| | | if (folder == 0) { |
| | | folder = "/tmp"; |
| | | } |
| | | strcpy(logpath, folder); |
| | | strcat(logpath, "/open-license.log"); |
| | | strncpy(logpath, folder, MAX_PATH); |
| | | strncat(logpath, "/open-license.log", MAX_PATH - strlen(logpath)); |
| | | #else |
| | | int plen=GetTempPath(MAX_PATH,logpath); |
| | | if(plen == 0) { |
| | | fprintf(stderr, "Error getting temporary directory path"); |
| | | } |
| | | strcat(logpath,"open-license.log"); |
| | | strncat(logpath, "open-license.log", MAX_PATH - strlen(logpath)); |
| | | #endif |
| | | } |
| | | |
| | | void _log(char* format, ...) { |
| | | void _log(const char* format, ...) { |
| | | char logpath[MAX_PATH]; |
| | | va_list args; |
| | | char * buffer; |
| | |
| | | #define LOG_ERROR(M, ...) |
| | | #endif |
| | | |
| | | void _log(char* format, ...); |
| | | void _log(const char* format, ...); |
| | | void _shutdown_log(); |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | if (pComment) { |
| | | DeleteString(a_pComment); |
| | | a_pComment = pComment; |
| | | CopyString(a_pComment); |
| | | (void)CopyString(a_pComment); |
| | | } |
| | | Delete(a_pSection, a_pKey); |
| | | iKey = keyval.end(); |
| | |
| | | |
| | | FUNCTION_RETURN f_return = FUNC_RET_OK; |
| | | struct ifaddrs *ifaddr, *ifa; |
| | | int family, i, n, if_name_position; |
| | | int family, n = 0, if_name_position; |
| | | unsigned int if_num, if_max; |
| | | //char host[NI_MAXHOST]; |
| | | char *ifnames; |
| | |
| | | strncpy(&ifnames[if_num * NI_MAXHOST], ifa->ifa_name, NI_MAXHOST); |
| | | if (adapterInfos != NULL && if_num < *adapter_info_size) { |
| | | strncpy(adapterInfos[if_num].description, ifa->ifa_name, |
| | | NI_MAXHOST); |
| | | NI_MAXHOST-1); |
| | | } |
| | | if_name_position = if_num; |
| | | if_num++; |
| | |
| | | } else if (family == AF_PACKET && ifa->ifa_data != NULL) { |
| | | struct sockaddr_ll *s1 = (struct sockaddr_ll*) ifa->ifa_addr; |
| | | if (adapterInfos != NULL && if_name_position < *adapter_info_size) { |
| | | for (i = 0; i < 6; i++) { |
| | | for (int i = 0; i < 6; i++) { |
| | | adapterInfos[if_name_position].mac_address[i] = |
| | | s1->sll_addr[i]; |
| | | #ifdef _DEBUG |
| | |
| | | struct mntent *ent; |
| | | |
| | | int maxDrives, currentDrive, i, drive_found; |
| | | __ino64_t *statDrives; |
| | | DiskInfo *tmpDrives; |
| | | FILE *aFile; |
| | | DIR *disk_by_uuid_dir, *disk_by_label; |
| | | struct dirent *dir; |
| | | __ino64_t *statDrives = NULL; |
| | | DiskInfo *tmpDrives = NULL; |
| | | FILE *aFile = NULL; |
| | | DIR *disk_by_uuid_dir = NULL, *disk_by_label = NULL; |
| | | struct dirent *dir = NULL; |
| | | FUNCTION_RETURN result; |
| | | |
| | | if (diskInfos != NULL) { |
| | |
| | | aFile = setmntent("/proc/mounts", "r"); |
| | | if (aFile == NULL) { |
| | | /*proc not mounted*/ |
| | | free(tmpDrives); |
| | | free(statDrives); |
| | | return FUNC_RET_ERROR; |
| | | } |
| | | |
| | |
| | | if (drive_found == -1) { |
| | | LOG_DEBUG("mntent: %s %s %d\n", ent->mnt_fsname, ent->mnt_dir, |
| | | (unsigned long int)mount_stat.st_ino); |
| | | strcpy(tmpDrives[currentDrive].device, ent->mnt_fsname); |
| | | strncpy(tmpDrives[currentDrive].device, ent->mnt_fsname, 255-1); |
| | | statDrives[currentDrive] = mount_stat.st_ino; |
| | | drive_found = currentDrive; |
| | | currentDrive++; |
| | |
| | | if (stat(cur_dir, &sym_stat) == 0) { |
| | | for (i = 0; i < currentDrive; i++) { |
| | | if (sym_stat.st_ino == statDrives[i]) { |
| | | strncpy(tmpDrives[i].label, dir->d_name, 255); |
| | | strncpy(tmpDrives[i].label, dir->d_name, 255-1); |
| | | printf("label %d %s %s\n", i, tmpDrives[i].label, |
| | | tmpDrives[i].device); |
| | | } |
| | |
| | | strcat(proc_path, pidStr); |
| | | strcat(proc_path, "/exe"); |
| | | |
| | | int ch = readlink(proc_path, path, MAX_PATH); |
| | | int ch = readlink(proc_path, path, MAX_PATH-1); |
| | | if (ch != -1) { |
| | | path[ch] = '\0'; |
| | | strncpy(buffer, path, ch); |
| | |
| | | |
| | | #include "../base/base.h" |
| | | #include <stddef.h> |
| | | #include <string.h> |
| | | #include <ctype.h> |
| | | #include <sys/types.h> |
| | | #include <unistd.h> |
| | | //definition of size_t |
| | | #include <stdlib.h> |
| | | #ifdef __unix__ |
| | |
| | | if (use_label) { |
| | | if (diskInfos[i].label[0] != 0) { |
| | | memset(identifiers[j], 0, sizeof(PcIdentifier)); //!!!!!!! |
| | | strncpy(identifiers[j], diskInfos[i].label, |
| | | strncpy((char*)identifiers[j], diskInfos[i].label, |
| | | sizeof(PcIdentifier)); |
| | | j++; |
| | | } |
| | |
| | | PcSignature pc_identifier_out) { |
| | | //TODO base62 encoding, now uses base64 |
| | | PcIdentifier concat_identifiers[2]; |
| | | char* b64_data; |
| | | char* b64_data = NULL; |
| | | int b64_size = 0; |
| | | size_t concatIdentifiersSize = sizeof(PcIdentifier) * 2; |
| | | //concat_identifiers = (PcIdentifier *) malloc(concatIdentifiersSize); |
| | |
| | | memcpy(&concat_identifiers[1], identifier2, sizeof(PcIdentifier)); |
| | | b64_data = base64(concat_identifiers, concatIdentifiersSize, &b64_size); |
| | | if (b64_size > sizeof(PcSignature)) { |
| | | free(b64_data); |
| | | return FUNC_RET_BUFFER_TOO_SMALL; |
| | | } |
| | | sprintf(pc_identifier_out, "%.4s-%.4s-%.4s-%.4s", &b64_data[0], |
| | |
| | | PcIdentifier identifier2_out, PcSignature pc_signature_in) { |
| | | //TODO base62 encoding, now uses base64 |
| | | |
| | | unsigned char * concat_identifiers; |
| | | unsigned char * concat_identifiers = NULL; |
| | | char base64ids[17]; |
| | | int identifiers_size; |
| | | |
| | |
| | | &base64ids[8], &base64ids[12]); |
| | | concat_identifiers = unbase64(base64ids, 16, &identifiers_size); |
| | | if (identifiers_size > sizeof(PcIdentifier) * 2) { |
| | | free(concat_identifiers); |
| | | return FUNC_RET_BUFFER_TOO_SMALL; |
| | | } |
| | | memcpy(identifier1_out, concat_identifiers, sizeof(PcIdentifier)); |
| | |
| | | for (i = 0; i < 2; i++) { |
| | | current_strategy_id = strategy_from_pc_id(user_identifiers[i]); |
| | | if (current_strategy_id == STRATEGY_UNKNOWN) { |
| | | free(calculated_identifiers); |
| | | return LICENSE_MALFORMED; |
| | | } |
| | | if (current_strategy_id != previous_strategy_id) { |
| | |
| | | #include "license-generator.h" |
| | | |
| | | int main(int argc, const char *argv[]) { |
| | | //license::LicenseGenerator lic; |
| | | return license::LicenseGenerator::generateLicense(argc, argv); |
| | | |
| | | } |
| | |
| | | |
| | | po::options_description LicenseGenerator::configureProgramOptions() { |
| | | po::options_description common("General options"); |
| | | common.add_options()("help,h", "print help message and exit.") // |
| | | ("verbose,v", "print more information.") // |
| | | common.add_options() |
| | | ("help,h", "print help message and exit.") |
| | | ("verbose,v", "print more information.") |
| | | ("output,o", po::value<string>(), "Output file name. If not specified the " |
| | | "license will be printed in standard output"); // |
| | | "license will be printed in standard output") |
| | | ; |
| | | po::options_description licenseGeneration("License Generation"); |
| | | licenseGeneration.add_options()("private_key,p", po::value<string>(), |
| | | licenseGeneration.add_options() |
| | | ("private_key,p", po::value<string>(), |
| | | "Specify an alternate file for the primary key to be used. " |
| | | "If not specified the internal primary key will be used.") // |
| | | "If not specified the internal primary key will be used.") |
| | | ("begin_date,b", po::value<string>(), |
| | | "Specify the start of the validity for this license. " |
| | | " Format YYYYMMDD. If not specified defaults to today") // |
| | | " Format YYYYMMDD. If not specified defaults to today") |
| | | ("expire_date,e", po::value<string>(), |
| | | "Specify the expire date for this license. " |
| | | " Format YYYYMMDD. If not specified the license won't expire") // |
| | | " Format YYYYMMDD. If not specified the license won't expire") |
| | | ("client_signature,s", po::value<string>(), |
| | | "The signature of the pc that requires the license. " |
| | | "It should be in the format XXXX-XXXX-XXXX-XXXX." |
| | | " If not specified the license " |
| | | "won't be linked to a specific pc.") // |
| | | "won't be linked to a specific pc.") |
| | | ("start_version,t", po::value<unsigned int>()->default_value(0 |
| | | /*FullLicenseInfo.UNUSED_SOFTWARE_VERSION*/, "All Versions"), |
| | | "Specify the first version of the software this license apply to.") // |
| | | "Specify the first version of the software this license apply to.") |
| | | ("end_version,n", po::value<unsigned int>()->default_value(0 |
| | | /*FullLicenseInfo.UNUSED_SOFTWARE_VERSION*/, "All Versions"), |
| | | "Specify the last version of the software this license apply to."); // |
| | | "Specify the last version of the software this license apply to.") |
| | | ("extra_data,x", po::value<string>(), "Specify extra data to be included into the license") |
| | | ; |
| | | po::options_description visibleOptions; |
| | | visibleOptions.add(common).add(licenseGeneration); |
| | | return visibleOptions; |
| | | } |
| | | |
| | | vector<FullLicenseInfo> LicenseGenerator::parseLicenseInfo( |
| | | po::variables_map vm) { |
| | | const po::variables_map& vm) { |
| | | string begin_date = FullLicenseInfo::UNUSED_TIME; |
| | | string end_date = FullLicenseInfo::UNUSED_TIME; |
| | | if (vm.count("expire_date")) { |
| | |
| | | string client_signature = ""; |
| | | if (vm.count("client_signature")) { |
| | | client_signature = vm["client_signature"].as<string>(); |
| | | //fixme match + and / |
| | | /*regex e("(A-Za-z0-9){4}-(A-Za-z0-9){4}-(A-Za-z0-9){4}-(A-Za-z0-9){4}"); |
| | | regex e("[A-Za-z0-9\\+/]{4}-[A-Za-z0-9\\+/]{4}-[A-Za-z0-9\\+/]{4}-[A-Za-z0-9\\+/]{4}"); |
| | | if (!regex_match(client_signature, e)) { |
| | | cerr << endl << "Client signature not recognized: " |
| | | << client_signature |
| | | << " Please enter a valid signature in format XXXX-XXXX-XXXX-XXXX" |
| | | << endl; |
| | | exit(2); |
| | | }*/ |
| | | } |
| | | } |
| | | string extra_data = ""; |
| | | if (vm.count("extra_data")) { |
| | |
| | | LicenseGenerator(); |
| | | static void printHelp(const char* prog_name, const po::options_description& options); |
| | | static po::options_description configureProgramOptions(); |
| | | static vector<FullLicenseInfo> parseLicenseInfo(po::variables_map vm); |
| | | static vector<FullLicenseInfo> parseLicenseInfo(const po::variables_map& vm); |
| | | static void generateAndOutputLicenses(const po::variables_map& vm, |
| | | ostream& outputFile); |
| | | static string normalize_date(const std::string& s); |
| | |
| | | continue; |
| | | PcSignature pcsig; |
| | | strncpy(pcsig, reference_signatures[i].c_str(), |
| | | sizeof(PcSignature)); |
| | | sizeof(PcSignature)-1); |
| | | EVENT_TYPE val_result = validate_pc_signature(pcsig); |
| | | BOOST_TEST_CHECKPOINT("Verifying signature: "); |
| | | BOOST_CHECK_EQUAL(val_result, LICENSE_OK); |
| | |
| | | argv[2] = fname.c_str(); |
| | | argv[3] = "test"; |
| | | int retCode = LicenseGenerator::generateLicense(argc, argv); |
| | | delete (argv); |
| | | delete[] (argv); |
| | | BOOST_CHECK_EQUAL(retCode, 0); |
| | | BOOST_ASSERT(fs::exists(fname)); |
| | | CSimpleIniA ini; |