void CWE620_Unverified_Password_Change__w32_05_bad()
{
    if(staticTrue)
    {
        {
            wchar_t newPassword[256];
            USER_INFO_1003 myUserInfo;
            NET_API_STATUS status;
            myUserInfo.usri1003_password = newPassword;
            printWLine(L"Enter new password: "******"%255s", myUserInfo.usri1003_password) != 1)
            {
                myUserInfo.usri1003_password[0] = L'\0';
            }
            /* FLAW: Set password without verifying the old one */
            status = NetUserSetInfo(NULL, USERNAME, 1003, (LPBYTE)&myUserInfo, NULL);
            if(status == NERR_Success)
            {
                printWLine(L"Success!");
            }
            else
            {
                wprintf(L"NetUserSetInfo failed.  Status = %u = 0x%x\n", status, status);
            }
        }
    }
}
Exemple #2
0
/**
 * @brief
 * 		set_account_expiration - sets the expiry period for the account on the
 * 		specidied server.
 *
 * @param[in]	dnamew	-	account name
 * @param[in]	dctrlw	-	A pointer to a constant string that specifies
 * 							the DNS or NetBIOS name of the remote server
 * 							on which the function is to execute.
 * 							If this parameter is NULL, the local computer
 * 							is used.
 * @param[in]	unamew	-	A pointer to a constant string that specifies
 * 							the name of the user account for which to set
 * 							information.
 * @param[in]	expire	-	Specifies a DWORD value that indicates when the
 * 							user account expires.
 *
 * @return	int
 * @retval	0	: Set the account expiration date.
 * @retval	1	: Setting account expiration failed.
 */
int
set_account_expiration(wchar_t *dnamew, wchar_t *dctrlw, wchar_t *unamew, DWORD expire)
{
	USER_INFO_1017 ui;
	NET_API_STATUS nstatus;


	ui.usri1017_acct_expires = expire;

	if (for_info_only)
		nstatus = NERR_Success;
	else
		nstatus = NetUserSetInfo(dctrlw, unamew, 1017, (LPBYTE)&ui,
			NULL);

	if (nstatus == NERR_Success) {
		if (!for_info_only)
			fprintf(stderr,
				"Set account %S\\%S's expiration date\n",
				dnamew, unamew);
		return (0);
	}

	fprintf(stderr,
		"Setting account %S\\%S expiration failed = %d\n",
		dnamew, unamew, nstatus);
	return (1);

}
Exemple #3
0
/**
 * @brief
 * 		set_account_primary_group - set the primary group for the account.
 *
 * @param[in]	dnamew	-	account name
 * @param[in]	dctrlw	-	A pointer to a constant string that specifies
 * 							the DNS or NetBIOS name of the remote server
 * 							on which the function is to execute.
 * 							If this parameter is NULL, the local computer
 * 							is used.
 * @param[in]	unamew	-	A pointer to a constant string that specifies
 * 							the name of the user account for which to set
 * 							information.
 * @param[in]	group_rid	-	Specifies a DWORD value that contains the
 * 							RID of the Primary Global Group for the user
 * 							specified in the username parameter to the
 * 							NetUserSetInfo function. This member must be
 * 							the RID of a global group that represents the
 * 							enrolled user.
 *
 * @return	int
 * @retval	0	: Set the account primary group.
 * @retval	1	: Setting account primary group failed.
 */
int
set_account_primary_group(wchar_t *dnamew, wchar_t *dctrlw, wchar_t *unamew, DWORD group_rid)
{
	USER_INFO_1051 ui;
	NET_API_STATUS nstatus;


	ui.usri1051_primary_group_id = group_rid;

	if (for_info_only)
		nstatus = NERR_Success;
	else
		nstatus = NetUserSetInfo(dctrlw, unamew, 1051, (LPBYTE)&ui,
			NULL);

	if (nstatus == NERR_Success) {
		if (!for_info_only)
			fprintf(stderr,
				"Set account %S\\%S's primary group\n",
				dnamew, unamew);
		return (0);
	}

	fprintf(stderr,
		"setting account %S\\%S's primary group failed = %d\n",
		dnamew, unamew, nstatus);
	return (1);

}
Exemple #4
0
bool UserUtilities::ChangeAccountInfo(Account* account)
{
	USER_INFO_2 *userInfo = new USER_INFO_2();
	DWORD error = 0;
	DWORD level;
	DWORD res;

	int getRes = NetUserGetInfo(NULL, account->m_StrUserName, 2, (LPBYTE*)&userInfo);
	if(getRes != 0)
	{
		return false;
	}
	else
	{
		userInfo->usri2_full_name = account->m_StrFullName.GetBuffer();
		userInfo->usri2_password = account->m_StrPassword.GetBuffer();
		userInfo->usri2_comment = account->m_StrDescription.GetBuffer();

		res = NetUserSetInfo(NULL, account->m_StrUserName, 2, (LPBYTE)userInfo, &error);
		if(res == 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	return true;
}
Exemple #5
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);
}
Exemple #6
0
static BOOL
OnEndLabelEdit(LPNMLVDISPINFO pnmv)
{
    TCHAR szOldUserName[UNLEN];
    TCHAR szNewUserName[UNLEN];
    USER_INFO_0 useri0;
    NET_API_STATUS status;

    /* Leave, if there is no valid listview item */
    if (pnmv->item.iItem == -1)
        return FALSE;

    /* Get the new user name */
    ListView_GetItemText(pnmv->hdr.hwndFrom,
                         pnmv->item.iItem, 0,
                         szOldUserName,
                         UNLEN);

    /* Leave, if the user canceled the edit action */
    if (pnmv->item.pszText == NULL)
        return FALSE;

    /* Get the new user name */
    lstrcpy(szNewUserName, pnmv->item.pszText);

    /* Leave, if the user name was not changed */
    if (lstrcmp(szOldUserName, szNewUserName) == 0)
        return FALSE;

    /* Check the user name for illegal characters */
    if (!CheckAccountName(NULL, 0, szNewUserName))
        return FALSE;

    /* Change the user name */
    useri0.usri0_name = szNewUserName;

#if 0
    status = NetUserSetInfo(NULL, szOldUserName, 0, (LPBYTE)&useri0, NULL);
#else
    status = NERR_Success;
#endif
    if (status != NERR_Success)
    {
        TCHAR szText[256];
        wsprintf(szText, TEXT("Error: %u"), status);
        MessageBox(NULL, szText, TEXT("NetUserSetInfo"), MB_ICONERROR | MB_OK);
        return FALSE;
    }

    /* Update the listview item */
    ListView_SetItemText(pnmv->hdr.hwndFrom,
                         pnmv->item.iItem, 0,
                         szNewUserName);

    return TRUE;
}
Exemple #7
0
/**
 * Set user account controls.
 *
 * @param appContext Application context reference.
 * @param userNameC User name.
 * @param flags Account controls.
 * @return 0 on success; error code on failure.
 */
DWORD
AdtNetUserSetInfoFlags(
    IN AppContextTP appContext,
    IN PSTR  userNameC,
    IN DWORD flags
)
{
   DWORD dwError = ERROR_SUCCESS;
   DWORD parmErr = 0;
   PWSTR hostName = NULL;
   PWSTR userName = NULL;
   PSTR  userNameN = NULL;
   USER_INFO_1008 info1008;

   userNameN = GetNameComp(userNameC);

   dwError = LwMbsToWc16s((PCSTR) (appContext->workConn->serverName), &hostName);
   ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

   dwError = LwMbsToWc16s((PCSTR) userNameN, &userName);
   ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

   PrintStderr(appContext, LogLevelTrace, "%s: Changing control flags of user %s ...\n",
               appContext->actionName, userNameN);

   /* Perform the modify operation. */
   if (!appContext->gopts.isReadOnly) {
        info1008.usri1008_flags = flags;

        dwError = NetUserSetInfo(hostName,
                                 userName,
                                 1008,
                                 (PVOID) &info1008,
                                 &parmErr);

        if (dwError) {
            dwError += ADT_WIN_ERR_BASE;
            ADT_BAIL_ON_ERROR_NP(dwError);
        }
    }

    PrintStderr(appContext, LogLevelTrace, "%s: Done changing control flags of user %s\n",
               appContext->actionName, userNameN);

   cleanup:
       LW_SAFE_FREE_MEMORY(hostName);
       LW_SAFE_FREE_MEMORY(userName);
       LW_SAFE_FREE_MEMORY(userNameN);

       return dwError;

   error:
       goto cleanup;
}
Exemple #8
0
static VOID
UserChangePassword(HWND hwndDlg)
{
    TCHAR szUserName[UNLEN];
    USER_INFO_1003 user;
    INT nItem;
    HWND hwndLV;
    NET_API_STATUS status;

    ZeroMemory(&user, sizeof(USER_INFO_1003));

    hwndLV = GetDlgItem(hwndDlg, IDC_USERS_LIST);
    nItem = ListView_GetNextItem(hwndLV, -1, LVNI_SELECTED);
    if (nItem == -1)
        return;

    /* Get the new user name */
    ListView_GetItemText(hwndLV,
                         nItem, 0,
                         szUserName,
                         UNLEN);

    if (DialogBoxParam(hApplet,
                       MAKEINTRESOURCE(IDD_CHANGE_PASSWORD),
                       hwndDlg,
                       ChangePasswordDlgProc,
                       (LPARAM)&user) == IDOK)
    {
        status = NetUserSetInfo(NULL,
                                szUserName,
                                1003,
                                (LPBYTE)&user,
                                NULL);
        if (status != NERR_Success)
        {
            TCHAR szText[256];
            wsprintf(szText, TEXT("Error: %u"), status);
            MessageBox(NULL, szText, TEXT("NetUserSetInfo"), MB_ICONERROR | MB_OK);
        }
    }

    if (user.usri1003_password)
        HeapFree(GetProcessHeap(), 0, user.usri1003_password);
}
Exemple #9
0
APIERR MNetUserSetInfo(
	const TCHAR FAR	 * pszServer,
	TCHAR FAR	 * pszUserName,
	UINT	        Level,
	BYTE FAR	 * pbBuffer,
	UINT		   cbBuffer,
	UINT		   ParmNum )
{
    UNREFERENCED( cbBuffer );

    if( ParmNum != PARMNUM_ALL )
    {
    	return ERROR_NOT_SUPPORTED;
    }

    return (APIERR)NetUserSetInfo( (TCHAR *)pszServer,
				   pszUserName,
				   Level,
				   pbBuffer,
				   NULL );

}   // MNetUserSetInfo
Exemple #10
0
/**
 * Modify AD user account.
 *
 * @param appContext Application context reference.
 * @param level Info level.
 * @param userNameC User name.
 * @param fullNameC Full user name.
 * @param commentC Comments.
 * @param homeDirC User's home directory
 * @param scriptPathC Full path to executable logon script
 * @param passwordC Password
 * @param flags Account controls
 * @param isRenamed Will be set to true is the accont has been renamed.
 * @return 0 on success; error code on failure.
 */
DWORD
AdtNetUserSetInfoFromParams(
    IN AppContextTP appContext,
    IN DWORD level,
    IN PSTR  userNameC,
    IN PSTR  changedUserNameC,
    IN PSTR  fullNameC,
    IN PSTR  commentC,
    IN PSTR  homeDirC,
    IN PSTR  scriptPathC,
    IN PSTR  passwordC,
    IN DWORD flags,
    IN PBOOL isRenamed
)
{
    DWORD dwError = ERROR_SUCCESS;
    PVOID pBuffer = NULL;
    USER_INFO_0 Info0 = {0};
    USER_INFO_1 Info1 = {0};
    USER_INFO_2 Info2 = {0};
    USER_INFO_3 Info3 = {0};
    USER_INFO_4 Info4 = {0};
    USER_INFO_1003 Info1003 = {0};
    USER_INFO_1007 Info1007 = {0};
    USER_INFO_1008 Info1008 = {0};
    USER_INFO_1011 Info1011 = {0};
    DWORD parmErr = 0;

    PWSTR hostName = NULL;
    PWSTR userName = NULL;
    PWSTR changedUserName = NULL;
    PWSTR fullName = NULL;
    PWSTR comment = NULL;
    PWSTR homeDir = NULL;
    PWSTR scriptPath = NULL;
    PWSTR password = NULL;
    PSTR  userNameN = NULL;

    userNameN = GetNameComp(userNameC);

    dwError = LwMbsToWc16s((PCSTR) (appContext->workConn->serverAddress), &hostName);
    ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

    dwError = LwMbsToWc16s((PCSTR) userNameN, &userName);
    ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

    if(changedUserNameC) {
        dwError = LwMbsToWc16s((PCSTR) changedUserNameC, &changedUserName);
        ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);
    }

    if (fullNameC) {
        dwError = LwMbsToWc16s((PCSTR) fullNameC, &fullName);
        ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);
    }

    if (commentC) {
        dwError = LwMbsToWc16s((PCSTR) commentC, &comment);
        ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);
    }

    if (homeDirC) {
        dwError = LwMbsToWc16s((PCSTR) homeDirC, &homeDir);
        ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);
    }

    if (scriptPathC) {
        dwError = LwMbsToWc16s((PCSTR) scriptPathC, &scriptPath);
        ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);
    }

    if (passwordC) {
        dwError = LwMbsToWc16s((PCSTR) passwordC, &password);
        ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);
    }

    switch (level)
    {
    case 0:
        Info0.usri0_name        = changedUserName;

        pBuffer = (PVOID)&Info0;
        break;

    case 1:
        Info1.usri1_name        = userName;
        Info1.usri1_password    = password;
        Info1.usri1_priv        = USER_PRIV_USER;
        Info1.usri1_home_dir    = homeDir;
        Info1.usri1_comment     = comment;
        Info1.usri1_flags       = flags;
        Info1.usri1_script_path = scriptPath;

        pBuffer = (PVOID)&Info1;
        break;

    case 2:
        Info2.usri2_name        = userName;
        Info2.usri2_password    = password;
        Info2.usri2_priv        = USER_PRIV_USER;
        Info2.usri2_home_dir    = homeDir;
        Info2.usri2_comment     = comment;
        Info2.usri2_flags       = flags;
        Info2.usri2_script_path = scriptPath;

        pBuffer = (PVOID)&Info2;
        break;

    case 3:
        Info3.usri3_name        = userName;
        Info3.usri3_password    = password;
        Info3.usri3_priv        = USER_PRIV_USER;
        Info3.usri3_home_dir    = homeDir;
        Info3.usri3_comment     = comment;
        Info3.usri3_flags       = flags;
        Info3.usri3_script_path = scriptPath;

        pBuffer = (PVOID)&Info3;
        break;

    case 4:
        Info4.usri4_name        = userName;
        Info4.usri4_password    = password;
        Info4.usri4_priv        = USER_PRIV_USER;
        Info4.usri4_home_dir    = homeDir;
        Info4.usri4_comment     = comment;
        Info4.usri4_flags       = flags;
        Info4.usri4_script_path = scriptPath;

        pBuffer = (PVOID)&Info4;
        break;

    case 1003:
        Info1003.usri1003_password = password;

        pBuffer = (PVOID)&Info1003;
        break;

    case 1007:
        Info1007.usri1007_comment = comment;

        pBuffer = (PVOID)&Info1007;
        break;

    case 1008:
        Info1008.usri1008_flags = flags;

        pBuffer = (PVOID)&Info1008;
        break;

    case 1011:
        Info1011.usri1011_full_name = fullName;

        pBuffer = (PVOID)&Info1011;
        break;
    }

    PrintStderr(appContext, LogLevelTrace, "%s: Changing properties of user %s ...\n",
                appContext->actionName, userNameN);

    /* Perform the modify operation. */
    if(!appContext->gopts.isReadOnly) {
        dwError = NetUserSetInfo(hostName, userName, level, pBuffer, &parmErr);
    }

    if (dwError) {
        dwError += ADT_WIN_ERR_BASE;
        ADT_BAIL_ON_ERROR_NP(dwError);
    }

    PrintStderr(appContext, LogLevelTrace, "%s: Done changing properties of user %s\n",
                appContext->actionName, userNameN);

    if (level == 0 && isRenamed) {
        *isRenamed = TRUE;
    }

    cleanup:
        LW_SAFE_FREE_MEMORY(hostName);
        LW_SAFE_FREE_MEMORY(userName);
        LW_SAFE_FREE_MEMORY(changedUserName);
        LW_SAFE_FREE_MEMORY(fullName);
        LW_SAFE_FREE_MEMORY(comment);
        LW_SAFE_FREE_MEMORY(homeDir);
        LW_SAFE_FREE_MEMORY(scriptPath);
        LW_SAFE_FREE_MEMORY(password);
        LW_SAFE_FREE_MEMORY(userNameN);

        return dwError;

    error:
        goto cleanup;
}
Exemple #11
0
INT
cmdUser(
    INT argc,
    WCHAR **argv)
{
    INT i, j;
    INT result = 0;
    BOOL bAdd = FALSE;
    BOOL bDelete = FALSE;
#if 0
    BOOL bDomain = FALSE;
#endif
    BOOL bRandomPassword = FALSE;
    LPWSTR lpUserName = NULL;
    LPWSTR lpPassword = NULL;
    PUSER_INFO_4 pUserInfo = NULL;
    USER_INFO_4 UserInfo;
    LPWSTR pWorkstations = NULL;
    LPWSTR p;
    LPWSTR endptr;
    DWORD value;
    BOOL bPasswordAllocated = FALSE;
    NET_API_STATUS Status;

    i = 2;
    if ((i < argc) && (argv[i][0] != L'/'))
    {
        lpUserName = argv[i];
//        ConPrintf(StdOut, L"User: %s\n", lpUserName);
        i++;
    }

    if ((i < argc) && (argv[i][0] != L'/'))
    {
        lpPassword = argv[i];
//        ConPrintf(StdOut, L"Password: %s\n", lpPassword);
        i++;
    }

    for (j = i; j < argc; j++)
    {
        if (_wcsicmp(argv[j], L"/help") == 0)
        {
            PrintNetMessage(MSG_USER_HELP);
            return 0;
        }
        else if (_wcsicmp(argv[j], L"/add") == 0)
        {
            bAdd = TRUE;
        }
        else if (_wcsicmp(argv[j], L"/delete") == 0)
        {
            bDelete = TRUE;
        }
        else if (_wcsicmp(argv[j], L"/domain") == 0)
        {
            ConPuts(StdErr, L"The /DOMAIN option is not supported yet.\n");
#if 0
            bDomain = TRUE;
#endif
        }
        else if (_wcsicmp(argv[j], L"/random") == 0)
        {
            bRandomPassword = TRUE;
            GenerateRandomPassword(&lpPassword,
                                   &bPasswordAllocated);
        }
    }

    if (lpUserName == NULL && lpPassword == NULL)
    {
        Status = EnumerateUsers();
        ConPrintf(StdOut, L"Status: %lu\n", Status);
        return 0;
    }
    else if (lpUserName != NULL && lpPassword == NULL)
    {
        Status = DisplayUser(lpUserName);
        ConPrintf(StdOut, L"Status: %lu\n", Status);
        return 0;
    }

    if (bAdd && bDelete)
    {
        result = 1;
        goto done;
    }

    /* Interactive password input */
    if (lpPassword != NULL && wcscmp(lpPassword, L"*") == 0)
    {
        ReadPassword(&lpPassword,
                     &bPasswordAllocated);
    }

    if (!bAdd && !bDelete)
    {
        /* Modify the user */
        Status = NetUserGetInfo(NULL,
                                lpUserName,
                                4,
                                (LPBYTE*)&pUserInfo);
        if (Status != NERR_Success)
        {
            ConPrintf(StdOut, L"Status: %lu\n", Status);
            result = 1;
            goto done;
        }
    }
    else if (bAdd && !bDelete)
    {
        /* Add the user */
        ZeroMemory(&UserInfo, sizeof(USER_INFO_4));

        UserInfo.usri4_name = lpUserName;
        UserInfo.usri4_password = lpPassword;
        UserInfo.usri4_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT;
        UserInfo.usri4_acct_expires = TIMEQ_FOREVER;
        UserInfo.usri4_primary_group_id = DOMAIN_GROUP_RID_USERS;

        pUserInfo = &UserInfo;
    }

    for (j = i; j < argc; j++)
    {
        if (_wcsnicmp(argv[j], L"/active:", 8) == 0)
        {
            p = &argv[i][8];
            if (_wcsicmp(p, L"yes") == 0)
            {
                pUserInfo->usri4_flags &= ~UF_ACCOUNTDISABLE;
            }
            else if (_wcsicmp(p, L"no") == 0)
            {
                pUserInfo->usri4_flags |= UF_ACCOUNTDISABLE;
            }
            else
            {
                PrintMessageStringV(3952, L"/ACTIVE");
                result = 1;
                goto done;
            }
        }
        else if (_wcsnicmp(argv[j], L"/comment:", 9) == 0)
        {
            pUserInfo->usri4_comment = &argv[j][9];
        }
        else if (_wcsnicmp(argv[j], L"/countrycode:", 13) == 0)
        {
            p = &argv[i][13];
            value = wcstoul(p, &endptr, 10);
            if (*endptr != 0)
            {
                PrintMessageStringV(3952, L"/COUNTRYCODE");
                result = 1;
                goto done;
            }

            /* Verify the country code */
            if (GetCountryFromCountryCode(value, 0, NULL))
                pUserInfo->usri4_country_code = value;
        }
        else if (_wcsnicmp(argv[j], L"/expires:", 9) == 0)
        {
            p = &argv[i][9];
            if (_wcsicmp(p, L"never") == 0)
            {
                pUserInfo->usri4_acct_expires = TIMEQ_FOREVER;
            }
            else if (!ParseDate(p, &pUserInfo->usri4_acct_expires))
            {
                PrintMessageStringV(3952, L"/EXPIRES");
                result = 1;
                goto done;
            }
        }
        else if (_wcsnicmp(argv[j], L"/fullname:", 10) == 0)
        {
            pUserInfo->usri4_full_name = &argv[j][10];
        }
        else if (_wcsnicmp(argv[j], L"/homedir:", 9) == 0)
        {
            pUserInfo->usri4_home_dir = &argv[j][9];
        }
        else if (_wcsnicmp(argv[j], L"/passwordchg:", 13) == 0)
        {
            p = &argv[i][13];
            if (_wcsicmp(p, L"yes") == 0)
            {
                pUserInfo->usri4_flags &= ~UF_PASSWD_CANT_CHANGE;
            }
            else if (_wcsicmp(p, L"no") == 0)
            {
                pUserInfo->usri4_flags |= UF_PASSWD_CANT_CHANGE;
            }
            else
            {
                PrintMessageStringV(3952, L"/PASSWORDCHG");
                result = 1;
                goto done;
            }
        }
        else if (_wcsnicmp(argv[j], L"/passwordreq:", 13) == 0)
        {
            p = &argv[i][13];
            if (_wcsicmp(p, L"yes") == 0)
            {
                pUserInfo->usri4_flags &= ~UF_PASSWD_NOTREQD;
            }
            else if (_wcsicmp(p, L"no") == 0)
            {
                pUserInfo->usri4_flags |= UF_PASSWD_NOTREQD;
            }
            else
            {
                PrintMessageStringV(3952, L"/PASSWORDREQ");
                result = 1;
                goto done;
            }
        }
        else if (_wcsnicmp(argv[j], L"/profilepath:", 13) == 0)
        {
            pUserInfo->usri4_profile = &argv[j][13];
        }
        else if (_wcsnicmp(argv[j], L"/scriptpath:", 12) == 0)
        {
            pUserInfo->usri4_script_path = &argv[j][12];
        }
        else if (_wcsnicmp(argv[j], L"/times:", 7) == 0)
        {
            /* FIXME */
            ConPuts(StdErr, L"The /TIMES option is not supported yet.\n");
        }
        else if (_wcsnicmp(argv[j], L"/usercomment:", 13) == 0)
        {
            pUserInfo->usri4_usr_comment = &argv[j][13];
        }
        else if (_wcsnicmp(argv[j], L"/workstations:", 14) == 0)
        {
            p = &argv[i][14];
            if (wcscmp(p, L"*") == 0 || wcscmp(p, L"") == 0)
            {
                pUserInfo->usri4_workstations = NULL;
            }
            else
            {
                Status = BuildWorkstationsList(&pWorkstations, p);
                if (Status == NERR_Success)
                {
                    pUserInfo->usri4_workstations = pWorkstations;
                }
                else
                {
                    ConPrintf(StdOut, L"Status %lu\n\n", Status);
                    result = 1;
                    goto done;
                }
            }
        }
    }

    if (!bAdd && !bDelete)
    {
        /* Modify the user */
        Status = NetUserSetInfo(NULL,
                                lpUserName,
                                4,
                                (LPBYTE)pUserInfo,
                                NULL);
        ConPrintf(StdOut, L"Status: %lu\n", Status);
    }
    else if (bAdd && !bDelete)
    {
        /* Add the user */
        Status = NetUserAdd(NULL,
                            4,
                            (LPBYTE)pUserInfo,
                            NULL);
        ConPrintf(StdOut, L"Status: %lu\n", Status);
    }
    else if (!bAdd && bDelete)
    {
        /* Delete the user */
        Status = NetUserDel(NULL,
                            lpUserName);
        ConPrintf(StdOut, L"Status: %lu\n", Status);
    }

    if (Status == NERR_Success &&
        lpPassword != NULL &&
        bRandomPassword == TRUE)
    {
        PrintMessageStringV(3968, lpUserName, lpPassword);
    }

done:
    if (pWorkstations != NULL)
        HeapFree(GetProcessHeap(), 0, pWorkstations);

    if ((bPasswordAllocated == TRUE) && (lpPassword != NULL))
        HeapFree(GetProcessHeap(), 0, lpPassword);

    if (!bAdd && !bDelete && pUserInfo != NULL)
        NetApiBufferFree(pUserInfo);

    if (result != 0)
    {
        PrintMessageString(4381);
        ConPuts(StdOut, L"\n");
        PrintNetMessage(MSG_USER_SYNTAX);
    }

    return result;
}
Exemple #12
0
/////////////////////////////////////////////////////////////////////
// 
// Function:    
//
// Description: 
//
/////////////////////////////////////////////////////////////////////
UINT CACreateBOINCAccounts::OnExecution()
{
    tstring          strBOINCMasterAccountUsername;
    tstring          strBOINCMasterAccountPassword;
    tstring          strBOINCProjectAccountUsername;
    tstring          strBOINCProjectAccountPassword;
    tstring          strComputerName;
    tstring          strProductType;
    tstring          strDataDirectory;
    tstring          strEnableProtectedApplicationExecution;
    PSID             pSid;
    NET_API_STATUS   nasReturnValue;
    BOOL             bCreateBOINCMasterAccount = FALSE;
    BOOL             bCreateBOINCProjectAccount = FALSE;
    BOOL             bBOINCMasterAccountCreated = FALSE;
    BOOL             bBOINCProjectAccountCreated = FALSE;
    BOOL             bBOINCMasterAccountModified = FALSE;
    BOOL             bBOINCProjectAccountModified = FALSE;
    UINT             uiReturnValue = -1;

    uiReturnValue = GetProperty( _T("BOINC_MASTER_USERNAME"), strBOINCMasterAccountUsername );
    if ( uiReturnValue ) return uiReturnValue;

    uiReturnValue = GetProperty( _T("BOINC_MASTER_PASSWORD"), strBOINCMasterAccountPassword );
    if ( uiReturnValue ) return uiReturnValue;

    uiReturnValue = GetProperty( _T("BOINC_PROJECT_USERNAME"), strBOINCProjectAccountUsername );
    if ( uiReturnValue ) return uiReturnValue;

    uiReturnValue = GetProperty( _T("BOINC_PROJECT_PASSWORD"), strBOINCProjectAccountPassword );
    if ( uiReturnValue ) return uiReturnValue;

    uiReturnValue = GetProperty( _T("ComputerName"), strComputerName );
    if ( uiReturnValue ) return uiReturnValue;

    uiReturnValue = GetProperty( _T("MsiNTProductType"), strProductType );
    if ( uiReturnValue ) return uiReturnValue;

    uiReturnValue = GetProperty( _T("ENABLEPROTECTEDAPPLICATIONEXECUTION3"), strEnableProtectedApplicationExecution );
    if ( uiReturnValue ) return uiReturnValue;



    // Only create a new account or change the password on an existing account
    //   if the user hasn't explicitly defined an account
    if (strBOINCMasterAccountUsername.empty() && strBOINCMasterAccountPassword.empty()) bCreateBOINCMasterAccount = true;
    if (strBOINCMasterAccountUsername == _T("boinc_master")) bCreateBOINCMasterAccount = true;
    if (strProductType == tstring(_T("2")) && (strBOINCMasterAccountUsername == (tstring(_T("boinc_master_")) + strComputerName))) bCreateBOINCMasterAccount = true;

    if (bCreateBOINCMasterAccount) {

        LogMessage(
            INSTALLMESSAGE_INFO,
            NULL, 
            NULL,
            NULL,
            NULL,
            _T("Using automatic account creation and management of 'boinc_master' account")
        );

        // Determine what the real values of the usernames should be based off
        //   of the inputs
        //
        if (strBOINCMasterAccountUsername.empty()) {
            LogMessage(
                INSTALLMESSAGE_INFO,
                NULL, 
                NULL,
                NULL,
                NULL,
                _T("Generating 'boinc_master' account name")
            );
            if (strProductType == tstring(_T("2"))) {                    // Domain Controller
                strBOINCMasterAccountUsername = _T("boinc_master_") + strComputerName;
            } else {
                strBOINCMasterAccountUsername = _T("boinc_master");
            }
        }


        // Generate random passwords if needed
        //
        if (strBOINCMasterAccountPassword.empty()) {
            LogMessage(
                INSTALLMESSAGE_INFO,
                NULL, 
                NULL,
                NULL,
                NULL,
                _T("Generating 'boinc_master' password")
            );
            GenerateRandomPassword(strBOINCMasterAccountPassword, 12);
            strBOINCMasterAccountPassword = _T("!") + strBOINCMasterAccountPassword;
        }


        // Create the 'boinc_master' account if needed, otherwise just update the password.
        //
        if(GetAccountSid(NULL, strBOINCMasterAccountUsername.c_str(), &pSid)) {   // Check if user exists

            LogMessage(
                INSTALLMESSAGE_INFO,
                NULL, 
                NULL,
                NULL,
                NULL,
                _T("Resetting 'boinc_master' password")
            );

            // Account already exists, just change the password
            //
            USER_INFO_1003 ui;
            DWORD          dwParameterError;

            ui.usri1003_password = (LPWSTR)strBOINCMasterAccountPassword.c_str();

            nasReturnValue = NetUserSetInfo(
                NULL,
                strBOINCMasterAccountUsername.c_str(),
                1003,
                (LPBYTE)&ui,
                &dwParameterError
            );

            if (NERR_Success != nasReturnValue) {
                LogMessage(
                    INSTALLMESSAGE_ERROR,
                    NULL, 
                    NULL,
                    NULL,
                    nasReturnValue,
                    _T("Failed to reset password on the 'boinc_master' account.")
                );
                return ERROR_INSTALL_FAILURE;
            }
        } else {

            LogMessage(
                INSTALLMESSAGE_INFO,
                NULL, 
                NULL,
                NULL,
                NULL,
                _T("Creating 'boinc_master' account")
            );

            // Account does not exist, create it
            //
            USER_INFO_1 ui;
            DWORD       dwParameterError;

            ui.usri1_name = (LPWSTR)strBOINCMasterAccountUsername.c_str();
            ui.usri1_password = (LPWSTR)strBOINCMasterAccountPassword.c_str();
            ui.usri1_comment = _T("Account used to execute BOINC as a system service");
            ui.usri1_priv = USER_PRIV_USER;
            ui.usri1_home_dir = NULL;
            ui.usri1_comment = NULL;
            ui.usri1_flags = UF_SCRIPT | UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD;
            ui.usri1_script_path = NULL;

            nasReturnValue = NetUserAdd(
                NULL,
                1,
                (LPBYTE)&ui,
                &dwParameterError
            );

            if (NERR_Success != nasReturnValue) {
                LogMessage(
                    INSTALLMESSAGE_INFO,
                    NULL, 
                    NULL,
                    NULL,
                    nasReturnValue,
                    _T("NetUserAdd retval")
                );
                LogMessage(
                    INSTALLMESSAGE_INFO,
                    NULL, 
                    NULL,
                    NULL,
                    dwParameterError,
                    _T("NetUserAdd dwParameterError")
                );
                LogMessage(
                    INSTALLMESSAGE_ERROR,
                    NULL, 
                    NULL,
                    NULL,
                    nasReturnValue,
                    _T("Failed to create the 'boinc_master' account.")
                );
                return ERROR_INSTALL_FAILURE;
            }

            bBOINCMasterAccountCreated = TRUE;
        }
        if(pSid != NULL) {
            HeapFree(GetProcessHeap(), 0, pSid);
            pSid = NULL;
        }

        bBOINCMasterAccountModified = TRUE;
    }

    // Only create a new account or change the password on an existing account
    //   if the user hasn't explicitly defined an account
    if (strBOINCProjectAccountUsername.empty() && strBOINCProjectAccountPassword.empty()) bCreateBOINCProjectAccount = true;
    if (strBOINCProjectAccountUsername == _T("boinc_project")) bCreateBOINCProjectAccount = true;
    if (strProductType == tstring(_T("2")) && (strBOINCProjectAccountUsername == (tstring(_T("boinc_project_")) + strComputerName))) bCreateBOINCProjectAccount = true;

    if (bCreateBOINCProjectAccount) {

        LogMessage(
            INSTALLMESSAGE_INFO,
            NULL, 
            NULL,
            NULL,
            NULL,
            _T("Using automatic account creation and management of 'boinc_project' account")
        );

        // Determine what the real values of the usernames should be based off
        //   of the inputs
        //
        if (strBOINCProjectAccountUsername.empty()) {
            LogMessage(
                INSTALLMESSAGE_INFO,
                NULL, 
                NULL,
                NULL,
                NULL,
                _T("Generating 'boinc_project' account name")
            );
            if (strProductType == tstring(_T("2"))) {                    // Domain Controller
                strBOINCProjectAccountUsername = _T("boinc_project_") + strComputerName;
            } else {
                strBOINCProjectAccountUsername = _T("boinc_project");
            }
        }


        // Generate random passwords if needed
        //
        if (strBOINCProjectAccountPassword.empty()) {
            LogMessage(
                INSTALLMESSAGE_INFO,
                NULL, 
                NULL,
                NULL,
                NULL,
                _T("Generating 'boinc_project' password")
            );
            GenerateRandomPassword(strBOINCProjectAccountPassword, 12);
            strBOINCProjectAccountPassword = _T("!") + strBOINCProjectAccountPassword;
        }


        // Create the 'boinc_project' account if needed, otherwise just update the password.
        //
        if(GetAccountSid(NULL, strBOINCProjectAccountUsername.c_str(), &pSid)) {   // Check if user exists

            LogMessage(
                INSTALLMESSAGE_INFO,
                NULL, 
                NULL,
                NULL,
                NULL,
                _T("Resetting 'boinc_project' password")
            );

            // Account already exists, just change the password
            //
            USER_INFO_1003 ui;
            DWORD          dwParameterError;

            ui.usri1003_password = (LPWSTR)strBOINCProjectAccountPassword.c_str();

            nasReturnValue = NetUserSetInfo(
                NULL,
                strBOINCProjectAccountUsername.c_str(),
                1003,
                (LPBYTE)&ui,
                &dwParameterError
            );

            if (NERR_Success != nasReturnValue) {
                LogMessage(
                    INSTALLMESSAGE_ERROR,
                    NULL, 
                    NULL,
                    NULL,
                    nasReturnValue,
                    _T("Failed to reset password on the 'boinc_project' account.")
                );
                return ERROR_INSTALL_FAILURE;
            }
        } else {

            LogMessage(
                INSTALLMESSAGE_INFO,
                NULL, 
                NULL,
                NULL,
                NULL,
                _T("Creating 'boinc_project' account")
            );

            // Account does not exist, create it
            //
            USER_INFO_1 ui;
            DWORD       dwParameterError;

            ui.usri1_name = (LPWSTR)strBOINCProjectAccountUsername.c_str();
            ui.usri1_password = (LPWSTR)strBOINCProjectAccountPassword.c_str();
            ui.usri1_comment = _T("Account used to execute BOINC applications");
            ui.usri1_priv = USER_PRIV_USER;
            ui.usri1_home_dir = NULL;
            ui.usri1_comment = NULL;
            ui.usri1_flags = UF_SCRIPT | UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD;
            ui.usri1_script_path = NULL;

            nasReturnValue = NetUserAdd(
                NULL,
                1,
                (LPBYTE)&ui,
                &dwParameterError
            );

            if (NERR_Success != nasReturnValue) {
                LogMessage(
                    INSTALLMESSAGE_INFO,
                    NULL, 
                    NULL,
                    NULL,
                    nasReturnValue,
                    _T("NetUserAdd retval")
                );
                LogMessage(
                    INSTALLMESSAGE_INFO,
                    NULL, 
                    NULL,
                    NULL,
                    dwParameterError,
                    _T("NetUserAdd dwParameterError")
                );
                LogMessage(
                    INSTALLMESSAGE_ERROR,
                    NULL, 
                    NULL,
                    NULL,
                    nasReturnValue,
                    _T("Failed to create the 'boinc_project' account.")
                );
                return ERROR_INSTALL_FAILURE;
            }

            bBOINCProjectAccountCreated = TRUE;
        }
        if(pSid != NULL) {
            HeapFree(GetProcessHeap(), 0, pSid);
            pSid = NULL;
        }

        bBOINCProjectAccountModified = TRUE;
    }


    SetProperty( _T("BOINC_MASTER_USERNAME"), strBOINCMasterAccountUsername );
    if (bBOINCMasterAccountModified) {
        SetProperty( _T("BOINC_MASTER_ISUSERNAME"), tstring(_T(".\\") + strBOINCMasterAccountUsername) );
    } else {
        SetProperty( _T("BOINC_MASTER_ISUSERNAME"), strBOINCMasterAccountUsername );
    }
    SetProperty( _T("BOINC_MASTER_PASSWORD"), strBOINCMasterAccountPassword, false );

    SetProperty( _T("BOINC_PROJECT_USERNAME"), strBOINCProjectAccountUsername );
    if (bBOINCProjectAccountModified) {
        SetProperty( _T("BOINC_PROJECT_ISUSERNAME"), tstring(_T(".\\") + strBOINCProjectAccountUsername) );
    } else {
        SetProperty( _T("BOINC_PROJECT_ISUSERNAME"), strBOINCProjectAccountUsername );
    }
    SetProperty( _T("BOINC_PROJECT_PASSWORD"), strBOINCProjectAccountPassword, false );

    if (bBOINCMasterAccountCreated || bBOINCProjectAccountCreated) {
        RebootWhenFinished();
    }

    return ERROR_SUCCESS;
}
Exemple #13
0
int main(int argc, const char **argv)
{
	NET_API_STATUS status;
	struct libnetapi_ctx *ctx = NULL;
	const char *hostname = NULL;
	const char *username = NULL;
	uint32_t level = 0;
	uint32_t parm_err = 0;
	uint8_t *buffer = NULL;
	const char *val = NULL;

	struct USER_INFO_0 u0;
	struct USER_INFO_1 u1;
	struct USER_INFO_2 u2;
	struct USER_INFO_3 u3;
	struct USER_INFO_4 u4;
	struct USER_INFO_21 u21;
	struct USER_INFO_22 u22;
	struct USER_INFO_1003 u1003;
	struct USER_INFO_1005 u1005;
	struct USER_INFO_1006 u1006;
	struct USER_INFO_1007 u1007;
	struct USER_INFO_1008 u1008;
	struct USER_INFO_1009 u1009;
	struct USER_INFO_1010 u1010;
	struct USER_INFO_1011 u1011;
	struct USER_INFO_1012 u1012;
	struct USER_INFO_1014 u1014;
	struct USER_INFO_1017 u1017;
	struct USER_INFO_1020 u1020;
	struct USER_INFO_1024 u1024;
	struct USER_INFO_1051 u1051;
	struct USER_INFO_1052 u1052;
	struct USER_INFO_1053 u1053;

	poptContext pc;
	int opt;

	struct poptOption long_options[] = {
		POPT_AUTOHELP
		POPT_COMMON_LIBNETAPI_EXAMPLES
		POPT_TABLEEND
	};

	status = libnetapi_init(&ctx);
	if (status != 0) {
		return status;
	}

	pc = poptGetContext("user_setinfo", argc, argv, long_options, 0);

	poptSetOtherOptionHelp(pc, "hostname username level");
	while((opt = poptGetNextOpt(pc)) != -1) {
	}

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	hostname = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	username = poptGetArg(pc);

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	level = atoi(poptGetArg(pc));

	if (!poptPeekArg(pc)) {
		poptPrintHelp(pc, stderr, 0);
		goto out;
	}
	val = poptGetArg(pc);

	/* NetUserSetInfo */

	switch (level) {
		case 0:
			u0.usri0_name = val;
			buffer = (uint8_t *)&u0;
			break;
		case 1:
		case 2:
		case 3:
		case 4:
			break;
		case 21:
			break;
		case 22:
			break;
		case 1003:
			u1003.usri1003_password = val;
			buffer = (uint8_t *)&u1003;
			break;
		case 1005:
			u1005.usri1005_priv = atoi(val);
			buffer = (uint8_t *)&u1005;
			break;
		case 1006:
			u1006.usri1006_home_dir = val;
			buffer = (uint8_t *)&u1006;
			break;
		case 1007:
			u1007.usri1007_comment = val;
			buffer = (uint8_t *)&u1007;
			break;
		case 1008:
			u1008.usri1008_flags = atoi(val);
			buffer = (uint8_t *)&u1008;
			break;
		case 1009:
			u1009.usri1009_script_path = val;
			buffer = (uint8_t *)&u1009;
			break;
		case 1010:
			u1010.usri1010_auth_flags = atoi(val);
			buffer = (uint8_t *)&u1010;
			break;
		case 1011:
			u1011.usri1011_full_name = val;
			buffer = (uint8_t *)&u1011;
			break;
		case 1012:
			u1012.usri1012_usr_comment = val;
			buffer = (uint8_t *)&u1012;
			break;
		case 1014:
			u1014.usri1014_workstations = val;
			buffer = (uint8_t *)&u1014;
			break;
		case 1017:
			u1017.usri1017_acct_expires = atoi(val);
			buffer = (uint8_t *)&u1017;
			break;
		case 1020:
			break;
		case 1024:
			u1024.usri1024_country_code = atoi(val);
			buffer = (uint8_t *)&u1024;
			break;
		case 1051:
			u1051.usri1051_primary_group_id = atoi(val);
			buffer = (uint8_t *)&u1051;
			break;
		case 1052:
			u1052.usri1052_profile = val;
			buffer = (uint8_t *)&u1052;
			break;
		case 1053:
			u1053.usri1053_home_dir_drive = val;
			buffer = (uint8_t *)&u1053;
			break;
		default:
			break;
	}

	status = NetUserSetInfo(hostname,
				username,
				level,
				buffer,
				&parm_err);
	if (status != 0) {
		printf("NetUserSetInfo failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
		goto out;
	}

 out:
	libnetapi_free(ctx);
	poptFreeContext(pc);

	return status;
}
Exemple #14
0
static BOOL
SetUserProfileData(HWND hwndDlg,
                   PPROFILE_USER_DATA pUserData)
{
    PUSER_INFO_3 pUserInfo = NULL;
    LPTSTR pszProfilePath = NULL;
    LPTSTR pszScriptPath = NULL;
    LPTSTR pszHomeDir = NULL;
    LPTSTR pszHomeDrive = NULL;
    NET_API_STATUS status;
#if 0
    DWORD dwIndex;
#endif
    INT nLength;
    INT nIndex;

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

    /* Get the profile path */
    nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_PATH));
    if (nLength == 0)
    {
        pUserInfo->usri3_profile = NULL;
    }
    else
    {
        pszProfilePath = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
        GetDlgItemText(hwndDlg, IDC_USER_PROFILE_PATH, pszProfilePath, nLength + 1);
        pUserInfo->usri3_profile = pszProfilePath;
    }

    /* Get the script path */
    nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_SCRIPT));
    if (nLength == 0)
    {
        pUserInfo->usri3_script_path = NULL;
    }
    else
    {
        pszScriptPath = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
        GetDlgItemText(hwndDlg, IDC_USER_PROFILE_SCRIPT, pszScriptPath, nLength + 1);
        pUserInfo->usri3_script_path = pszScriptPath;
    }

    if (IsDlgButtonChecked(hwndDlg, IDC_USER_PROFILE_LOCAL) == BST_CHECKED)
    {
        /* Local home directory */
        nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_LOCAL_PATH));
        if (nLength == 0)
        {
            pUserInfo->usri3_home_dir = NULL;
        }
        else
        {
            pszHomeDir = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
            GetDlgItemText(hwndDlg, IDC_USER_PROFILE_LOCAL_PATH, pszHomeDir, nLength + 1);
            pUserInfo->usri3_home_dir = pszHomeDir;
        }
    }
    else
    {
        /* Remote home directory */
        nLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH));
        if (nLength == 0)
        {
            pUserInfo->usri3_home_dir = NULL;
        }
        else
        {
            pszHomeDir = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
            GetDlgItemText(hwndDlg, IDC_USER_PROFILE_REMOTE_PATH, pszHomeDir, nLength + 1);
            pUserInfo->usri3_home_dir = pszHomeDir;
        }

        nIndex = SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), CB_GETCURSEL, 0, 0);
        if (nIndex != CB_ERR)
        {
            nLength = SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), CB_GETLBTEXTLEN, nIndex, 0);
            pszHomeDrive = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(TCHAR));
            SendMessage(GetDlgItem(hwndDlg, IDC_USER_PROFILE_DRIVE), CB_GETLBTEXT, nIndex, (LPARAM)pszHomeDrive);
            pUserInfo->usri3_home_dir_drive = pszHomeDrive;
        }
    }

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

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

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

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

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

    NetApiBufferFree(pUserInfo);

    return (status == NERR_Success);
}
Exemple #15
0
/**
 * Modify AD user account.
 *
 * @param appContext Application context reference.
 * @param info User information.
 * @param userNameC User name.
 * @param password Password; must be NULL if we do not want to change it.
 * @return 0 on success; error code on failure.
 */
DWORD
AdtNetUserSetInfo4(
    IN AppContextTP appContext,
    IN PUSER_INFO_4 info,
    IN PSTR  userNameC,
    IN PSTR passwordC
)
{
   DWORD dwError = ERROR_SUCCESS;
   DWORD parmErr = 0;
   PWSTR hostName = NULL;
   PWSTR userName = NULL;
   PWSTR password = NULL;
   PSTR  userNameN = NULL;

   userNameN = GetNameComp(userNameC);

   dwError = LwMbsToWc16s((PCSTR) (appContext->workConn->serverName), &hostName);
   ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

   dwError = LwMbsToWc16s((PCSTR) userNameN, &userName);
   ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

   if (passwordC) {
       dwError = LwMbsToWc16s((PCSTR) passwordC, &password);
       ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

       LW_SAFE_FREE_MEMORY(info->usri4_password);
       info->usri4_password = password;
       password = NULL;
   }
   else {
       info->usri4_password = NULL;
   }

   PrintStderr(appContext, LogLevelTrace, "%s: Changing properties of user %s ...\n",
               appContext->actionName, userNameN);

   /* Perform the modify operation. */
   if(!appContext->gopts.isReadOnly) {
       dwError = NetUserSetInfo(hostName, userName, 4, (PVOID) &info, &parmErr);
   }

   PrintStderr(appContext, LogLevelTrace, "%s: Done changing properties of user %s\n",
               appContext->actionName, userNameN);

   if (dwError) {
       dwError += ADT_WIN_ERR_BASE;
       ADT_BAIL_ON_ERROR_NP(dwError);
   }

   cleanup:
       LW_SAFE_FREE_MEMORY(hostName);
       LW_SAFE_FREE_MEMORY(userName);
       LW_SAFE_FREE_MEMORY(password);
       LW_SAFE_FREE_MEMORY(userNameN);

       return dwError;

   error:
       goto cleanup;
}
Exemple #16
0
INT
cmdUser(
    INT argc,
    WCHAR **argv)
{
    INT i, j;
    INT result = 0;
    BOOL bAdd = FALSE;
    BOOL bDelete = FALSE;
#if 0
    BOOL bDomain = FALSE;
#endif
    LPWSTR lpUserName = NULL;
    LPWSTR lpPassword = NULL;
    PUSER_INFO_4 pUserInfo = NULL;
    USER_INFO_4 UserInfo;
    LPWSTR p;
    LPWSTR endptr;
    DWORD value;
    BOOL bPasswordAllocated = FALSE;
    NET_API_STATUS Status;

    if (argc == 2)
    {
        Status = EnumerateUsers();
        ConPrintf(StdOut, L"Status: %lu\n", Status);
        return 0;
    }
    else if (argc == 3)
    {
        Status = DisplayUser(argv[2]);
        ConPrintf(StdOut, L"Status: %lu\n", Status);
        return 0;
    }

    i = 2;
    if (argv[i][0] != L'/')
    {
        lpUserName = argv[i];
//        ConPrintf(StdOut, L"User: %s\n", lpUserName);
        i++;
    }

    if (argv[i][0] != L'/')
    {
        lpPassword = argv[i];
//        ConPrintf(StdOut, L"Password: %s\n", lpPassword);
        i++;
    }

    for (j = i; j < argc; j++)
    {
        if (_wcsicmp(argv[j], L"/help") == 0)
        {
            ConResPuts(StdOut, IDS_USER_HELP);
            return 0;
        }
        else if (_wcsicmp(argv[j], L"/add") == 0)
        {
            bAdd = TRUE;
        }
        else if (_wcsicmp(argv[j], L"/delete") == 0)
        {
            bDelete = TRUE;
        }
        else if (_wcsicmp(argv[j], L"/domain") == 0)
        {
            ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/DOMAIN");
#if 0
            bDomain = TRUE;
#endif
        }
    }

    if (bAdd && bDelete)
    {
        result = 1;
        goto done;
    }

    /* Interactive password input */
    if (lpPassword != NULL && wcscmp(lpPassword, L"*") == 0)
    {
        ReadPassword(&lpPassword,
                     &bPasswordAllocated);
    }

    if (!bAdd && !bDelete)
    {
        /* Modify the user */
        Status = NetUserGetInfo(NULL,
                                lpUserName,
                                4,
                                (LPBYTE*)&pUserInfo);
        if (Status != NERR_Success)
        {
            ConPrintf(StdOut, L"Status: %lu\n", Status);
            result = 1;
            goto done;
        }
    }
    else if (bAdd && !bDelete)
    {
        /* Add the user */
        ZeroMemory(&UserInfo, sizeof(USER_INFO_4));

        UserInfo.usri4_name = lpUserName;
        UserInfo.usri4_password = lpPassword;
        UserInfo.usri4_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT;

        pUserInfo = &UserInfo;
    }

    for (j = i; j < argc; j++)
    {
        if (_wcsnicmp(argv[j], L"/active:", 8) == 0)
        {
            p = &argv[i][8];
            if (_wcsicmp(p, L"yes") == 0)
            {
                pUserInfo->usri4_flags &= ~UF_ACCOUNTDISABLE;
            }
            else if (_wcsicmp(p, L"no") == 0)
            {
                pUserInfo->usri4_flags |= UF_ACCOUNTDISABLE;
            }
            else
            {
                ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/ACTIVE");
                result = 1;
                goto done;
            }
        }
        else if (_wcsnicmp(argv[j], L"/comment:", 9) == 0)
        {
            pUserInfo->usri4_comment = &argv[j][9];
        }
        else if (_wcsnicmp(argv[j], L"/countrycode:", 13) == 0)
        {
            p = &argv[i][13];
            value = wcstoul(p, &endptr, 10);
            if (*endptr != 0)
            {
                ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/COUNTRYCODE");
                result = 1;
                goto done;
            }

            /* FIXME: verify the country code */

            pUserInfo->usri4_country_code = value;
        }
        else if (_wcsnicmp(argv[j], L"/expires:", 9) == 0)
        {
            p = &argv[i][9];
            if (_wcsicmp(p, L"never") == 0)
            {
                pUserInfo->usri4_acct_expires = TIMEQ_FOREVER;
            }
            else
            {
                /* FIXME: Parse the date */
                ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/EXPIRES");
            }
        }
        else if (_wcsnicmp(argv[j], L"/fullname:", 10) == 0)
        {
            pUserInfo->usri4_full_name = &argv[j][10];
        }
        else if (_wcsnicmp(argv[j], L"/homedir:", 9) == 0)
        {
            pUserInfo->usri4_home_dir = &argv[j][9];
        }
        else if (_wcsnicmp(argv[j], L"/passwordchg:", 13) == 0)
        {
            p = &argv[i][13];
            if (_wcsicmp(p, L"yes") == 0)
            {
                pUserInfo->usri4_flags &= ~UF_PASSWD_CANT_CHANGE;
            }
            else if (_wcsicmp(p, L"no") == 0)
            {
                pUserInfo->usri4_flags |= UF_PASSWD_CANT_CHANGE;
            }
            else
            {
                ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/PASSWORDCHG");
                result = 1;
                goto done;
            }
        }
        else if (_wcsnicmp(argv[j], L"/passwordreq:", 13) == 0)
        {
            p = &argv[i][13];
            if (_wcsicmp(p, L"yes") == 0)
            {
                pUserInfo->usri4_flags &= ~UF_PASSWD_NOTREQD;
            }
            else if (_wcsicmp(p, L"no") == 0)
            {
                pUserInfo->usri4_flags |= UF_PASSWD_NOTREQD;
            }
            else
            {
                ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/PASSWORDREQ");
                result = 1;
                goto done;
            }
        }
        else if (_wcsnicmp(argv[j], L"/profilepath:", 13) == 0)
        {
            pUserInfo->usri4_profile = &argv[j][13];
        }
        else if (_wcsnicmp(argv[j], L"/scriptpath:", 12) == 0)
        {
            pUserInfo->usri4_script_path = &argv[j][12];
        }
        else if (_wcsnicmp(argv[j], L"/times:", 7) == 0)
        {
            /* FIXME */
            ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/TIMES");
        }
        else if (_wcsnicmp(argv[j], L"/usercomment:", 13) == 0)
        {
            pUserInfo->usri4_usr_comment = &argv[j][13];
        }
        else if (_wcsnicmp(argv[j], L"/workstations:", 14) == 0)
        {
            /* FIXME */
            ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/WORKSTATIONS");
        }
    }

    if (!bAdd && !bDelete)
    {
        /* Modify the user */
        Status = NetUserSetInfo(NULL,
                                lpUserName,
                                4,
                                (LPBYTE)pUserInfo,
                                NULL);
        ConPrintf(StdOut, L"Status: %lu\n", Status);
    }
    else if (bAdd && !bDelete)
    {
        /* Add the user */
        Status = NetUserAdd(NULL,
                            4,
                            (LPBYTE)pUserInfo,
                            NULL);
        ConPrintf(StdOut, L"Status: %lu\n", Status);
    }
    else if (!bAdd && bDelete)
    {
        /* Delete the user */
        Status = NetUserDel(NULL,
                            lpUserName);
        ConPrintf(StdOut, L"Status: %lu\n", Status);
    }

done:
    if (bPasswordAllocated == TRUE && lpPassword != NULL)
        HeapFree(GetProcessHeap(), 0, lpPassword);

    if (!bAdd && !bDelete && pUserInfo != NULL)
        NetApiBufferFree(pUserInfo);

    if (result != 0)
        ConResPuts(StdOut, IDS_USER_SYNTAX);

    return result;
}
Exemple #17
0
bool torture_libnetapi_user(struct torture_context *tctx)
{
	NET_API_STATUS status = 0;
	uint8_t *buffer = NULL;
	uint32_t levels[] = { 0, 1, 2, 3, 4, 10, 11, 20, 23 };
	uint32_t enum_levels[] = { 0, 1, 2, 3, 4, 10, 11, 20, 23 };
	uint32_t getgr_levels[] = { 0, 1 };
	int i;

	struct USER_INFO_0 u0;
	struct USER_INFO_1007 u1007;
	uint32_t parm_err = 0;

	const char *hostname = torture_setting_string(tctx, "host", NULL);
	struct libnetapi_ctx *ctx;

	torture_assert(tctx, torture_libnetapi_init_context(tctx, &ctx),
		       "failed to initialize libnetapi");

	torture_comment(tctx, "NetUser tests\n");

	/* cleanup */

	NetUserDel(hostname, TORTURE_TEST_USER);
	NetUserDel(hostname, TORTURE_TEST_USER2);

	/* add a user */

	status = test_netuseradd(tctx, hostname, TORTURE_TEST_USER);
	if (status) {
		NETAPI_STATUS(tctx, ctx, status, "NetUserAdd");
		goto out;
	}

	/* enum the new user */

	for (i=0; i<ARRAY_SIZE(enum_levels); i++) {

		status = test_netuserenum(tctx, hostname, enum_levels[i], TORTURE_TEST_USER);
		if (status) {
			NETAPI_STATUS(tctx, ctx, status, "NetUserEnum");
			goto out;
		}
	}

	/* basic queries */

	for (i=0; i<ARRAY_SIZE(levels); i++) {

		torture_comment(tctx, "Testing NetUserGetInfo level %d\n", levels[i]);

		status = NetUserGetInfo(hostname, TORTURE_TEST_USER, levels[i], &buffer);
		if (status && status != 124) {
			NETAPI_STATUS(tctx, ctx, status, "NetUserGetInfo");
			goto out;
		}
	}

	/* testing getgroups */

	for (i=0; i<ARRAY_SIZE(getgr_levels); i++) {

		status = test_netusergetgroups(tctx, hostname, getgr_levels[i], TORTURE_TEST_USER, NULL);
		if (status) {
			NETAPI_STATUS(tctx, ctx, status, "NetUserGetGroups");
			goto out;
		}
	}

	/* modify description */

	torture_comment(tctx, "Testing NetUserSetInfo level %d\n", 1007);

	u1007.usri1007_comment = "NetApi modified user";

	status = NetUserSetInfo(hostname, TORTURE_TEST_USER, 1007, (uint8_t *)&u1007, &parm_err);
	if (status) {
		NETAPI_STATUS(tctx, ctx, status, "NetUserSetInfo");
		goto out;
	}

	/* query info */

	for (i=0; i<ARRAY_SIZE(levels); i++) {
		status = NetUserGetInfo(hostname, TORTURE_TEST_USER, levels[i], &buffer);
		if (status && status != 124) {
			NETAPI_STATUS(tctx, ctx, status, "NetUserGetInfo");
			goto out;
		}
	}

	torture_comment(tctx, "Testing NetUserSetInfo level 0\n");

	u0.usri0_name = TORTURE_TEST_USER2;

	status = NetUserSetInfo(hostname, TORTURE_TEST_USER, 0, (uint8_t *)&u0, &parm_err);
	if (status) {
		NETAPI_STATUS(tctx, ctx, status, "NetUserSetInfo");
		goto out;
	}

	/* delete */

	torture_comment(tctx, "Testing NetUserDel\n");

	status = NetUserDel(hostname, TORTURE_TEST_USER2);
	if (status) {
		NETAPI_STATUS(tctx, ctx, status, "NetUserDel");
		goto out;
	}

	/* should not exist anymore */

	status = NetUserGetInfo(hostname, TORTURE_TEST_USER2, 0, &buffer);
	if (status == 0) {
		NETAPI_STATUS(tctx, ctx, status, "NetUserGetInfo");
		status = -1;
		goto out;
	}

	status = test_netusermodals(tctx, ctx, hostname);
	if (status) {
		goto out;
	}

	status = 0;

	torture_comment(tctx, "NetUser tests succeeded\n");
 out:
	/* cleanup */
	NetUserDel(hostname, TORTURE_TEST_USER);
	NetUserDel(hostname, TORTURE_TEST_USER2);

	if (status != 0) {
		torture_comment(tctx, "NetUser testsuite failed with: %s\n",
			libnetapi_get_error_string(ctx, status));
		libnetapi_free(ctx);
		return false;
	}

	libnetapi_free(ctx);
	return true;
}