' ########################################################################################
' Microsoft Windows
' File: LMShare.inc
' Contents: API function prototypes and data structures for the following groups of NT API functions:
' NetShare, NetSession, NetFile, NetConnection
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
'//
'// SHARE API
'//
#IF NOT %DEF(PBX_LMShare_PBI)
#DEFINE PBX_LMShare_PBI
%EQUATE `LMSHARE_INC = 1
#INCLUDE ONCE "Legacy/System/WTypes.inc"
#INCLUDE ONCE "Legacy/Platform/LMCons.inc"
#IF NOT %DEF(%LMSHARE)
 %LMSHARE = 1
'//
'// Function Prototypes - Share
'//
DECLARE FUNCTION NetShareAdd LIB "netapi32.dll" ALIAS "NetShareAdd" ( BYREF servername AS WSTRINGZ , BYVAL level AS QUAD , BYVAL buf AS BYTE PTR , BYREF parm_err AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetShareEnum LIB "netapi32.dll" ALIAS "NetShareEnum" ( BYREF servername AS WSTRINGZ , BYVAL level AS QUAD , BYREF bufptr AS ANY , BYVAL prefmaxlen AS QUAD , BYREF entriesread AS QUAD , BYREF totalentries AS QUAD , BYREF resume_handle AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetShareEnumSticky LIB "netapi32.dll" ALIAS "NetShareEnumSticky" ( BYREF servername AS WSTRINGZ , BYVAL level AS QUAD , BYREF bufptr AS ANY , BYVAL prefmaxlen AS QUAD , BYREF entriesread AS QUAD , BYREF totalentries AS QUAD , BYREF resume_handle AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetShareGetInfo LIB "netapi32.dll" ALIAS "NetShareGetInfo" ( BYREF servername AS WSTRINGZ , BYREF netname AS WSTRINGZ , BYVAL level AS QUAD , BYREF bufptr AS ANY ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetShareSetInfo LIB "netapi32.dll" ALIAS "NetShareSetInfo" ( BYREF servername AS WSTRINGZ , BYREF netname AS WSTRINGZ , BYVAL level AS QUAD , BYVAL buf AS BYTE PTR , BYREF parm_err AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetShareDel LIB "netapi32.dll" ALIAS "NetShareDel" ( BYREF servername AS WSTRINGZ , BYREF netname AS WSTRINGZ , BYVAL reserved AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetShareDelSticky LIB "netapi32.dll" ALIAS "NetShareDelSticky" ( BYREF servername AS WSTRINGZ , BYREF netname AS WSTRINGZ , BYVAL reserved AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetShareCheck LIB "netapi32.dll" ALIAS "NetShareCheck" ( BYREF servername AS WSTRINGZ , BYREF device AS WSTRINGZ , BYREF type AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetShareDelEx LIB "netapi32.dll" ALIAS "NetShareDelEx" ( BYREF servername AS WSTRINGZ , BYVAL level AS QUAD , BYVAL buf AS BYTE PTR ) AS QUAD ' NET_API_STATUS
'//
'// Data Structures - Share
'//
' // Size = 4 bytes
TYPE SHARE_INFO_0 DWORD
 shi0_netname AS WSTRINGZ PTR ' LMSTR shi0_netname
END TYPE
' // Size = 12 bytes
TYPE SHARE_INFO_1 DWORD
 shi1_netname AS WSTRINGZ PTR ' LMSTR shi1_netname
 shi1_type AS DWORD ' DWORD shi1_type
 shi1_remark AS WSTRINGZ PTR ' LMSTR shi1_remark
END TYPE
' // Size = 32 bytes
TYPE SHARE_INFO_2 DWORD
 shi2_netname AS WSTRINGZ PTR ' LMSTR shi2_netname
 shi2_type AS DWORD ' DWORD shi2_type
 shi2_remark AS WSTRINGZ PTR ' LMSTR shi2_remark
 shi2_permissions AS DWORD ' DWORD shi2_permissions
 shi2_max_uses AS DWORD ' DWORD shi2_max_uses
 shi2_current_uses AS DWORD ' DWORD shi2_current_uses
 shi2_path AS WSTRINGZ PTR ' LMSTR shi2_path
 shi2_passwd AS WSTRINGZ PTR ' LMSTR shi2_passwd
END TYPE
' // Size = 16 bytes
TYPE SHARE_INFO_501 DWORD
 shi501_netname AS WSTRINGZ PTR ' LMSTR shi501_netname
 shi501_type AS DWORD ' DWORD shi501_type
 shi501_remark AS WSTRINGZ PTR ' LMSTR shi501_remark
 shi501_flags AS DWORD ' DWORD shi501_flags
END TYPE
' // Size = 40 bytes
TYPE SHARE_INFO_502 DWORD
 shi502_netname AS WSTRINGZ PTR ' LMSTR shi502_netname
 shi502_type AS DWORD ' DWORD shi502_type
 shi502_remark AS WSTRINGZ PTR ' LMSTR shi502_remark
 shi502_permissions AS DWORD ' DWORD shi502_permissions
 shi502_max_uses AS DWORD ' DWORD shi502_max_uses
 shi502_current_uses AS DWORD ' DWORD shi502_current_uses
 shi502_path AS WSTRINGZ PTR ' LMSTR shi502_path
 shi502_passwd AS WSTRINGZ PTR ' LMSTR shi502_passwd
 shi502_reserved AS DWORD ' DWORD shi502_reserved
 shi502_security_descriptor AS SECURITY_DESCRIPTOR PTR ' PSECURITY_DESCRIPTOR shi502_security_descriptor
END TYPE
' // Size = 44 bytes
TYPE SHARE_INFO_503 DWORD
 shi503_netname AS WSTRINGZ PTR ' LMSTR
 shi503_type AS DWORD
 shi503_remark AS WSTRINGZ PTR ' LMSTR
 shi503_permissions AS DWORD
 shi503_max_uses AS DWORD
 shi503_current_uses AS DWORD
 shi503_path AS WSTRINGZ PTR ' LMSTR
 shi503_passwd AS WSTRINGZ PTR ' LMSTR
 shi503_servername AS WSTRINGZ PTR ' LMSTR
 shi503_reserved AS DWORD
 shi503_security_descriptor AS SECURITY_DESCRIPTOR PTR ' PSECURITY_DESCRIPTOR
END TYPE
' // Size = 4 bytes
TYPE SHARE_INFO_1004 DWORD
 shi1004_remark AS WSTRINGZ PTR ' LMSTR shi1004_remark
END TYPE
' // Size = 4 bytes
TYPE SHARE_INFO_1005 DWORD
 shi1005_flags AS DWORD ' DWORD shi1005_flags
END TYPE
' // Size = 4 bytes
TYPE SHARE_INFO_1006 DWORD
 shi1006_max_uses AS DWORD ' DWORD shi1006_max_uses
END TYPE
' // Size = 8 bytes
TYPE SHARE_INFO_1501 DWORD
 shi1501_reserved AS DWORD ' DWORD shi1501_reserved
 shi1501_security_descriptor AS SECURITY_DESCRIPTOR PTR ' PSECURITY_DESCRIPTOR shi1501_security_descriptor
END TYPE
' // Size = 16 bytes
TYPE SHARE_INFO_1503 DWORD
 shi1503_sharefilter AS GUID ' GUID
END TYPE
'//
'// NetShareAlias functions
'//
DECLARE FUNCTION NetServerAliasAdd LIB "netapi32.dll" ALIAS "NetServerAliasAdd" ( BYREF servername AS WSTRINGZ , BYVAL level AS QUAD , BYVAL buf AS BYTE PTR ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetServerAliasDel LIB "netapi32.dll" ALIAS "NetServerAliasDel" ( BYREF servername AS WSTRINGZ , BYVAL level AS QUAD , BYVAL buf AS BYTE PTR ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetServerAliasEnum LIB "netapi32.dll" ALIAS "NetServerAliasEnum" ( BYREF servername AS WSTRINGZ , BYVAL level AS QUAD , BYREF bufptr AS ANY , BYVAL prefmaxlen AS QUAD , BYREF entriesread AS QUAD , BYREF totalentries AS QUAD , BYREF resumehandle AS QUAD ) AS QUAD ' NET_API_STATUS
' // Size = 16 bytes
TYPE SERVER_ALIAS_INFO_0 DWORD
 srvai0_alias AS WSTRINGZ PTR ' LMSTR
 srvai0_target AS WSTRINGZ PTR ' LMSTR
 srvai0_default AS BYTE ' BOOLEAN
 srvai0_reserved AS DWORD ' ULONG
END TYPE
'//
'// Special Values and Constants - Share
'//
'//
'// Values for parm_err parameter.
'//
%EQUATE `SHARE_NETNAME_PARMNUM = 1
%EQUATE `SHARE_TYPE_PARMNUM = 3
%EQUATE `SHARE_REMARK_PARMNUM = 4
%EQUATE `SHARE_PERMISSIONS_PARMNUM = 5
%EQUATE `SHARE_MAX_USES_PARMNUM = 6
%EQUATE `SHARE_CURRENT_USES_PARMNUM = 7
%EQUATE `SHARE_PATH_PARMNUM = 8
%EQUATE `SHARE_PASSWD_PARMNUM = 9
%EQUATE `SHARE_FILE_SD_PARMNUM = 501
%EQUATE `SHARE_SERVER_PARMNUM = 503
'//
'// Single-field infolevels for NetShareSetInfo.
'//
%EQUATE `SHARE_REMARK_INFOLEVEL = %PARMNUM_BASE_INFOLEVEL + %SHARE_REMARK_PARMNUM
%EQUATE `SHARE_MAX_USES_INFOLEVEL = %PARMNUM_BASE_INFOLEVEL + %SHARE_MAX_USES_PARMNUM
%EQUATE `SHARE_FILE_SD_INFOLEVEL = %PARMNUM_BASE_INFOLEVEL + %SHARE_FILE_SD_PARMNUM
%EQUATE `SHI1_NUM_ELEMENTS = 4
%EQUATE `SHI2_NUM_ELEMENTS = 10
'//
'// Share types (shi1_type and shi2_type fields).
'//
%EQUATE `STYPE_DISKTREE = 0
%EQUATE `STYPE_PRINTQ = 1
%EQUATE `STYPE_DEVICE = 2
%EQUATE `STYPE_IPC = 3
%EQUATE `STYPE_TEMPORARY = &H40000000
%EQUATE `STYPE_SPECIAL = &H80000000
%EQUATE `SHI_USES_UNLIMITED = &HFFFFFFFF ' (DWORD)-1
'//
'// Flags values for the 501 and 1005 levels
'//
%EQUATE `SHI1005_FLAGS_DFS = &H0001 ' // Share is in the DFS
%EQUATE `SHI1005_FLAGS_DFS_ROOT = &H0002 ' // Share is root of DFS
%EQUATE `CSC_MASK_EXT = &H2030 ' // Used to mask off the following states (including SHI1005_FLAGS_ENABLE_HASH)
%EQUATE `CSC_MASK = &H0030 ' // Used to mask off the following states
%EQUATE `CSC_CACHE_MANUAL_REINT = &H0000 ' // No automatic file by file reintegration
%EQUATE `CSC_CACHE_AUTO_REINT = &H0010 ' // File by file reintegration is OK
%EQUATE `CSC_CACHE_VDO = &H0020 ' // no need to flow opens
%EQUATE `CSC_CACHE_NONE = &H0030 ' // no CSC for this share
%EQUATE `SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS = &H0100 ' // Used to disallow read-deny read behavior
%EQUATE `SHI1005_FLAGS_FORCE_SHARED_DELETE = &H0200 ' // Used to allows force shared delete
%EQUATE `SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING = &H0400 ' // The clients may cache the namespace
%EQUATE `SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM = &H0800 ' // Trim visible files in enumerations based on access
%EQUATE `SHI1005_FLAGS_FORCE_LEVELII_OPLOCK = &H1000 ' // Only issue level2 oplock
%EQUATE `SHI1005_FLAGS_ENABLE_HASH = &H2000 ' // Enable hash generation and retrieval requests from share
'//
'// The subset of 1005 infolevel flags that can be set via the API
'//
%EQUATE `SHI1005_VALID_FLAGS_SET = %CSC_MASK OR %SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS OR %SHI1005_FLAGS_FORCE_SHARED_DELETE OR %SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING OR %SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM OR %SHI1005_FLAGS_FORCE_LEVELII_OPLOCK OR %SHI1005_FLAGS_ENABLE_HASH
'#endif // _LMSHARE_
#ENDIF ' #IF NOT %DEF(%LMSHARE)
'//
'// SESSION API
'//
#IF NOT %DEF(%LMSESSION)
 %LMSESSION = 1
'#ifndef _LMSESSION_
'#define _LMSESSION_
'//
'// Function Prototypes Session
'//
DECLARE FUNCTION NetSessionEnum LIB "netapi32.dll" ALIAS "NetSessionEnum" ( BYREF servername AS WSTRINGZ , BYREF UncClientName AS WSTRINGZ , BYREF username AS WSTRINGZ , BYVAL level AS QUAD , BYREF bufptr AS ANY , BYVAL prefmaxlen AS QUAD , BYREF entriesread AS QUAD , BYREF totalentries AS QUAD , BYREF resume_handle AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetSessionDel LIB "netapi32.dll" ALIAS "NetSessionDel" ( BYREF servername AS WSTRINGZ , BYREF UncClientName AS WSTRINGZ , BYREF username AS WSTRINGZ ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetSessionGetInfo LIB "netapi32.dll" ALIAS "NetSessionGetInfo" ( BYREF WSTRINGZ , BYREF WSTRINGZ , BYREF WSTRINGZ , BYVAL DWORD , BYREF ANY ) AS QUAD ' NET_API_STATUS
'//
'// Data Structures - Session
'//
' // Size = 4 bytes
TYPE SESSION_INFO_0 DWORD
 sesi0_cname AS WSTRINGZ PTR ' LMSTR sesi0_cname // client name (no backslashes)
END TYPE
' // Size = 24 bytes
TYPE SESSION_INFO_1 DWORD
 sesi1_cname AS WSTRINGZ PTR ' LMSTR sesi1_cname // client name (no backslashes)
 sesi1_username AS WSTRINGZ PTR ' LMSTR sesi1_username
 sesi1_num_opens AS DWORD ' DWORD sesi1_num_opens
 sesi1_time AS DWORD ' DWORD sesi1_time
 sesi1_idle_time AS DWORD ' DWORD sesi1_idle_time
 sesi1_user_flags AS DWORD ' DWORD sesi1_user_flags
END TYPE
' // Size = 28 bytes
TYPE SESSION_INFO_2 DWORD
 sesi2_cname AS WSTRINGZ PTR ' LMSTR sesi2_cname
 sesi2_username AS WSTRINGZ PTR ' LMSTR sesi2_username
 sesi2_num_opens AS DWORD ' DWORD sesi2_num_opens
 sesi2_time AS DWORD ' DWORD sesi2_time
 sesi2_idle_time AS DWORD ' DWORD sesi2_idle_time
 sesi2_user_flags AS DWORD ' DWORD sesi2_user_flags
 sesi2_cltype_name AS WSTRINGZ PTR ' LMSTR sesi2_cltype_name
END TYPE
' // Size = 12 bytes
TYPE SESSION_INFO_10 DWORD
 sesi10_cname AS WSTRINGZ PTR ' LMSTR sesi10_cname // client name (no backslashes)
 sesi10_username AS WSTRINGZ PTR ' LMSTR sesi10_username
 sesi10_time AS DWORD ' DWORD sesi10_time
 sesi10_idle_time AS DWORD ' DWORD sesi10_idle_time
END TYPE
' // Size = 32 bytes
TYPE SESSION_INFO_502 DWORD
 sesi502_cname AS WSTRINGZ PTR ' LMSTR sesi502_cname // client name (no backslashes)
 sesi502_username AS WSTRINGZ PTR ' LMSTR sesi502_username
 sesi502_num_opens AS DWORD ' DWORD sesi502_num_opens
 sesi502_time AS DWORD ' DWORD sesi502_time
 sesi502_idle_time AS DWORD ' DWORD sesi502_idle_time
 sesi502_user_flags AS DWORD ' DWORD sesi502_user_flags
 sesi502_cltype_name AS WSTRINGZ PTR ' LMSTR sesi502_cltype_name
 sesi502_transport AS WSTRINGZ PTR ' LMSTR sesi502_transport
END TYPE
'//
'// Special Values and Constants - Session
'//
'//
'// Bits defined in sesi1_user_flags.
'//
%EQUATE `SESS_GUEST = &H00000001 ' // session is logged on as a guest
%EQUATE `SESS_NOENCRYPTION = &H00000002 ' // session is not using encryption
%EQUATE `SESI1_NUM_ELEMENTS = 8
%EQUATE `SESI2_NUM_ELEMENTS = 9
'#endif // _LMSESSION_
#ENDIF ' #IF NOT %DEF(%LMSESSION)
'//
'// CONNECTION API
'//
#IF NOT %DEF(%LMCONNECTION)
 %LMCONNECTION = 1
'#ifndef _LMCONNECTION_
'#define _LMCONNECTION_
'//
'// Function Prototypes - CONNECTION
'//
DECLARE FUNCTION NetConnectionEnum LIB "netapi32.dll" ALIAS "NetConnectionEnum" ( BYREF servername AS WSTRINGZ , BYREF qualifier AS WSTRINGZ , BYVAL level AS QUAD , BYREF bufptr AS ANY , BYVAL prefmaxlen AS QUAD , BYREF entriesread AS QUAD , BYREF totalentries AS QUAD , BYREF resume_handle AS QUAD ) AS QUAD ' NET_API_STATUS
'//
'// Data Structures - CONNECTION
'//
' // Size = 4 bytes
TYPE CONNECTION_INFO_0 DWORD
 coni0_id AS DWORD ' DWORD coni0_id
END TYPE
' // Size = 28 bytes
TYPE CONNECTION_INFO_1 DWORD
 coni1_id AS DWORD ' DWORD coni1_id
 coni1_type AS DWORD ' DWORD coni1_type
 coni1_num_opens AS DWORD ' DWORD coni1_num_opens
 coni1_num_users AS DWORD ' DWORD coni1_num_users
 coni1_time AS DWORD ' DWORD coni1_time
 coni1_username AS WSTRINGZ PTR ' LMSTR coni1_username
 coni1_netname AS WSTRINGZ PTR ' LMSTR coni1_netname
END TYPE
'#endif // _LMCONNECTION_
#ENDIF ' #IF NOT %DEF(%LMCONNECTION)
'//
'// FILE API
'//
#IF NOT %DEF(%LMFILE)
 %LMFILE = 1
'#ifndef _LMFILE_
'#define _LMFILE_
'//
'// Function Prototypes - FILE
'//
DECLARE FUNCTION NetFileClose LIB "netapi32.dll" ALIAS "NetFileClose" ( BYREF servername AS WSTRINGZ , BYVAL fileid AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetFileEnum LIB "netapi32.dll" ALIAS "NetFileEnum" ( BYREF servername AS WSTRINGZ , BYREF basepath AS WSTRINGZ , BYREF username AS WSTRINGZ , BYVAL level AS QUAD , BYREF bufptr AS ANY , BYVAL prefmaxlen AS QUAD , BYREF prefmaxlen AS QUAD , BYREF totalentries AS QUAD , BYREF resume_handle AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetFileGetInfo LIB "netapi32.dll" ALIAS "NetFileGetInfo" ( BYREF servername AS WSTRINGZ , BYVAL fileid AS QUAD , BYVAL level AS QUAD , BYREF bufptr AS ANY ) AS QUAD ' NET_API_STATUS
'//
'// Data Structures - File
'//
'// File APIs are available at information levels 2 & 3 only. Levels 0 &
'// 1 are not supported.
'//
' // Size = 4 bytes
TYPE FILE_INFO_2 DWORD
 fi2_id AS DWORD ' DWORD fi2_id
END TYPE
' // Size = 20 bytes
TYPE FILE_INFO_3 DWORD
 fi3_id AS DWORD ' DWORD fi3_id
 fi3_permissions AS DWORD ' DWORD fi3_permissions
 fi3_num_locks AS DWORD ' DWORD fi3_num_locks
 fi3_pathname AS WSTRINGZ PTR ' LMSTR fi3_pathname
 fi3_username AS WSTRINGZ PTR ' LMSTR fi3_username
END TYPE
'//
'// Special Values and Constants - File
'//
'//
'// bit values for permissions
'//
%EQUATE `PERM_FILE_READ = &H1 ' // user has read access
%EQUATE `PERM_FILE_WRITE = &H2 ' // user has write access
%EQUATE `PERM_FILE_CREATE = &H4 ' // user has create access
#ENDIF ' #IF NOT %DEF(%LMFILE)
#ENDIF
