open-license-manager
2014-10-14 fc983a64e86a0b756c91db501d660bc02edd1609
linux test ok
4个文件已修改
94 ■■■■ 已修改文件
.cproject 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/base/base.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/pc-identifiers.c 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/library/Os_Linux_test.cpp 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.cproject
@@ -48,24 +48,8 @@
                            </tool>
                        </toolChain>
                    </folderInfo>
                    <folderInfo id="cdt.managedbuild.toolchain.gnu.base.1941555127.1870622802" name="/" resourcePath="src">
                        <toolChain id="cdt.managedbuild.toolchain.gnu.base.1412322516" name="cdt.managedbuild.toolchain.gnu.base" superClass="cdt.managedbuild.toolchain.gnu.base" unusedChildren="">
                            <tool id="cdt.managedbuild.tool.gnu.archiver.base.924146927" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base.1063978701"/>
                            <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.455275272" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base.1465609732">
                                <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.743382935" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
                            </tool>
                            <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1499862118" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base.589770174">
                                <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.16209603" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
                            </tool>
                            <tool id="cdt.managedbuild.tool.gnu.c.linker.base.1934467411" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base.1466986479"/>
                            <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.263030776" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base.233385682"/>
                            <tool id="cdt.managedbuild.tool.gnu.assembler.base.1495429968" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base.1674253564">
                                <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1348112222" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
                            </tool>
                        </toolChain>
                    </folderInfo>
                    <sourceEntries>
                        <entry excluding="**/win/**" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
                        <entry excluding="scratch/linux|**/win/**" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
                        <entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="test"/>
                    </sourceEntries>
                </configuration>
src/library/base/base.h
@@ -25,7 +25,7 @@
#endif
/* #define _DEBUG */
/*
#define cmax(a,b) \
   ({ __typeof__ (a) _a = (a); \
       __typeof__ (b) _b = (b); \
@@ -35,7 +35,7 @@
   ({ __typeof__ (a) _a = (a); \
       __typeof__ (b) _b = (b); \
     _a < _b ? _a : _b; })
*/
typedef enum  {
    FUNC_RET_OK, FUNC_RET_NOT_AVAIL, FUNC_RET_ERROR, FUNC_RET_BUFFER_TOO_SMALL
} FUNCTION_RETURN;
src/library/pc-identifiers.c
@@ -9,6 +9,7 @@
#include "pc-identifiers.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "base/base64.h"
#include "base/base.h"
#ifdef __linux__
@@ -18,7 +19,12 @@
#include <Windows.h>
#endif
//FIXME if adapterinfo or diskinfo fail the function fails
static FUNCTION_RETURN generate_disk_pc_id(PcIdentifier * identifiers,
        unsigned int * num_identifiers, bool use_label);
static FUNCTION_RETURN generate_ethernet_pc_id(PcIdentifier * identifiers,
        unsigned int * num_identifiers, int use_mac);
static FUNCTION_RETURN generate_default_pc_id(PcIdentifier * identifiers,
                                              unsigned int * num_identifiers) {
    size_t adapter_num, disk_num;
@@ -39,17 +45,20 @@
        *num_identifiers = disk_num * adapter_num;
        function_return = FUNC_RET_OK;
    } else {
        adapterInfoPtr = (OsAdapterInfo*)malloc((*num_identifiers) * sizeof(OsAdapterInfo));
        adapterInfoPtr = (OsAdapterInfo*) malloc(
                (*num_identifiers) * sizeof(OsAdapterInfo));
        adapter_num = *num_identifiers;
        result_adapterInfos = getAdapterInfos(adapterInfoPtr, &adapter_num);
        if (result_adapterInfos != FUNC_RET_OK && result_adapterInfos != FUNC_RET_BUFFER_TOO_SMALL) {
            free(diskInfoPtr);
        if (result_adapterInfos != FUNC_RET_OK
                && result_adapterInfos != FUNC_RET_BUFFER_TOO_SMALL) {
            free(adapterInfoPtr);
            return generate_disk_pc_id(identifiers, num_identifiers, false);
        }
        diskInfoPtr = (DiskInfo*)malloc((*num_identifiers) * sizeof(DiskInfo));
        disk_num = *num_identifiers;
        result_diskinfos = getDiskInfos(adapterInfoPtr, &disk_num);
        if (result_diskinfos != FUNC_RET_OK && result_diskinfos != FUNC_RET_BUFFER_TOO_SMALL) {
        result_diskinfos = getDiskInfos(diskInfoPtr, &disk_num);
        if (result_diskinfos != FUNC_RET_OK
                && result_diskinfos != FUNC_RET_BUFFER_TOO_SMALL) {
            free(diskInfoPtr);
            free(adapterInfoPtr);
            return generate_ethernet_pc_id(identifiers, num_identifiers, true);
@@ -66,13 +75,12 @@
                    goto end;
                }
                for (k = 0; k < 6; k++)
                    identifiers[array_index][k] =
                    diskInfoPtr[i].disk_sn[k + 2]
                    identifiers[array_index][k] = diskInfoPtr[i].disk_sn[k + 2]
                    ^ adapterInfoPtr[j].mac_address[k + 2];
            }
        }
end:
        *num_identifiers = min(*num_identifiers, adapter_num * disk_num);
        *num_identifiers = cmin(*num_identifiers, adapter_num * disk_num);
        free(diskInfoPtr);
        free(adapterInfoPtr);
    }
@@ -82,39 +90,41 @@
static FUNCTION_RETURN generate_ethernet_pc_id(PcIdentifier * identifiers,
                                               unsigned int * num_identifiers, int use_mac) {
    FUNCTION_RETURN result_adapterInfos;
    unsigned int i, j, k;
    unsigned int j, k;
    OsAdapterInfo *adapterInfos;
    size_t defined_adapters, adapters = 0;
    if (identifiers == NULL || *num_identifiers == 0) {
        result_adapterInfos = getAdapterInfos(NULL, &adapters);
        if (result_adapterInfos == FUNC_RET_OK || result_adapterInfos == FUNC_RET_BUFFER_TOO_SMALL) {
        if (result_adapterInfos == FUNC_RET_OK
                || result_adapterInfos == FUNC_RET_BUFFER_TOO_SMALL) {
            *num_identifiers = adapters;
            result_adapterInfos=FUNC_RET_OK;
        }
    } else {
        defined_adapters = adapters = *num_identifiers;
        adapterInfos = (OsAdapterInfo*)malloc(adapters * sizeof(OsAdapterInfo));
        adapterInfos = (OsAdapterInfo*) malloc(
                adapters * sizeof(OsAdapterInfo));
        result_adapterInfos = getAdapterInfos(adapterInfos, &adapters);
        if (result_adapterInfos == FUNC_RET_BUFFER_TOO_SMALL || result_adapterInfos == FUNC_RET_OK){
        if (result_adapterInfos == FUNC_RET_BUFFER_TOO_SMALL
                || result_adapterInfos == FUNC_RET_OK) {
            for (j = 0; j < adapters; j++) {
                for (k = 0; k < 6; k++)
                if (use_mac) {
                    identifiers[j][k] = adapterInfos[j].mac_address[k + 2];
                }
                else {
                    } else {
                    //use ip
                    if (k < 4) {
                        identifiers[j][k] = adapterInfos[j].ipv4_address[k];
                    }
                    else {
                        } else {
                        //padding
                        identifiers[j][k] = 42;
                    }
                }
            }
            result_adapterInfos = (adapters>defined_adapters ? FUNC_RET_BUFFER_TOO_SMALL : FUNC_RET_OK);
            result_adapterInfos = (
                    adapters > defined_adapters ?
                            FUNC_RET_BUFFER_TOO_SMALL : FUNC_RET_OK);
        }
        free(adapterInfos);
    }
@@ -125,7 +135,7 @@
                                           unsigned int * num_identifiers, bool use_label) {
    size_t disk_num, available_disk_info = 0;
    FUNCTION_RETURN result_diskinfos;
    unsigned int i, k, j;
    unsigned int i, j;
    int defined_identifiers;
    char firstChar;
    DiskInfo * diskInfos;
@@ -151,8 +161,7 @@
    if (identifiers == NULL) {
        free(diskInfos);
        return FUNC_RET_OK;
    }
    else if (available_disk_info > defined_identifiers) {
    } else if (available_disk_info > defined_identifiers) {
        free(diskInfos);
        return FUNC_RET_BUFFER_TOO_SMALL;
    }
@@ -162,13 +171,14 @@
        if (use_label){
            if (diskInfos[i].label[0] != 0){
                memset(identifiers[j], 0, sizeof(PcIdentifier)); //!!!!!!!
                strncpy(identifiers[j], diskInfos[i].label, sizeof(PcIdentifier));
                strncpy(identifiers[j], diskInfos[i].label,
                        sizeof(PcIdentifier));
                j++;
            }
        }
        else{
        } else {
            if (diskInfos[i].disk_sn[0] != 0){
                memcpy(identifiers[j], &diskInfos[i].disk_sn[2], sizeof(PcIdentifier));
                memcpy(identifiers[j], &diskInfos[i].disk_sn[2],
                        sizeof(PcIdentifier));
                j++;
            }
        }
@@ -269,8 +279,7 @@
    //concat_identifiers = (PcIdentifier *) malloc(concatIdentifiersSize);
    memcpy(&concat_identifiers[0], identifier1, sizeof(PcIdentifier));
    memcpy(&concat_identifiers[1], identifier2, sizeof(PcIdentifier));
    b64_data = base64(concat_identifiers, concatIdentifiersSize,
                      &b64_size);
    b64_data = base64(concat_identifiers, concatIdentifiersSize, &b64_size);
    if (b64_size > sizeof(PcSignature)) {
        return FUNC_RET_BUFFER_TOO_SMALL;
    }
test/library/Os_Linux_test.cpp
@@ -43,7 +43,12 @@
        if (string(adapter_info[i].description) == "lo") {
            BOOST_CHECK_NE(adapter_info[i].ipv4_address[0], 0);
        } else {
            BOOST_CHECK_NE(adapter_info[i].mac_address[0], 0);
            bool mac_is_0 = true;
            for(int j=0;j<6;j++){
                mac_is_0 = mac_is_0 && (adapter_info[i].mac_address[j]==0);
            }
            BOOST_CHECK_MESSAGE( !mac_is_0,
                    "Mac address for interface " << adapter_info[i].description << " is 0");
        }
    }
    free(adapter_info);