/*!
 @brief ユーザフルネームの取得 (Unicode)
*/
BOOL CUserInfoDlg::GetFullNameW(wchar_t *UserName, wchar_t *, wchar_t *dest)
{
	LPBYTE ComputerName = 0;
  
	struct _USER_INFO_2 *ui;          // User structure

	BOOL bFoundDC = TRUE;
	DWORD nRet = NetGetDCName(NULL, NULL, &ComputerName );
	// Get the computer name of a DC for the specified domain.
	if (nRet != NERR_Success) {
		printf("Error getting user information.\n" );
		bFoundDC = FALSE;
	}

	// Look up the user on the DC.
	nRet = NetUserGetInfo((LPWSTR) ComputerName,
		(LPWSTR) UserName, 2, (LPBYTE *) &ui);
	if (nRet != NERR_Success) {

		if (bFoundDC == TRUE) {
			NetApiBufferFree(ComputerName);
		}
		printf("Error getting user information.\n" );
		return(FALSE );
	}
	if (bFoundDC == TRUE) {
		NetApiBufferFree(ComputerName);
	}

	wcsncpy_s(dest, 256, ui->usri2_full_name, _TRUNCATE);
	
	return(TRUE );
}
Exemple #2
0
NET_API_STATUS 
NetUserGetProfilePath( LPCWSTR Domain, LPCWSTR UserName, char * profilePath, 
                       DWORD profilePathLen )
{
    NET_API_STATUS code;
    LPWSTR ServerName = NULL;
    LPUSER_INFO_3 p3 = NULL;

    NetGetAnyDCName(NULL, Domain, (LPBYTE *)&ServerName);
    /* if NetGetAnyDCName fails, ServerName == NULL
     * NetUserGetInfo will obtain local user information 
     */
    code = NetUserGetInfo(ServerName, UserName, 3, (LPBYTE *)&p3);
    if (code == NERR_Success)
    {
        code = NERR_UserNotFound;
        if (p3) {
            if (p3->usri3_profile) {
                DWORD len = lstrlenW(p3->usri3_profile);
                if (len > 0) {
                    /* Convert From Unicode to ANSI (UTF-8 for future) */
                    len = len < profilePathLen ? len : profilePathLen - 1;
                    WideCharToMultiByte(CP_UTF8, 0, p3->usri3_profile, len, profilePath, len, NULL, NULL);
                    profilePath[len] = '\0';
                    code = NERR_Success;
                }
            }
            NetApiBufferFree(p3);
        }
    }
    if (ServerName) 
        NetApiBufferFree(ServerName);
    return code;
}
Exemple #3
0
/*	InitName - initialize name translation
 *
 *	pszServer   machine name for symref daemon
 */
void InitName (IN PSZ pszServer)
{
    PSERVICE_INFO_0 psi;
    PWKSTA_INFO_100 pwi;

    //
    //	Set up daemon server name
    //

    strcpy (szServer, pszServer);

    //
    //	See if our own server is started
    //

    if (NetServiceGetInfo (NULL, "SERVER", 0, (LPBYTE *) &psi) == 0) {
	fServerStarted = TRUE;
	NetApiBufferFree (psi);
	}


    //
    //	Set up workstation name
    //

    NetWkstaGetInfo (NULL, 100, (LPBYTE *) &pwi);

    strcpy (szWksta, pwi->wki100_computername);

    NetApiBufferFree (pwi);
}
Exemple #4
0
static
NET_API_STATUS
EnumerateUsers(VOID)
{
    PUSER_INFO_0 pBuffer = NULL;
    PSERVER_INFO_100 pServer = NULL;
    DWORD dwRead = 0, dwTotal = 0;
    DWORD i;
    DWORD_PTR ResumeHandle = 0;
    NET_API_STATUS Status;

    Status = NetServerGetInfo(NULL,
                              100,
                              (LPBYTE*)&pServer);
    if (Status != NERR_Success)
        return Status;

    ConPuts(StdOut, L"\n");
    ConResPrintf(StdOut, IDS_USER_ACCOUNTS, pServer->sv100_name);
    ConPuts(StdOut, L"\n\n");
    PrintPadding(L'-', 79);
    ConPuts(StdOut, L"\n");

    NetApiBufferFree(pServer);

    do
    {
        Status = NetUserEnum(NULL,
                             0,
                             0,
                             (LPBYTE*)&pBuffer,
                             MAX_PREFERRED_LENGTH,
                             &dwRead,
                             &dwTotal,
                             &ResumeHandle);
        if ((Status != NERR_Success) && (Status != ERROR_MORE_DATA))
            return Status;

        qsort(pBuffer,
              dwRead,
              sizeof(PUSER_INFO_0),
              CompareInfo);

        for (i = 0; i < dwRead; i++)
        {
            if (pBuffer[i].usri0_name)
                ConPrintf(StdOut, L"%s\n", pBuffer[i].usri0_name);
        }

        NetApiBufferFree(pBuffer);
        pBuffer = NULL;
    }
    while (Status == ERROR_MORE_DATA);

    return NERR_Success;
}
Exemple #5
0
bool CWfpNET::PasswordPolicy_get(void)
{
	USER_MODALS_INFO_0 *pBuf0 = NULL;
	USER_MODALS_INFO_3 *pBuf3 = NULL;
	NET_API_STATUS nStatus = NULL;
	CString tmp;

	if((nStatus = NetUserModalsGet(node.szComputerW, 0,(LPBYTE *)&pBuf0)) != NERR_Success)
		ErrorHandler("NetUserModalsGet", nStatus);
	else
	{
		//m_output.operator +=(_T("Password Policy:\n"));
		if (pBuf0 != NULL)
		{
			tmp.Format("\tMinimum password length:  %d\n", pBuf0->usrmod0_min_passwd_len);
			Users.Add(tmp);
			if(pBuf0->usrmod0_max_passwd_age == TIMEQ_FOREVER)
				tmp.Format("\tMaximum password age: Forever\n");
			else
				tmp.Format("\tMaximum password age : %d days\n", pBuf0->usrmod0_max_passwd_age/86400);
			Users.Add(tmp);
			tmp.Format("\tMinimum password age : %d days\n", pBuf0->usrmod0_min_passwd_age/86400);
			Users.Add(tmp);
			if(pBuf0->usrmod0_force_logoff == TIMEQ_FOREVER)
				tmp.Format("\tForced log off time : Never\n");
			else
				tmp.Format("\tForced log off time :  %d seconds\n", pBuf0->usrmod0_force_logoff);
			Users.Add(tmp);
			tmp.Format("\tPassword history length:  %d\n", pBuf0->usrmod0_password_hist_len);
			Users.Add(tmp);
      }
	}
 
	if (pBuf0 != NULL)
		NetApiBufferFree(pBuf0);
	if((nStatus = NetUserModalsGet(node.szComputerW, 3,(LPBYTE *)&pBuf3)) != NERR_Success)
		ErrorHandler("NetUserModalsGet", nStatus);
	else
	{
		if(pBuf3 != NULL)
		{
			tmp.Format("\tAttempts before Lockout: %d\n",pBuf3->usrmod3_lockout_threshold);
			Users.Add(tmp);
			tmp.Format("\tTime between two failed login attempts: %d seconds\n",pBuf3->usrmod3_lockout_duration);
			Users.Add(tmp);
			tmp.Format("\tLockout Duration: %d minutes\n",pBuf3->usrmod3_lockout_duration/60);
			Users.Add(tmp);
		}
	}

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

	return true;
}
/*!
 @brief ユーザグループの取得 (MBCS)
*/
BOOL CUserInfoDlg::GetGroupNameA(char *UserName, char *dest)
{
	WCHAR  wszUserName[256];           // Unicode user name
	LPBYTE ComputerName = 0;
  
	// Convert ASCII user name and domain to Unicode.
	MultiByteToWideChar(CP_ACP, 0, UserName, strlen(UserName) + 1, wszUserName, sizeof(wszUserName) / sizeof(WCHAR));

	// Get the computer name of a DC for the specified domain.
	BOOL bFoundDC = TRUE;
	DWORD nRet = NetGetDCName(NULL, NULL, &ComputerName );
	if (nRet != NERR_Success) {
		printf("Error getting group information.\n" );
		bFoundDC = FALSE;
	}

	LPLOCALGROUP_USERS_INFO_0 pBuf = NULL;
	DWORD dwEntriesRead = 0;
	DWORD dwTotalEntries = 0;	// Look up the user on the DC.
	nRet = NetUserGetLocalGroups((LPWSTR) ComputerName,
		(LPWSTR) wszUserName, 0, LG_INCLUDE_INDIRECT, (LPBYTE *) &pBuf, MAX_PREFERRED_LENGTH, &dwEntriesRead, &dwTotalEntries);
	if (nRet != NERR_Success) {
		if (bFoundDC == TRUE) {
			NetApiBufferFree(ComputerName);
		}
		printf("Error getting group information.\n" );
		return(FALSE );
	}
	if (bFoundDC == TRUE) {
		NetApiBufferFree(ComputerName);
	}

	LPLOCALGROUP_USERS_INFO_0 pTmpBuf = pBuf;
	for (unsigned int i = 0; i < dwEntriesRead; i++) {
		if (pTmpBuf == NULL) {
		   fprintf(stderr, "An access violation has occurred\n");
		   break;
		}
		strcat_s(dest, (GNLEN + 1) * 5, ",");

		char szGroupName[GNLEN + 1];
		// Convert the Unicode full name to ASCII.
		WideCharToMultiByte(CP_ACP, 0, pTmpBuf->lgrui0_name, -1, szGroupName, GNLEN, NULL, NULL );

		strcat_s(dest, (GNLEN + 1) * 5, szGroupName);
		pTmpBuf++;
	}
	NetApiBufferFree(pBuf);

	
	return (TRUE);
}
NS_IMETHODIMP
nsUserInfo::GetFullname(PRUnichar **aFullname)
{
  NS_ENSURE_ARG_POINTER(aFullname);
  *aFullname = nullptr;

  PRUnichar fullName[512];
  DWORD size = mozilla::ArrayLength(fullName);

  if (GetUserNameExW(NameDisplay, fullName, &size)) {
    *aFullname = ToNewUnicode(nsDependentString(fullName));
  } else {
    DWORD getUsernameError = GetLastError();

    // Try to use the net APIs regardless of the error because it may be
    // able to obtain the information.
    PRUnichar username[UNLEN + 1];
    size = mozilla::ArrayLength(username);
    if (!GetUserNameW(username, &size)) {
      // ERROR_NONE_MAPPED means the user info is not filled out on this computer
      return getUsernameError == ERROR_NONE_MAPPED ?
             NS_ERROR_NOT_AVAILABLE : NS_ERROR_FAILURE;
    }

    const DWORD level = 2;
    LPBYTE info;
    // If the NetUserGetInfo function has no full name info it will return
    // success with an empty string.
    NET_API_STATUS status = NetUserGetInfo(nullptr, username, level, &info);
    if (status != NERR_Success) {
      // We have an error with NetUserGetInfo but we know the info is not
      // filled in because GetUserNameExW returned ERROR_NONE_MAPPED.
      return getUsernameError == ERROR_NONE_MAPPED ?
             NS_ERROR_NOT_AVAILABLE : NS_ERROR_FAILURE;
    }

    nsDependentString fullName =
      nsDependentString(reinterpret_cast<USER_INFO_2 *>(info)->usri2_full_name);

    // NetUserGetInfo returns an empty string if the full name is not filled out
    if (fullName.Length() == 0) {
      NetApiBufferFree(info);
      return NS_ERROR_NOT_AVAILABLE;
    }

    *aFullname = ToNewUnicode(fullName);
    NetApiBufferFree(info);
  }

  return (*aFullname) ? NS_OK : NS_ERROR_FAILURE;
}
Exemple #8
0
USHORT find_rts(TCHAR FAR * buf, USHORT buflen)

{
    USHORT                       err;                   /* API return status */
    struct server_info_0 FAR * si;
    USHORT2ULONG               eread;

    UNREFERENCED_PARAMETER(buflen) ;

    /* find a reliable time server */
    err = MNetServerEnum(NULL,0,(LPBYTE*)&si, &eread,
             (ULONG) SV_TYPE_TIME_SOURCE, NULL);

    /* there are none -- bag it */
    if (err != NERR_Success || eread == 0)
        return APE_TIME_RtsNotFound;

    /* copy over name into buffer */
    _tcscpy(buf,TEXT("\\\\"));
    _tcscat(buf,si->sv0_name);

    NetApiBufferFree((TCHAR FAR *) si);

    return 0;

}
    virtual void GetLoggedInUsers(const std::wstring& ComputerName, OBJ_LIST& loggedInUsers, OBJ_LIST& domains)
	{
		LPWKSTA_USER_INFO_1 pBuf = NULL;
		LPWKSTA_USER_INFO_1 pTmpBuf;
		DWORD dwLevel = 1;
		DWORD dwPrefMaxLen = -1;
		DWORD dwEntriesRead = 0;
		DWORD dwTotalEntries = 0;
		DWORD dwResumeHandle = 0;
		NET_API_STATUS nStatus;

		do
		{
			nStatus = NetWkstaUserEnum((wchar_t*)ComputerName.c_str(), dwLevel, (LPBYTE*)&pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, &dwResumeHandle);
			if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
			{
				pTmpBuf = pBuf;
				
				// Loop through the entries.
				for (DWORD i = 0; (i < dwEntriesRead); i++)
				{
					loggedInUsers.push_back(pTmpBuf->wkui1_username);
					domains.push_back(pTmpBuf->wkui1_logon_domain);

					pTmpBuf++;
				}

				NetApiBufferFree(pBuf);
			}
			else
				KLSTD_THROW_LASTERROR_CODE(nStatus);
		}
		while (nStatus == ERROR_MORE_DATA);
	}
Exemple #10
0
JSBool netgetjoinableous(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
	LPWSTR domain, account, password;
	JS_BeginRequest(cx);
	if(!JS_ConvertArguments(cx, argc, argv, "W W W", &domain, &account, &password))
	{
		JS_ReportError(cx, "Error parsing arguments in NetGetJoinableOUs");
		JS_EndRequest(cx);
	}

	JS_YieldRequest(cx);
	DWORD ouCount = 0;
	LPWSTR * ous = NULL;
	DWORD status = NetGetJoinableOUs(NULL, domain, (JSVAL_IS_NULL(argv[1]) ? NULL : account), (JSVAL_IS_NULL(argv[2]) ? NULL : password), &ouCount, &ous);
	if(status != NERR_Success)
	{
		JS_NewNumberValue(cx, status, rval);
		JS_EndRequest(cx);
		return JS_TRUE;
	}

	JSObject * arrayObj = JS_NewArrayObject(cx, 0, NULL);
	*rval = OBJECT_TO_JSVAL(arrayObj);
	for(DWORD i = 0; i < ouCount; i++)
	{
		JSString * curOu = JS_NewUCStringCopyZ(cx, (jschar*)ous[i]);
		JS_DefineElement(cx, arrayObj, i, STRING_TO_JSVAL(curOu), NULL, NULL, 0);
	}
	NetApiBufferFree(ous);
	JS_EndRequest(cx);
	return JS_TRUE;
}
QString SystemInfo::getJoinInformation(bool *isJoinedToDomain, const QString &serverName){
    qDebug()<<"--SystemInfo::getJoinInformation()";


    QString workgroupName = "";
    NET_API_STATUS err;
    LPWSTR lpNameBuffer = new wchar_t[256];
    NETSETUP_JOIN_STATUS bufferType;
    LPCWSTR lpServer = NULL; // The server is the default local computer.
    if(!serverName.trimmed().isEmpty()){
        lpServer = serverName.toStdWString().c_str();
    }

    err = NetGetJoinInformation(lpServer, &lpNameBuffer, &bufferType);
    if(err == NERR_Success){
        workgroupName = QString::fromWCharArray(lpNameBuffer);
    }else{
        QMessageBox::critical(this, tr("Error"), tr("Can not get join status information!"));
    }

    NetApiBufferFree(lpNameBuffer);
    if(isJoinedToDomain){
        *isJoinedToDomain = (bufferType == NetSetupDomainName)?true:false;
    }

    return workgroupName;

}
static int get_user_local_groups(WCHAR *user, struct oscap_list *list)
{
	NET_API_STATUS status;

	LOCALGROUP_USERS_INFO_0 *buffer = NULL;
	DWORD preffered_max_len = MAX_PREFERRED_LENGTH;
	DWORD entries_read = 0;
	DWORD total_entries = 0;
	/*
	 * LG_INCLUDE_INDIRECT means the function also returns the names of
	 * the local groups in which the user is indirectly a member (that is,
	 * the user has membership in a global group that is itself a member
	 * of one or more local groups).
	 */
	status = NetUserGetLocalGroups(NULL, user, 0, LG_INCLUDE_INDIRECT, (LPBYTE *)&buffer, preffered_max_len, &entries_read, &total_entries);
	if (status != NERR_Success) {
		dD("NetUserGetLocalGroups failed: %d", status);
		return 1;
	}
	for (DWORD i = 0; i < entries_read; i++) {
		WCHAR *group_name = buffer[i].lgrui0_name;
		oscap_list_add(list, wcsdup(group_name));
	}
	NetApiBufferFree(buffer);
	return 0;
}
Exemple #13
0
USHORT MNetAccessGetInfo (
    const CHAR FAR * pszServer,
    CHAR       FAR * pszResource,
    SHORT	     Level,
    CHAR     FAR **  ppBuffer ) {

    USHORT	     usReturnCode,
		     cbTotalAvail;

    // get a small buffer
    *ppBuffer = MGetBuffer(LITTLE_BUFFER_SIZE);
    if (*ppBuffer == NULL)
    {
	return(ERROR_NOT_ENOUGH_MEMORY);
    }


    usReturnCode = NetAccessGetInfo(pszServer, pszResource, Level, *ppBuffer,
	    LITTLE_BUFFER_SIZE, & cbTotalAvail);

    // If we're returning an error that's not moredata, free the buffer first

    if (usReturnCode && usReturnCode != ERROR_MORE_DATA &&
	usReturnCode != NERR_BufTooSmall) {
	    NetApiBufferFree(*ppBuffer);
    }

    return (usReturnCode);

}
Exemple #14
0
/**
 * Lookup a user based on a user ID. Calling functions should
 * free the result with authz_free_buffer().
 *
 * @param userid    user name to lookup
 *
 * @return a user info structure or NULL on error
 */
userinfo_t *authz_lookup_user(const char *userid)
{
    struct USER_INFO_23 *buf = NULL;
    userinfo_t *result = NULL;
    NET_API_STATUS status;

    pthread_mutex_lock(&_ctxmtx);

    if (!userid || !_netapictx) {
        pthread_mutex_unlock(&_ctxmtx);
        return NULL;
    }

    status = NetUserGetInfo(_host, userid, 23, (uint8_t **)&buf);
    if (status != NET_API_STATUS_SUCCESS) {
        log_warn("NetApi lookup for user %s failed (%d)", userid, status);
        pthread_mutex_unlock(&_ctxmtx);
        return NULL;
    }

    result = (userinfo_t *)malloc(sizeof(userinfo_t));
    bzero(result, sizeof(userinfo_t));

    result->logon_name = strdup(userid);
    result->display_name = strdup(buf->usri23_full_name);

    ConvertSidToStringSid(buf->usri23_user_sid, &result->sid);

    NetApiBufferFree(buf);
    pthread_mutex_unlock(&_ctxmtx);

    log_debug("found user %s with SID %s", userid, result->sid);
    return result;
}
Exemple #15
0
std::vector<Group*> UserUtilities::GetUserGroupList(CString strUserName)
{
	std::vector<Group*> lstUserGroups;
	LOCALGROUP_USERS_INFO_0 *grpInfo = NULL;
	LOCALGROUP_USERS_INFO_0 *tempgrpInfo = NULL;
	DWORD entriesRead = 0;
	DWORD totalEntries = 0;
	int res = NetUserGetLocalGroups(NULL, strUserName, 0, 0, (LPBYTE*)&grpInfo, MAX_PREFERRED_LENGTH, &entriesRead, &totalEntries);
	if(entriesRead > 0)
	{
		tempgrpInfo = grpInfo;
		for(int i = 0;i < entriesRead;i++)
		{
			Group* grp = new Group();
			grp->m_StrGroupName = tempgrpInfo->lgrui0_name;
			lstUserGroups.push_back(grp);
			
			tempgrpInfo++;
		}
	}

	if(grpInfo)
	{
		NetApiBufferFree(grpInfo);
		grpInfo = NULL;
	}

	return lstUserGroups;
}
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;
  }
}
Exemple #17
0
UINT initializeAfsAdminGroup(void) {
    PSID psidAdmin = NULL;
    SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY;
    NET_API_STATUS status;
    LOCALGROUP_MEMBERS_INFO_0 *gmAdmins = NULL;
    DWORD dwNEntries, dwTEntries;
    WCHAR AdminGroupName[UNLEN+1];
    DWORD cchName = UNLEN;

    if (!LookupAliasFromRid( NULL, DOMAIN_ALIAS_RID_ADMINS, AdminGroupName, &cchName )) 
    {
        /* if we fail, we will try the English string "Administrators" */
        wcsncpy(AdminGroupName, L"Administrators", UNLEN+1);
        AdminGroupName[UNLEN] = 0;
    }

    status = NetLocalGroupGetMembers(NULL, AdminGroupName, 0, (LPBYTE *) &gmAdmins, MAX_PREFERRED_LENGTH, &dwNEntries, &dwTEntries, NULL);
    if(status)
        return status;

    status = NetLocalGroupAddMembers(NULL, AFSCLIENT_ADMIN_GROUPNAMEW, 0, (LPBYTE) gmAdmins, dwNEntries);

    NetApiBufferFree( gmAdmins );

    return status;
}
Exemple #18
0
        ~Private()
        {
            if (userInfo)
                NetApiBufferFree(userInfo);

            delete[] sid;
        }
	virtual std::wstring DistDomainNameToNT4Name(const std::wstring& domain)
	{
		KLSTD_CHKINPTR(m_fnDsGetDcName);

		std::wstring wstrDNSDomain(domain.begin() + 3, domain.end());

		size_t nPos = wstrDNSDomain.find(L",DC=");
		while(nPos != std::wstring::npos)
		{
			wstrDNSDomain.replace(nPos, 4, L".");
			nPos = wstrDNSDomain.find(L",DC=", nPos + 1);
		}

		PDOMAIN_CONTROLLER_INFO pDomainControllerInfo = NULL;
		DWORD dwResult = m_fnDsGetDcName(NULL, KLSTD_W2T2(wstrDNSDomain.c_str()), NULL, NULL, 
										 DS_DIRECTORY_SERVICE_REQUIRED | DS_IS_DNS_NAME | DS_RETURN_FLAT_NAME,
										 &pDomainControllerInfo);
		if (dwResult != NO_ERROR)
		{
			KLSTD_TRACE3(1, L"DistDomainNameToNT4Name(DN:'%ls', DNS:'%ls')::DsGetDcName - Error '%u'\n", domain.c_str(), wstrDNSDomain.c_str(), dwResult);
			KLSTD_THROW(KLSTD::STDE_FAULT);
		}
		
		std::wstring rc = KLSTD_T2W2(pDomainControllerInfo->DomainName);
		NetApiBufferFree(pDomainControllerInfo);
		return rc;
	}
Exemple #20
0
static VOID
UpdateGroupProperties(HWND hwndDlg)
{
    TCHAR szGroupName[UNLEN];
    INT iItem;
    HWND hwndLV;
    PLOCALGROUP_INFO_1 pGroupInfo = NULL;

    hwndLV = GetDlgItem(hwndDlg, IDC_GROUPS_LIST);
    iItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
    if (iItem == -1)
        return;

    /* Get the group name */
    ListView_GetItemText(hwndLV,
                         iItem, 0,
                         szGroupName,
                         UNLEN);

    NetLocalGroupGetInfo(NULL, szGroupName, 1, (LPBYTE*)&pGroupInfo);

    ListView_SetItemText(hwndLV, iItem, 1,
                         pGroupInfo->lgrpi1_comment);

    NetApiBufferFree(pGroupInfo);
}
Exemple #21
0
WORD
MFreeMem(
    LPBYTE Buffer
    )
{
   return(LOWORD(NetApiBufferFree(Buffer)));
}
Exemple #22
0
std::vector<Group*> UserUtilities::GetGroupList()
{
	std::vector<Group*> lstGroups;
	LOCALGROUP_INFO_1* grpInfo = NULL;
	LOCALGROUP_INFO_1* tempgrpInfo;
	DWORD entriesRead = 0;
	DWORD totalEntries = 0;
	DWORD resume = 0;

	int res = NetLocalGroupEnum(NULL, 1, (LPBYTE*)&grpInfo, -1, &entriesRead, &totalEntries, &resume);
	if(entriesRead > 0)
	{
		tempgrpInfo = grpInfo;
		for(int i = 0;i < entriesRead;i++)
		{
			Group* grp = new Group();
			grp->m_StrGroupName = tempgrpInfo->lgrpi1_name;
			grp->m_StrDescription = tempgrpInfo->lgrpi1_comment;
			lstGroups.push_back(grp);
			
			tempgrpInfo++;
		}
	}

	if(grpInfo)
	{
		NetApiBufferFree(grpInfo);
		grpInfo = NULL;
	}

	return lstGroups;
}
Exemple #23
0
USHORT MNetServiceControl (
    const CHAR FAR * pszServer,
    const CHAR FAR * pszService,
    CHAR	     wpOpCode,
    CHAR	     wpArg,
    CHAR      FAR ** ppBuffer ) {

    USHORT	     usReturnCode;

    // get a small buffer
    *ppBuffer = MGetBuffer(LITTLE_BUFFER_SIZE);
    if (*ppBuffer == NULL)
    {
	return(ERROR_NOT_ENOUGH_MEMORY);
    }

    usReturnCode = NetServiceControl(pszServer, pszService, wpOpCode, wpArg,
	    *ppBuffer, LITTLE_BUFFER_SIZE);

    // If we're returning an error that's not moredata, free the buffer first

    if (usReturnCode && usReturnCode != ERROR_MORE_DATA &&
	usReturnCode != NERR_BufTooSmall) {
	    NetApiBufferFree(*ppBuffer);
    }

    return (usReturnCode);

}
Exemple #24
0
enum System::userlevel System::userPermissions(void)
{
    LPUSER_INFO_1 buf = NULL;
    wchar_t userbuf[UNLEN];
    DWORD usersize = UNLEN;
    BOOL status;
    enum userlevel result = ERR;

    status = GetUserNameW(userbuf, &usersize);
    if(!status)
        return ERR;

    if(NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf) == NERR_Success) {
        switch(buf->usri1_priv) {
            case USER_PRIV_GUEST:
                result = GUEST;
                break;
            case USER_PRIV_USER:
                result = USER;
                break;
            case USER_PRIV_ADMIN:
                result = ADMIN;
                break;
            default:
                result = ERR;
                break;
        }
    }
    if(buf != NULL)
        NetApiBufferFree(buf);

    return result;
}
Exemple #25
0
bool LdapUtils::getDcName(const char* domain, StringBuffer& dc)
{
    bool ret = false;
#ifdef _WIN32
    PDOMAIN_CONTROLLER_INFO psInfo = NULL;
    DWORD dwErr = DsGetDcName(NULL, domain, NULL, NULL, DS_FORCE_REDISCOVERY | DS_DIRECTORY_SERVICE_REQUIRED, &psInfo);
    if( dwErr == NO_ERROR)
    {
        const char* dcname = psInfo->DomainControllerName;
        if(dcname != NULL)
        {
            while(*dcname == '\\')
                dcname++;

            dc.append(dcname);
            ret = true;
        }
        NetApiBufferFree(psInfo);
    }
    else
    {
        DBGLOG("Error getting domain controller, error = %d", dwErr);
        ret = false;
    }
#endif
    return ret;
}
Exemple #26
0
bool CWfpNET::Time_get(void) // Obtain Date and Time
{
	LPTIME_OF_DAY_INFO pTOD = NULL;
	NET_API_STATUS nStatus = NULL;
	DWORD mindiff = 0, hourdiff = 0;
	CString tmp;
	
	// The NetRemoteTOD function returns the time of day information from
	// a specified server.
	// No special group membership is required to successfully execute the
	// NetRemoteTOD function.

	nStatus = NetRemoteTOD(node.szComputerW, (LPBYTE *)&pTOD);
	
	if(nStatus == NERR_Success)
	{
		if(pTOD != NULL)
		{
			tmp.Format(_T("Date and Time:\n\t[%d/%d/%d] "),pTOD->tod_month, pTOD->tod_day, pTOD->tod_year);
			Time.Add(tmp);
			tmp.Format(_T(" -- %02lu:%02lu:%02lu.%02lu\n"), pTOD->tod_hours - (pTOD->tod_timezone / 60), pTOD->tod_mins, pTOD->tod_secs, pTOD->tod_hunds); 
			Time.Add(tmp);		
		}
	}
	else
	{
		ErrorHandler("NetRemoteTOD", nStatus);
	    return false;
	}
	if(pTOD != NULL)
      NetApiBufferFree(pTOD);

	return true;
}
Exemple #27
0
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
	unsigned char MACData[8];						// Allocate data structure for MAC (6 bytes needed)

	WKSTA_TRANSPORT_INFO_0 *pwkti;					// Allocate data structure for Netbios
	DWORD dwEntriesRead;
	DWORD dwTotalEntries;
	BYTE *pbBuffer;

	// Get MAC address via NetBios's enumerate function
	NET_API_STATUS dwStatus = NetWkstaTransportEnum(
		NULL,						// [in]  server name
		0,							// [in]  data structure to return
		&pbBuffer,					// [out] pointer to buffer
		MAX_PREFERRED_LENGTH,		// [in]  maximum length
		&dwEntriesRead,				// [out] counter of elements actually enumerated
		&dwTotalEntries,			// [out] total number of elements that could be enumerated
		NULL);						// [in/out] resume handle
	assert(dwStatus == NERR_Success);

	pwkti = (WKSTA_TRANSPORT_INFO_0 *)pbBuffer;		// type cast the buffer

	for (DWORD i = 0; i< dwEntriesRead; i++)			// first address is 00000000, skip it
	{												// enumerate MACs and print
		swscanf((wchar_t *)pwkti[i].wkti0_transport_address, L"%2hx%2hx%2hx%2hx%2hx%2hx",
			&MACData[0], &MACData[1], &MACData[2], &MACData[3], &MACData[4], &MACData[5]);
		PrintMACaddress(MACData);
	}

	// Release pbBuffer allocated by above function
	dwStatus = NetApiBufferFree(pbBuffer);
	assert(dwStatus == NERR_Success);
}
Exemple #28
0
/***
 *  check_max_uses()
 *
 *      Check if a share has a /USERS:n switch or a /UNLIMITED
 *      switch.  If not, set max_users to the value of num_admin.
 *
 *      Currently used only on the ADMIN$ share.
 *
 *  Args:
 *      none
 *
 *  Returns:
 *      nothing - success
 *      exit(2) - command failed
 */
VOID NEAR check_max_uses(VOID)
{
    USHORT          err;                /* API return status */
    int                     i;
    struct server_info_2 FAR *      server_entry;
    TCHAR FAR *              ptr;
    USHORT2ULONG            swlen1, swlen2 ;
    static TCHAR             users_switch[20] ;

    _tcscpy(users_switch,swtxt_SW_SHARE_USERS);
    swlen1 = _tcslen(users_switch);
    swlen2 = _tcslen(swtxt_SW_SHARE_UNLIMITED);
    for (i = 0; SwitchList[i]; i++)
    {
        if ( (strncmpf(SwitchList[i], users_switch, swlen1) == 0) ||
             (strncmpf(SwitchList[i], swtxt_SW_SHARE_UNLIMITED, swlen2) == 0)
           )
        {
            return;     //  A specific switch exists; return without
                        //  further action.
        }
    }

    if (err = MNetServerGetInfo(NULL,
                                2,
                                (LPBYTE*)&server_entry))
        ErrorExit (err);

    ptr = _tcschr(users_switch, NULLC);
    nsprintf(ptr, TEXT(":%u"), server_entry->sv2_numadmin);

    SwitchList[i] = users_switch;
    NetApiBufferFree((TCHAR FAR *) server_entry);
}
Exemple #29
0
USHORT MNetAccessEnum (
    const CHAR	     FAR * pszServer,
    CHAR	     FAR * pszBasePath,
    USHORT	     fsRecursive,
    SHORT	     Level,
    CHAR FAR **      ppBuffer,
    USHORT     FAR * pcEntriesRead ) {

    USHORT				       usReturnCode,
					       cbTotalAvail;
    SEL 				       sel;

    // get a 4K buffer
    *ppBuffer = MGetBuffer(BIG_BUFFER_SIZE);
    if (*ppBuffer == NULL)
    {
	return(ERROR_NOT_ENOUGH_MEMORY);
    }

    usReturnCode = NetAccessEnum(pszServer, pszBasePath, fsRecursive, Level,
	    *ppBuffer, BIG_BUFFER_SIZE, pcEntriesRead, & cbTotalAvail);
		
    // is there more data? if so, allocate a big enough buffer to get it
    if(usReturnCode == ERROR_MORE_DATA || usReturnCode == NERR_BufTooSmall)
    {
	NetApiBufferFree(*ppBuffer);

	if (DEBUGALLOC(FULL_SEG_BUFFER_SIZE, & sel, SEG_NONSHARED))
	{
	    return(ERROR_NOT_ENOUGH_MEMORY);
	}
	*ppBuffer = MAKEP(sel, 0);
	usReturnCode = NetAccessEnum(pszServer, pszBasePath, fsRecursive, Level,
	    *ppBuffer, FULL_SEG_BUFFER_SIZE, pcEntriesRead, & cbTotalAvail);
    }

    // If we're returning an error that's not moredata, or there are no
    // entries to return, free the buffer first

    if ((usReturnCode && usReturnCode != ERROR_MORE_DATA &&
	usReturnCode != NERR_BufTooSmall) || *pcEntriesRead == 0) {
	    NetApiBufferFree(*ppBuffer);
    }

    return (usReturnCode);

}
Exemple #30
0
static BOOL
SetUserGeneralData(HWND hwndDlg,
                   PGENERAL_USER_DATA pUserData)
{
    PUSER_INFO_3 pUserInfo = NULL;
    LPTSTR pszFullName = NULL;
    LPTSTR pszComment = NULL;
    NET_API_STATUS status;
    DWORD dwIndex;
    INT nLength;

    NetUserGetInfo(NULL, pUserData->szUserName, 3, (LPBYTE*)&pUserInfo);

    pUserInfo->usri3_flags =
        (pUserData->dwFlags & VALID_GENERAL_FLAGS) |
        (pUserInfo->usri3_flags & ~VALID_GENERAL_FLAGS);

    pUserInfo->usri3_password_expired = pUserData->dwPasswordExpired;

    nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_GENERAL_FULL_NAME));
    if (nLength == 0)
    {
        pUserInfo->usri3_full_name = NULL;
    }
    else
    {
        pszFullName = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
        GetDlgItemText(hwndDlg, IDC_USER_GENERAL_FULL_NAME, pszFullName, nLength + 1);
        pUserInfo->usri3_full_name = pszFullName;
    }

    nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_GENERAL_DESCRIPTION));
    if (nLength == 0)
    {
        pUserInfo->usri3_full_name = NULL;
    }
    else
    {
        pszComment = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
        GetDlgItemText(hwndDlg, IDC_USER_GENERAL_DESCRIPTION, pszComment, nLength + 1);
        pUserInfo->usri3_comment = pszComment;
    }

    status = NetUserSetInfo(NULL, pUserData->szUserName, 3, (LPBYTE)pUserInfo, &dwIndex);
    if (status != NERR_Success)
    {
        DebugPrintf(_T("Status: %lu  Index: %lu"), status, dwIndex);
    }

    if (pszFullName)
        HeapFree(GetProcessHeap(), 0, pszFullName);

    if (pszComment)
        HeapFree(GetProcessHeap(), 0, pszComment);

    NetApiBufferFree(pUserInfo);

    return (status == NERR_Success);
}