885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose/*
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose Unix SMB/CIFS implementation.
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose Winbind client API
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose Copyright (C) Gerald (Jerry) Carter 2007
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose This library is free software; you can redistribute it and/or
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose modify it under the terms of the GNU Lesser General Public
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose License as published by the Free Software Foundation; either
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose version 3 of the License, or (at your option) any later version.
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose This library is distributed in the hope that it will be useful,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose Library General Public License for more details.
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose You should have received a copy of the GNU Lesser General Public License
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose*/
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose/* Required Headers */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose#include "libwbclient.h"
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose/* Convert a binary GUID to a character string */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit BosewbcErr wbcGuidToString(const struct wbcGuid *guid,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose char **guid_string)
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose{
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose char *result;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose result = (char *)wbcAllocateMemory(37, 1, NULL);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose if (result == NULL) {
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose return WBC_ERR_NO_MEMORY;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose }
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose snprintf(result, 37,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->time_low, guid->time_mid,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->time_hi_and_version,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->clock_seq[0],
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->clock_seq[1],
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->node[0], guid->node[1],
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->node[2], guid->node[3],
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->node[4], guid->node[5]);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose *guid_string = result;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose return WBC_ERR_SUCCESS;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose}
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose/* @brief Convert a character string to a binary GUID */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit BosewbcErr wbcStringToGuid(const char *str,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose struct wbcGuid *guid)
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose{
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose uint32_t time_low;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose uint32_t time_mid, time_hi_and_version;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose uint32_t clock_seq[2];
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose uint32_t node[6];
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose int i;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose if (!guid) {
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose wbc_status = WBC_ERR_INVALID_PARAM;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose BAIL_ON_WBC_ERROR(wbc_status);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose }
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose if (!str) {
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose wbc_status = WBC_ERR_INVALID_PARAM;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose BAIL_ON_WBC_ERROR(wbc_status);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose }
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose if (11 == sscanf(str, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose &time_low, &time_mid, &time_hi_and_version,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose &clock_seq[0], &clock_seq[1],
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose wbc_status = WBC_ERR_SUCCESS;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose } else if (11 == sscanf(str, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose &time_low, &time_mid, &time_hi_and_version,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose &clock_seq[0], &clock_seq[1],
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose &node[0], &node[1], &node[2], &node[3], &node[4], &node[5])) {
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose wbc_status = WBC_ERR_SUCCESS;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose }
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose BAIL_ON_WBC_ERROR(wbc_status);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->time_low = time_low;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->time_mid = time_mid;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->time_hi_and_version = time_hi_and_version;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->clock_seq[0] = clock_seq[0];
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->clock_seq[1] = clock_seq[1];
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose for (i=0;i<6;i++) {
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose guid->node[i] = node[i];
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose }
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose wbc_status = WBC_ERR_SUCCESS;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bosedone:
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose return wbc_status;
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose}