예제 #1
0
static
DWORD
DumpShareInfo(
    PSHARE_INFO_502 pShareInfo
    )
{
    DWORD dwError = 0;
    DWORD dwAllowUserCount = 0;
    PWSTR* ppwszAllowUsers = NULL;
    DWORD dwDenyUserCount = 0;
    PWSTR* ppwszDenyUsers = NULL;
    BOOLEAN bReadOnly = FALSE;
    PSTR pszUserName = NULL;
    DWORD dwIndex = 0;

    dwError = PrintStringAttribute("name", pShareInfo->shi502_netname);
    BAIL_ON_SRVSVC_ERROR(dwError);

    dwError = PrintStringAttribute("path", pShareInfo->shi502_path);
    BAIL_ON_SRVSVC_ERROR(dwError);

    dwError = PrintStringAttribute("comment", pShareInfo->shi502_remark);
    BAIL_ON_SRVSVC_ERROR(dwError);

    if (pShareInfo->shi502_security_descriptor)
    {
        dwError = DeconstructSecurityDescriptor(
            pShareInfo->shi502_reserved,
            (PSECURITY_DESCRIPTOR_RELATIVE) pShareInfo->shi502_security_descriptor,
            &dwAllowUserCount,
            &ppwszAllowUsers,
            &dwDenyUserCount,
            &ppwszDenyUsers,
            &bReadOnly);
        BAIL_ON_SRVSVC_ERROR(dwError);

        if (dwAllowUserCount)
        {
            printf("allow=");

            for (dwIndex = 0; dwIndex < dwAllowUserCount; dwIndex++)
            {
                dwError = LwWc16sToMbs(ppwszAllowUsers[dwIndex], &pszUserName);
                BAIL_ON_SRVSVC_ERROR(dwError);

                printf("%s", pszUserName);
                if (dwIndex < dwAllowUserCount - 1)
                {
                    printf(",");
                }
            }

            printf("\n");
        }

        if (dwDenyUserCount)
        {
            printf("deny=");

            for (dwIndex = 0; dwIndex < dwDenyUserCount; dwIndex++)
            {
                dwError = LwWc16sToMbs(ppwszDenyUsers[dwIndex], &pszUserName);
                BAIL_ON_SRVSVC_ERROR(dwError);

                printf("%s", pszUserName);
                if (dwIndex < dwDenyUserCount - 1)
                {
                    printf(",");
                }
            }

            printf("\n");
        }

        printf("read_only=%s\n", bReadOnly ? "true" : "false");
    }

cleanup:

    FreeStringArray(dwAllowUserCount, ppwszAllowUsers);
    FreeStringArray(dwDenyUserCount, ppwszDenyUsers);

    return dwError;

error:

    goto cleanup;
}
예제 #2
0
파일: netshare.c 프로젝트: twistround/pbis
DWORD
NetExecSetInfo(
    NET_SHARE_ADD_OR_SET_INFO_PARAMS ShareSetInfo
    )
{
    static const DWORD dwLevel = 502;

    DWORD dwError = 0;
    SHARE_INFO_502 newShareInfo = {0};
    PSHARE_INFO_502 pShareInfo = NULL;
    DWORD dwParmErr = 0;
    PSECURITY_DESCRIPTOR_RELATIVE pSecDesc = NULL;
    DWORD dwSecDescSize = 0;
    DWORD dwAllowUserCount = 0;
    PWSTR* ppwszAllowUsers = NULL;
    DWORD dwDenyUserCount = 0;
    PWSTR* ppwszDenyUsers = NULL;
    BOOLEAN bReadOnly = FALSE;

    dwError = NetShareGetInfoW(
        ShareSetInfo.pwszServerName,
        ShareSetInfo.pwszShareName,
        dwLevel,
        (PBYTE*)(&pShareInfo));
    BAIL_ON_LTNET_ERROR(dwError);

    dwError = DeconstructSecurityDescriptor(
        pShareInfo->shi502_reserved,
        (PSECURITY_DESCRIPTOR_RELATIVE) pShareInfo->shi502_security_descriptor,
        &dwAllowUserCount,
        &ppwszAllowUsers,
        &dwDenyUserCount,
        &ppwszDenyUsers,
        &bReadOnly);
    BAIL_ON_LTNET_ERROR(dwError);

    newShareInfo = *pShareInfo;

    if (ShareSetInfo.pwszShareName)
    {
        newShareInfo.shi502_netname = ShareSetInfo.pwszShareName;
    }

    if (ShareSetInfo.pwszComment)
    {
        newShareInfo.shi502_remark = ShareSetInfo.pwszComment;
    }

    if (ShareSetInfo.pwszPath)
    {
        newShareInfo.shi502_path = ShareSetInfo.pwszPath;
    }

    dwError = ConstructSecurityDescriptor(
        ShareSetInfo.dwAllowUserCount
        || ShareSetInfo.bClearAllow ? ShareSetInfo.dwAllowUserCount : dwAllowUserCount,
        ShareSetInfo.dwAllowUserCount || ShareSetInfo.bClearAllow ? ShareSetInfo.ppwszAllowUsers : ppwszAllowUsers,
        ShareSetInfo.dwDenyUserCount || ShareSetInfo.bClearDeny ? ShareSetInfo.dwDenyUserCount : dwDenyUserCount,
        ShareSetInfo.dwDenyUserCount || ShareSetInfo.bClearDeny ? ShareSetInfo.ppwszDenyUsers : ppwszDenyUsers,
        ShareSetInfo.bReadOnly || ShareSetInfo.bReadWrite ? (ShareSetInfo.bReadOnly && !ShareSetInfo.bReadWrite) : bReadOnly,
        &pSecDesc,
        &dwSecDescSize);
    BAIL_ON_LTNET_ERROR(dwError);

    newShareInfo.shi502_type = pShareInfo->shi502_type;
    newShareInfo.shi502_reserved = dwSecDescSize;
    newShareInfo.shi502_security_descriptor = (PBYTE) pSecDesc;

    dwError = NetShareSetInfoW(
        ShareSetInfo.pwszServerName,
        ShareSetInfo.pwszShareName,
        dwLevel,
        (PBYTE)&newShareInfo,
        &dwParmErr);
    BAIL_ON_LTNET_ERROR(dwError);

cleanup:

    if (pShareInfo)
    {
        LwNetFreeMemory(pShareInfo);
    }

    LwNetFreeWC16StringArray(dwAllowUserCount, ppwszAllowUsers);
    LwNetFreeWC16StringArray(dwDenyUserCount, ppwszDenyUsers);

    LTNET_SAFE_FREE_MEMORY(pSecDesc);

    return dwError;

error:

    goto cleanup;
}
예제 #3
0
static
DWORD
SetInfo(
    int argc,
    char** ppszArgv
    )
{
    static const DWORD dwLevel = 502;

    DWORD dwError = 0;
    SHARE_INFO_502 newShareInfo = {0};
    PSHARE_INFO_502 pShareInfo = NULL;
    DWORD dwParmErr = 0;
    PSECURITY_DESCRIPTOR_RELATIVE pSecDesc = NULL;
    DWORD dwSecDescSize = 0;
    DWORD dwAllowUserCount = 0;
    PWSTR* ppwszAllowUsers = NULL;
    DWORD dwDenyUserCount = 0;
    PWSTR* ppwszDenyUsers = NULL;
    BOOLEAN bReadOnly = FALSE;

    dwError = ParseShareArgs(
        argc,
        ppszArgv);
    BAIL_ON_SRVSVC_ERROR(dwError);

    dwError = NetShareGetInfo(
        gState.pwszServerName,
        gState.pwszTarget,
        dwLevel,
        OUT_PPVOID(&pShareInfo));
    BAIL_ON_SRVSVC_ERROR(dwError);

    dwError = DeconstructSecurityDescriptor(
        pShareInfo->shi502_reserved,
        (PSECURITY_DESCRIPTOR_RELATIVE) pShareInfo->shi502_security_descriptor,
        &dwAllowUserCount,
        &ppwszAllowUsers,
        &dwDenyUserCount,
        &ppwszDenyUsers,
        &bReadOnly);
    BAIL_ON_SRVSVC_ERROR(dwError);

    newShareInfo = *pShareInfo;

    if (gState.pwszName)
    {
        newShareInfo.shi502_netname = gState.pwszName;
    }

    if (gState.pwszComment)
    {
        newShareInfo.shi502_remark = gState.pwszComment;
    }

    if (gState.pwszPath)
    {
        newShareInfo.shi502_path = gState.pwszPath;
    }

    dwError = ConstructSecurityDescriptor(
        gState.dwAllowUserCount || gState.bClearAllow ? gState.dwAllowUserCount : dwAllowUserCount,
        gState.dwAllowUserCount || gState.bClearAllow ? gState.ppwszAllowUsers : ppwszAllowUsers,
        gState.dwDenyUserCount || gState.bClearDeny ? gState.dwDenyUserCount : dwDenyUserCount,
        gState.dwDenyUserCount || gState.bClearDeny ? gState.ppwszDenyUsers : ppwszDenyUsers,
        gState.bReadOnly || gState.bReadWrite ? (gState.bReadOnly && !gState.bReadWrite) : bReadOnly,
        &pSecDesc,
        &dwSecDescSize);
    BAIL_ON_SRVSVC_ERROR(dwError);

    newShareInfo.shi502_type = pShareInfo->shi502_type;
    newShareInfo.shi502_reserved = dwSecDescSize;
    newShareInfo.shi502_security_descriptor = (PBYTE) pSecDesc;

    dwError = NetShareSetInfo(
        gState.pwszServerName,
        gState.pwszTarget,
        dwLevel,
        &newShareInfo,
        &dwParmErr);
    BAIL_ON_SRVSVC_ERROR(dwError);

cleanup:

    if (pShareInfo)
    {
        SrvSvcFreeMemory(pShareInfo);
    }

    FreeStringArray(dwAllowUserCount, ppwszAllowUsers);
    FreeStringArray(dwDenyUserCount, ppwszDenyUsers);

    LW_SAFE_FREE_MEMORY(pSecDesc);

    return dwError;

error:

    goto cleanup;
}