Exemple #1
0
bool CWfpNET::Transports_get(void)
{
	NET_API_STATUS nStatus			  = NULL;
	LPSERVER_TRANSPORT_INFO_1 pBuf	  = NULL,
		pTmpBuf						  = NULL;
	DWORD dwEntriesRead				  = 0;
	DWORD dwTotalEntries			  = 0;
	DWORD dwResumeHandle			  = 0;
	DWORD i	= 0;
	int j = 0;
	CString tmp;	

	// The NetServerTransportEnum function supplies information about
	// transport protocols that are managed by the server.
	// No special group membership is required to successfully execute
	// the NetServerTransportEnum function.
		
	do 
	{
		nStatus = NetServerTransportEnum(node.szComputerW, 1, (LPBYTE *)&pBuf,
			MAX_PREFERRED_LENGTH, &dwEntriesRead, &dwTotalEntries, &dwResumeHandle);
		// If the call succeeds,
		if((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
		{
			if((pTmpBuf = pBuf) != NULL)
			{
				// Loop through the entries;
				//  process access errors.
	          		
				for(i = 0; i < dwEntriesRead; i++)
				{
					assert(pTmpBuf != NULL);
					if(pTmpBuf == NULL)
						return false;
					
					if(node.NetBIOS.IsEmpty())
						node.NetBIOS.Format("%s", pTmpBuf->svti1_transportaddress);
	
					if(node.Domain.IsEmpty())
						node.Domain.Format("%S", pTmpBuf->svti1_domain);
					
					tmp.Format("%S", pTmpBuf->svti1_networkaddress);
					
					if(options.optionmacaddress)
						if(wcscmp(pTmpBuf->svti1_transportname,L"\\Device\\NetbiosSmb") != 0)  
						{
							tmp.Format("%S", pTmpBuf->svti1_networkaddress);
							if(MACAddress.GetSize() > 0) 
							{
								bool exists = false;
								for(j = 0; j <= MACAddress.GetUpperBound(); j++)
								{	
									if(strcmp(tmp, MACAddress[j]) == 0)
										exists = true;
								}
								if(!exists)
									MACAddress.Add(tmp);
							}	
							else
								MACAddress.Add(tmp);
						}
					pTmpBuf++;
				}
			
				if(pBuf != NULL)
				{
					NetApiBufferFree(pBuf);
					pBuf = NULL;
				}
			}
		}
		else
		{
			ErrorHandler("NetServerTransportEnum", nStatus);
			// If NetServerTransportEnum fails, attempt via UDP
			//UDP_Sockets(node,137,137,1); // nbtstat -a equivalent
			return false;
		}
	}while(nStatus == ERROR_MORE_DATA);
	return true;
}
Exemple #2
0
static
INT
DisplayServerConfig(
    PSERVER_INFO_102 ServerInfo)
{
    PSERVER_TRANSPORT_INFO_0 TransportInfo = NULL;
    DWORD dwRead, dwTotal, i;
    INT nPaddedLength = 38;
    NET_API_STATUS Status;

    Status = NetServerTransportEnum(NULL, 0, (PBYTE*)&TransportInfo,
                                    MAX_PREFERRED_LENGTH,
                                    &dwRead,
                                    &dwTotal,
                                    NULL);
    if (Status != NERR_Success)
        goto done;

    PrintPaddedMessageString(4481, nPaddedLength);
    ConPrintf(StdOut, L"\\\\%s\n", ServerInfo->sv102_name);

    PrintPaddedMessageString(4482, nPaddedLength);
    ConPrintf(StdOut, L"%s\n\n", ServerInfo->sv102_comment);

    PrintPaddedMessageString(4484, nPaddedLength);
    ConPrintf(StdOut, L"%lu.%lu\n",
              ServerInfo->sv102_version_major,
              ServerInfo->sv102_version_minor);

    PrintPaddedMessageString(4489, nPaddedLength);
    ConPuts(StdOut, L"\n");
    for (i = 0; i < dwRead; i++)
    {
        ConPrintf(StdOut, L"      %s (%s)\n",
                  &TransportInfo[i].svti0_transportname[8],
                  TransportInfo[i].svti0_networkaddress);
    }
    ConPuts(StdOut, L"\n");

    PrintPaddedMessageString(4492, nPaddedLength);
    PrintMessageString((ServerInfo->sv102_hidden == SV_HIDDEN) ? 4300 : 4301);
    ConPuts(StdOut, L"\n");

    PrintPaddedMessageString(4506, nPaddedLength);
    ConPrintf(StdOut, L"%lu\n", ServerInfo->sv102_users);

    PrintPaddedMessageString(4511, nPaddedLength);
    ConPuts(StdOut, L"...\n\n");

    PrintPaddedMessageString(4520, nPaddedLength);
    if (ServerInfo->sv102_disc == SV_NODISC)
        PrintMessageString(4306);
    else
        ConPrintf(StdOut, L"%lu\n", ServerInfo->sv102_disc);

done:
    if (TransportInfo != NULL)
        NetApiBufferFree(TransportInfo);

    return 0;
}