MprAdminUserSetInfo returns error code 1003 on Windows Server 2008 EE SP2

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
On Windows Server 2003 R2 SE SP2 I am able to set Callback Options for a user on the Dial-in tab of the users properties window via Computer Management/System Tools/Local Users and Groups/Users/user, for example "Always Callback to: 999999".
I am also able to do this programmatically via the mprapi library call MprAdminUserSetInfo(), regardless of whether Routing and Remote Access has been set up or not.<br/>
<br/>
On Windows Server 2008 EE SP2 I am able to set Callback Options for a user on the Dial-in tab of the users properties window via Server Manager/Configuration/Local Users and Groups/Users/user, for example "Always Callback to: 999999". However, I
am *unable* to do this programmatically via the mprapi library call MprAdminUserSetInfo(), regardless of whether Routing and Remote Access has been set up or not.<br/>
<br/>
On 2008 the MprAdminUserSetInfo call returns the error code 1003, or "Cannot complete this function".<br/>
<br/>
Given that the same code works on WS 2003, and that the native Server Manager UI is able to set the callback number, I cannot understand why mprapi is returning a 1003 error code.<br/>
<br/>
Any help would be much appreicated!<br/>
<br/>
<br/>
To run the code sample, just type: admapit.exe \serverName userName<br/>
<br/>
Both my 2003 and 2008 servers were members of workgroups, not domains.<br/>
<br/>
<br/>
On Windows 2003 I get:<br/>
<br/>
admapit.exe \<serverName> Administrator<br/>
Please specify the Clients phone number or IP address<br/>
999999<br/>
<br/>
MprAdminUserGetInfo(\garbe04-w2k3-im-sdk, Administrator): 0<br/>
--PrintPriv--<br/>
ppRasUser0->bfPrivilege = 0x2<br/>
RASPRIV_AdminSetCallback = 0x2<br/>
Always callback to = 555555<br/>
-------------<br/>
<br/>
MprAdminUserSetInfo(\garbe04-w2k3-im-sdk, Administrator): 0<br/>
--PrintPriv--<br/>
ppRasUser0->bfPrivilege = 0xa<br/>
RASPRIV_AdminSetCallback = 0x2<br/>
Always callback to = 999999<br/>
RASPRIV_DialinPrivilege = 0x8<br/>
-------------<br/>
<br/>
Showing that I successfully changed the dial-in callback number from 555555 to 999999 (add added DialinPrivilege).<br/>
<br/>
<br/>
However, on Windows 2008 I get:<br/>
<br/>
admapit.exe \<serverName> Administrator<br/>
Please specify the Clients phone number or IP address<br/>
999999<br/>
<br/>
MprAdminUserGetInfo(\<serverName>, Administrator): 0<br/>
--PrintPriv--<br/>
ppRasUser0->bfPrivilege = 0x2<br/>
RASPRIV_AdminSetCallback = 0x2<br/>
Always callback to = 555555<br/>
-------------<br/>
<br/>
MprAdminUserSetInfo(\garbe04-w2k8-im, Administrator): 1003 <--------!!!<br/>
ERROR MprAdminUserSetInfo: Cannot complete this function.<br/>
<br/>
Parameters in:<br/>
lpszServer=\garbe04-w2k8-im<br/>
lpszUser=Administrator<br/>
dwLevel=0,<br/>
lpbBuffer=<br/>
--PrintPriv--<br/>
ppRasUser0->bfPrivilege = 0xa<br/>
RASPRIV_AdminSetCallback = 0x2<br/>
Always callback to = ccc <------ !!!<br/>
RASPRIV_DialinPrivilege = 0x8<br/>
-------------<br/>
<br/>
Note that the callback number buffer has been trashed by the failed MprAdminUserSetInfo call.<br/>
<br/>
<br/>
I have built the following code (based on the SDK SamplesNetDsRRasAdminapi) using Visual Studio 9 using the v6.0a SDK for WS 2003 and using the v6.1 SDK for WS 2008.<br/>
<br/>
<br/>
makefile<br/>
<br/>
<pre>!include <win32.mak>

all: admapit.exe

.c.obj:
$(cc) $(cdebug) $(cflags) $(cvars) -DUNICODE $*.c

admapit.exe: admapit.obj
$(link) $(linkdebug) $(lflags)
$** -out:admapit.exe
$(conlibs) shlwapi.lib mprapi.Lib user32.lib[/code]
<br/>
<br/>
admapit.c<br/>
<br/>
<pre>#include <windows.h>

#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <lm.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <conio.h>
#include <mprapi.h>
#include <memory.h>

#include <tchar.h>
#include "Shlwapi.h" // Platform SDK wasnt including this .h file so its part of this project
#include "strsafe.h"

//Function Definitions
VOID UserPrivilege(VOID);
VOID PrintPriv(WCHAR *DomainName, WCHAR *UserName);


// Global Variables
CHAR buf[120];
WCHAR CallbackNumber[255];
DWORD dwResult = 0;
DWORD dwBytesWritten = 0;
CHAR szBuf[120];
PRAS_USER_0 ppRasUser0;
RAS_USER_0 RasUser0;
WCHAR lpszServerName[50];
WCHAR RasSrv[64];
WCHAR UserName[64];


//
// Function to print user privileges to logfile
//
VOID PrintPriv(WCHAR *DomainName, WCHAR *UserName)
{
DWORD dwBytesWritten = 0;

/*********** from mprapi.h ****************************************************/
//
// Note: Bit 0 MUST represent NoCallback due to a quirk of the "userparms"
// storage method. When a new LAN Manager user is created, bit 0 of the
// userparms field is set to 1 and all other bits are 0. These bits are
// arranged so this "no Dial-In info" state maps to the "default Dial-In
// privilege" state.
//
// #define RASPRIV_NoCallback 0x01
// #define RASPRIV_AdminSetCallback 0x02
// #define RASPRIV_CallerSetCallback 0x04
// #define RASPRIV_DialinPrivilege 0x08
//
// #define RASPRIV_CallbackType (RASPRIV_AdminSetCallback
// | RASPRIV_CallerSetCallback
// | RASPRIV_NoCallback)
/*****************************************************************************/

wprintf(L"--PrintPriv--n");
//wprintf(L"DomainName = %wsnUserName = %wsn",DomainName, UserName);
wprintf(L"ppRasUser0->bfPrivilege = 0x%xn",ppRasUser0->bfPrivilege);
if ((ppRasUser0->bfPrivilege) & (RASPRIV_NoCallback))
{
wprintf(L"ttRASPRIV_NoCallback = 0x%xn", (ppRasUser0->bfPrivilege & (RASPRIV_NoCallback)));
}
if ((ppRasUser0->bfPrivilege) & (RASPRIV_AdminSetCallback))
{
wprintf(L"ttRASPRIV_AdminSetCallback = 0x%xn", (ppRasUser0->bfPrivilege & (RASPRIV_AdminSetCallback)));
wprintf(L"ttAlways callback to = %wsn", ppRasUser0->wszPhoneNumber);
}
if ((ppRasUser0->bfPrivilege) & (RASPRIV_CallerSetCallback))
{
wprintf(L"ttRASPRIV_CallerSetCallback = 0x%xn", (ppRasUser0->bfPrivilege & (RASPRIV_CallerSetCallback)));
}
if ((ppRasUser0->bfPrivilege) & (RASPRIV_DialinPrivilege))
{
wprintf(L"ttRASPRIV_DialinPrivilege = 0x%xn", (ppRasUser0->bfPrivilege & (RASPRIV_DialinPrivilege)));
}
wprintf(L"-------------n");
}


//
// Function to get and change User Dialin Privileges.
// It goes through all the Dialin Privileges for a user.
//
VOID UserPrivilege()
{
DWORD dwResult;
DWORD dwBytesWritten = 0;
WCHAR Buf[512];
WCHAR *lpszString;
static BYTE Dialin = 0x2;
lpszString = &Buf[0];
ppRasUser0 = &RasUser0;

dwResult = MprAdminUserGetInfo(RasSrv, UserName,(DWORD) 0, (LPBYTE) ppRasUser0);
if (dwResult != NO_ERROR)
{
wprintf(L"ERROR MprAdminUserGetInfo %dn",dwResult);
wprintf(L"Parameters in:ntlpszServer=%wsntlpszUser=%wsntdwLevel=0,ntlpbBuffer)n", RasSrv, UserName);
dwResult = MprAdminGetErrorString( dwResult, &lpszString);
if (dwResult == NO_ERROR)
{
wprintf(L"ERROR MprAdminUserGetInfo: %wsn",lpszString);
}
else
{
wprintf(L"ERROR MprAdminUserGetInfo: %dn",dwResult);
}
}
else //MprAdminUserGetInfo returned success
{
wprintf(L"nMprAdminUserGetInfo(%ws, %ws): %dn", RasSrv, UserName, dwResult);
PrintPriv(RasSrv, UserName);
ppRasUser0->bfPrivilege = (RASPRIV_DialinPrivilege | Dialin);
wcscpy_s(ppRasUser0->wszPhoneNumber, sizeof(ppRasUser0->wszPhoneNumber)/sizeof(ppRasUser0->wszPhoneNumber[0]), CallbackNumber);
dwResult = MprAdminUserSetInfo(RasSrv, UserName, 0, (LPBYTE)ppRasUser0);
if (dwResult != NO_ERROR)
{
wprintf(L"nMprAdminUserSetInfo(%ws, %ws): %dn", RasSrv, UserName, dwResult);

dwResult = MprAdminGetErrorString( dwResult, &lpszString);
if (dwResult == ERROR_SUCCESS)
{
wprintf(L"ERROR MprAdminUserSetInfo: %wsn",lpszString);
}
else
{
wprintf(L"ERROR MptAdminGetErrorString: %dn", dwResult);
}

wprintf(L"Parameters in:ntlpszServer=%wsntlpszUser=%wsntdwLevel=0,ntlpbBuffer=n", RasSrv, UserName);
// dump this out to see what privileges were passed in UserSetInfo call
PrintPriv(RasSrv, UserName);
}
else
{
wprintf(L"nMprAdminUserSetInfo(%ws, %ws): %dn", RasSrv, UserName, dwResult);
MprAdminUserGetInfo(RasSrv, UserName,(DWORD) 0, (LPBYTE) ppRasUser0);
PrintPriv(RasSrv, UserName);
}
}
} //end UserPrivilege()


/*************************************************************************/
/***************** Start Main ********************************************/
/*************************************************************************/

void _cdecl main(int argc, char **argv)
{
size_t rc;
if (argc > 1)
{
mbstowcs_s(&rc, RasSrv, 64, argv[1], 32);
mbstowcs_s(&rc, UserName, 64, argv[2], 32);
}
printf("Please specify the Clients phone number or IP addressn");
wscanf_s(L"%254s", CallbackNumber, 255);

UserPrivilege();
} // Main End[/code]

View the full article
 
Back
Top