/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*-
 * ex: set softtabstop=4 tabstop=8 expandtab shiftwidth=4: *
 * Editor Settings: expandtabs and use 4 spaces for indentation */

/*
 * Copyright Likewise Software
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.  You should have received a copy of the GNU General
 * Public License along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * LIKEWISE SOFTWARE MAKES THIS SOFTWARE AVAILABLE UNDER OTHER LICENSING
 * TERMS AS WELL.  IF YOU HAVE ENTERED INTO A SEPARATE LICENSE AGREEMENT
 * WITH LIKEWISE SOFTWARE, THEN YOU MAY ELECT TO USE THE SOFTWARE UNDER THE
 * TERMS OF THAT SOFTWARE LICENSE AGREEMENT INSTEAD OF THE TERMS OF THE GNU
 * GENERAL PUBLIC LICENSE, NOTWITHSTANDING THE ABOVE NOTICE.  IF YOU
 * HAVE QUESTIONS, OR WISH TO REQUEST A COPY OF THE ALTERNATE LICENSING
 * TERMS OFFERED BY LIKEWISE SOFTWARE, PLEASE CONTACT LIKEWISE SOFTWARE AT
 * license@likewisesoftware.com
 */

/*
 * Copyright (C) Likewise Software. All rights reserved.
 *
 * Module Name:
 *
 *        samdbattr.c
 *
 * Abstract:
 *
 *
 *      Likewise SAM Database Provider
 *
 *      SAM object attribute handling routines
 *
 * Authors: Rafal Szczesniak (rafal@likewise.com)
 *
 */

#ifndef __SAMDB_ATTR_H__
#define __SAMDB_ATTR_H__


typedef enum _SAMDB_ATTR_TYPE
{
    SAMDB_ATTR_TYPE_UNKNOWN = 0,
    SAMDB_ATTR_TYPE_TEXT,
    SAMDB_ATTR_TYPE_INT32,
    SAMDB_ATTR_TYPE_INT64,
    SAMDB_ATTR_TYPE_BOOLEAN,
    SAMDB_ATTR_TYPE_BLOB,
    SAMDB_ATTR_TYPE_DATETIME,
    SAMDB_ATTR_TYPE_SECURITY_DESCRIPTOR

} SAMDB_ATTR_TYPE, *PSAMDB_ATTR_TYPE;


typedef VOID
(*PFN_FREE_ATTRIBUTE_VALUE)(
    PVOID Value
    );


typedef struct _SAMDB_ATTRIBUTE
{
    CHAR DbColumnName[SAMDB_COL_NAME_MAX_LEN];
    SAMDB_ATTR_TYPE AttributeType;
    PVOID Value;
    PFN_FREE_ATTRIBUTE_VALUE FreeFn;
} SAMDB_ATTRIBUTE, *PSAMDB_ATTRIBUTE;


typedef struct _SAMDB_ATTRIBUTE_VALUE_BLOB
{
    PVOID Value;
    DWORD Length;
} SAMDB_ATTRIBUTE_VALUE_BLOB, *PSAMDB_ATTRIBUTE_VALUE_BLOB;


typedef DWORD
(*PFN_TRANSFER_ATTRIBUTE_VALUE)(
    PSAMDB_ATTRIBUTE Source,
    PVOID Destination
    );


typedef struct _SAMDB_ATTRIBUTE_TRANSFER
{
    PSTR AttributeName;
    PVOID Destination;
    PFN_TRANSFER_ATTRIBUTE_VALUE TransferFn;
} SAMDB_ATTRIBUTE_TRANSFER, *PSAMDB_ATTRIBUTE_TRANSFER;


DWORD
SamDbBindAttributeValues(
    PSAMDB_CONTEXT DbContext,
    sqlite3_stmt* SqlStatement,
    PSAMDB_ATTRIBUTE AttributeValues,
    DWORD AttributeValuesCount
    );


DWORD
SamDbGetOutputAttributeValues(
    PSAMDB_CONTEXT DbContext,
    sqlite3_stmt* SqlStatement,
    PSAMDB_ATTRIBUTE OutputAttributes,
    DWORD OutputAttributesCount
    );


DWORD
SamDbTransferPointerValue(
    PSAMDB_ATTRIBUTE Source,
    PVOID Destination
    );


DWORD
SamDbTransferSid(
    PSAMDB_ATTRIBUTE Source,
    PVOID Destination
    );


DWORD
SamDbTransferWorkstationsArray(
    PSAMDB_ATTRIBUTE Source,
    PVOID Destination
    );


DWORD
SamDbTransferOwfPassword(
    PSAMDB_ATTRIBUTE Source,
    PVOID Destination
    );


DWORD
SamDbTransferLogonHoursArray(
    PSAMDB_ATTRIBUTE Source,
    PVOID Destination
    );


VOID
SamDbFreeAttributesContents(
    PSAMDB_ATTRIBUTE Attributes,
    DWORD AttributesCount
    );


VOID
SamDbFreeAttributes(
    PSAMDB_ATTRIBUTE Attributes,
    DWORD AttributesCount
    );


VOID
SamDbAttributeFreeSidString(
    PVOID Pointer
    );


VOID
SamDbAttributeFreePointer(
    PVOID Pointer
    );


VOID
SamDbAttributeFreeString(
    PVOID Pointer
    );


VOID
SamDbAttributeFreeBlob(
    PVOID Pointer
    );


DWORD
SamDbMarshalDomainObject(
    PSAMDB_ATTRIBUTE Attributes,
    DWORD AttributesCount,
    PSAMDB_OBJECT_INFO* pObject
    );


DWORD
SamDbMarshalUserObject(
    PSAMDB_ATTRIBUTE Attributes,
    DWORD AttributesCount,
    PSAMDB_OBJECT_INFO* pObject
    );


DWORD
SamDbMarshalLocalGroupObject(
    PSAMDB_ATTRIBUTE Attributes,
    DWORD AttributesCount,
    PSAMDB_OBJECT_INFO* pObject
    );


SAMDB_OBJECT_CLASS
SamDbMapObjectTypeToObjectClass(
    IN SAMDB_OBJECT_TYPE Type
    );


SAMDB_OBJECT_TYPE
SamDbMapObjectClassToObjectType(
    IN SAMDB_OBJECT_CLASS Class
    );


#endif /* __SAMDB_ATTR_H__ */
