/* Editor Settings: expandtabs and use 4 spaces for indentation
 * ex: set softtabstop=4 tabstop=8 expandtab shiftwidth=4: *
 */

/*
 * 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:
 *
 *        srvsvc_netservergetinfo.c
 *
 * Abstract:
 *
 *        Likewise Server Service (srvsvc) RPC client and server
 *
 *        SrvSvcNetServerGetInfo server API
 *
 * Authors: Rafal Szczesniak (rafal@likewise.com)
 */

#include "includes.h"

// NT is 500
#define PLATFORM_ID 500
#define VERSION_MAJOR 5
#define VERSION_MINOR 1
// TOOD: Move SV_TYPE_* definitions so we can use them here
#if 1
#define SERVER_TYPE 0x00001003
#else
#define SERVER_TYPE (
    SV_TYPE_WORKSTATION | \
    SV_TYPE_SERVER | \
    SV_TYPE_NT | \
    0 )
#endif

NET_API_STATUS
SrvSvcNetrServerGetInfo(
    /* [in] */ handle_t b,
    /* [in] */ wchar16_t *server_name,
    /* [in] */ UINT32 level,
    /* [out] */ srvsvc_NetSrvInfo *info
    )
{
    DWORD dwError = ERROR_SUCCESS;
    CHAR szHostname[64] = {0};
    PWSTR pwszHostname = NULL;
    SERVER_INFO_100 *pInfo100 = NULL;
    SERVER_INFO_101 *pInfo101 = NULL;
    SERVER_INFO_102 *pInfo102 = NULL;

    dwError = gethostname(szHostname, sizeof(szHostname));
    BAIL_ON_SRVSVC_ERROR(dwError);

    if (server_name)
    {
        dwError = SrvSvcSrvAllocateWC16String(
                      &pwszHostname,
                      server_name);
    }
    else
    {
        dwError = SrvSvcSrvAllocateWC16StringFromCString(
                      &pwszHostname,
                      szHostname);
    }
    BAIL_ON_SRVSVC_ERROR(dwError);

    switch (level)
    {
    case 100:
        dwError = SrvSvcSrvAllocateMemory(
                      sizeof(*pInfo100),
                      OUT_PPVOID(&pInfo100));
        BAIL_ON_SRVSVC_ERROR(dwError);

        pInfo100->sv100_name = pwszHostname;
        pwszHostname = NULL;

        info->info100 = pInfo100;

        break;

    case 101:
        dwError = SrvSvcSrvAllocateMemory(
                      sizeof(*pInfo101),
                      OUT_PPVOID(&pInfo101));
        BAIL_ON_SRVSVC_ERROR(dwError);

         dwError = SrvSvcSrvAllocateWC16StringFromCString(
                      &pInfo101->sv101_comment,
                      SERVER_COMMENT_STRING);
        BAIL_ON_SRVSVC_ERROR(dwError);

        pInfo101->sv101_platform_id    = PLATFORM_ID;
        pInfo101->sv101_name           = pwszHostname;
        pwszHostname = NULL;
        pInfo101->sv101_version_major  = VERSION_MAJOR;
        pInfo101->sv101_version_minor  = VERSION_MINOR;
        pInfo101->sv101_type           = SERVER_TYPE;

        info->info101 = pInfo101;

        break;

    case 102:
        dwError = SrvSvcSrvAllocateMemory(
                      sizeof(*pInfo102),
                      OUT_PPVOID(&pInfo102));
        BAIL_ON_SRVSVC_ERROR(dwError);

         dwError = SrvSvcSrvAllocateWC16StringFromCString(
                      &pInfo102->sv102_comment,
                      SERVER_COMMENT_STRING);
        BAIL_ON_SRVSVC_ERROR(dwError);

        pInfo102->sv102_platform_id    = PLATFORM_ID;
        pInfo102->sv102_name           = pwszHostname;
        pwszHostname = NULL;
        pInfo102->sv102_version_major  = VERSION_MAJOR;
        pInfo102->sv102_version_minor  = VERSION_MINOR;
        pInfo102->sv102_type           = SERVER_TYPE;
        pInfo102->sv102_users          = 0;
        pInfo102->sv102_disc           = 0;
        pInfo102->sv102_hidden         = 0;
        pInfo102->sv102_announce       = 0;
        pInfo102->sv102_anndelta       = 0;
        pInfo102->sv102_licenses       = 5;
        pInfo102->sv102_userpath       = NULL;

        info->info102 = pInfo102;

        break;

    default:
        dwError = ERROR_NOT_SUPPORTED;
        BAIL_ON_SRVSVC_ERROR(dwError);
    }

cleanup:
    return dwError;

error:

    switch (level)
    {
    case 100:
        SrvSvcSrvFreeServerInfo100(pInfo100);
        break;

    case 101:
        SrvSvcSrvFreeServerInfo101(pInfo101);
        break;

    case 102:
        SrvSvcSrvFreeServerInfo102(pInfo102);
        break;
    }

    memset(info, 0, sizeof(*info));

    goto cleanup;
}


/*
local variables:
mode: c
c-basic-offset: 4
indent-tabs-mode: nil
tab-width: 4
end:
*/
