Skip to content

Commit

Permalink
print the type of shared folders
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ive committed Aug 20, 2024
1 parent 95aafc6 commit fec04ef
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ OPTIONS:
FLAGS:\n"
MENU Print UEFI boot menus.
VARS List all UEFI variables.
--shares Print network mapped drives.
--shares Print network mapped drives and shared folders.
--audio Print audio devices.
--public-ip Print public IP address.
--product-policy Print ProductPolicy.
Expand Down
80 changes: 49 additions & 31 deletions libnw/smb.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,54 @@
#include "utils.h"

static void
EnumConnectedDrives(PNODE pNode, HKEY root, LPCWSTR key)
EnumConnectedDrives(PNODE pParent)
{
PVOID lpData = NULL;
DWORD dwSize = 0;
DWORD dwType = 0;
PNODE nd = NWL_NodeAppendNew(pNode, "Drive", NFLG_TABLE_ROW);
NWL_NodeAttrSetf(nd, "Local Name", 0, "%s:\\", NWL_Ucs2ToUtf8(key));
lpData = NWL_NtGetRegValue(root, key, L"RemotePath", &dwSize, &dwType);
if (lpData)
HKEY root = NULL;
DWORD i;
DWORD dwIndex = 0;

if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Network", 0, KEY_READ, &root) != ERROR_SUCCESS)
goto fail;
if (RegQueryInfoKeyW(root, NULL, NULL, NULL, &dwIndex, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
goto fail;
for (i = 0; i < dwIndex; i++)
{
NWL_NodeAttrSet(nd, "Remote Name", NWL_Ucs2ToUtf8(lpData), 0);
free(lpData);
DWORD dwType = 0;
DWORD dwSize = NWINFO_BUFSZW;
if (RegEnumKeyExW(root, i, NWLC->NwBufW, &dwSize, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
continue;
PNODE nd = NWL_NodeAppendNew(pParent, "Drive", NFLG_TABLE_ROW);
NWL_NodeAttrSetf(nd, "Local Name", 0, "%s:\\", NWL_Ucs2ToUtf8(NWLC->NwBufW));
PVOID lpData = NWL_NtGetRegValue(root, NWLC->NwBufW, L"RemotePath", &dwSize, &dwType);
if (lpData)
{
NWL_NodeAttrSet(nd, "Remote Name", NWL_Ucs2ToUtf8(lpData), 0);
free(lpData);
}
lpData = NWL_NtGetRegValue(root, NWLC->NwBufW, L"ProviderName", &dwSize, &dwType);
if (lpData)
{
NWL_NodeAttrSet(nd, "Provider", NWL_Ucs2ToUtf8(lpData), 0);
free(lpData);
}
}
lpData = NWL_NtGetRegValue(root, key, L"ProviderName", &dwSize, &dwType);
if (lpData)

fail:
if (root)
RegCloseKey(root);
}

static LPCSTR
GetSharedFolderType(DWORD dwType)
{
dwType &= STYPE_MASK;
switch (dwType)
{
NWL_NodeAttrSet(nd, "Provider", NWL_Ucs2ToUtf8(lpData), 0);
free(lpData);
case STYPE_DISKTREE: return "Disk Drive";
case STYPE_PRINTQ: return "Print Queue";
case STYPE_DEVICE: return "Communication device";
case STYPE_IPC: return "IPC";
default: return "Unknown";
}
}

Expand Down Expand Up @@ -61,7 +91,11 @@ EnumSharedFolders(PNODE pParent)
PNODE nd = NWL_NodeAppendNew(pParent, "Shared Folder", NFLG_TABLE_ROW);
NWL_NodeAttrSet(nd, "Network Name", NWL_Ucs2ToUtf8(p->shi502_netname), 0);
NWL_NodeAttrSet(nd, "Path", NWL_Ucs2ToUtf8(p->shi502_path), 0);
NWL_NodeAttrSet(nd, "Remark", NWL_Ucs2ToUtf8(p->shi502_remark), 0);
NWL_NodeAttrSetf(nd, "Current Uses", NAFLG_FMT_NUMERIC, "%lu", p->shi502_current_uses);
NWL_NodeAttrSetBool(nd, "Special Share", (p->shi502_type & STYPE_SPECIAL), 0);
NWL_NodeAttrSetBool(nd, "Temporary Share", (p->shi502_type & STYPE_TEMPORARY), 0);
NWL_NodeAttrSet(nd, "Type", GetSharedFolderType(p->shi502_type), 0);
p++;
}
fpNetApiBufferFree(bufPtr);
Expand All @@ -75,29 +109,13 @@ EnumSharedFolders(PNODE pParent)

PNODE NW_NetShare(VOID)
{
HKEY root = NULL;
DWORD i;
DWORD dwIndex = 0;
PNODE node = NWL_NodeAlloc("NetworkDrives", NFLG_TABLE);
if (NWLC->ShareInfo)
NWL_NodeAppendChild(NWLC->NwRoot, node);

EnumSharedFolders(node);

if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Network", 0, KEY_READ, &root) != ERROR_SUCCESS)
goto fail;
if (RegQueryInfoKeyW(root, NULL, NULL, NULL, &dwIndex, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
goto fail;
for (i = 0; i < dwIndex; i++)
{
DWORD dwSize = NWINFO_BUFSZW;
if (RegEnumKeyExW(root, i, NWLC->NwBufW, &dwSize, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
continue;
EnumConnectedDrives(node, root, NWLC->NwBufW);
}
EnumConnectedDrives(node);

fail:
if (root)
RegCloseKey(root);
return node;
}
4 changes: 2 additions & 2 deletions libnw/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#define NWINFO_MAJOR_VERSION 1
#define NWINFO_MINOR_VERSION 0
#define NWINFO_MICRO_VERSION 0
#define NWINFO_BUILD_VERSION 7
#define NWINFO_MICRO_VERSION 1
#define NWINFO_BUILD_VERSION 1

#define NWINFO_VERSION NWINFO_MAJOR_VERSION,NWINFO_MINOR_VERSION,NWINFO_MICRO_VERSION,NWINFO_BUILD_VERSION
#define NWINFO_VERSION_STR QUOTE(NWINFO_MAJOR_VERSION.NWINFO_MINOR_VERSION.NWINFO_MICRO_VERSION.NWINFO_BUILD_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion nwinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void nwinfo_help(void)
" FLAGS:\n"
" MENU Print UEFI boot menus.\n"
" VARS List all UEFI variables.\n"
" --shares Print network mapped drives.\n"
" --shares Print network mapped drives and shared folders.\n"
" --audio Print audio devices.\n"
" --public-ip Print public IP address.\n"
" --product-policy Print ProductPolicy.\n"
Expand Down

0 comments on commit fec04ef

Please sign in to comment.