Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28602 Discussions

IOSTAT=30 after logonuser,impersonateloggedonuser

rwg
Beginner
516 Views

Are there any problems known concerning logonuser/impersonateloggedonuser and FORTRAN file I/O under Vista64?
I wrote following simple Program:

open(10,file="c:\test.dat",STATUS="OLD",READONLY,IOSTAT=IOS)
write(*,*) IOS
close(10)
call SETADMIN("Administrator","XXXX",IOS)
open(10,file="c:\test.dat",STATUS="OLD",READONLY,IOSTAT=IOS)
write(*,*) IOS
close(10)

where SETADMIN calls logonuser and impersonateloggedonuser which means that the current process is now owned by Administrator and not longer by the user who call the program. This works fine (getusername returns Administrator and I can access files which were protected before).
Theopen statements return noerror if I run this programas Administrator but when I switch to a user with restricted rights the 1st open-Statement returns no error but the 2nd open-Statement fails with IOS=30. After removing IOSTAT=IOS I get following error message:

forrtl: FormatMessage failed for sysmem message number 1346forrtl: severe (30):
open failure, unit 10, file c:\test.dat

Edit:
System error code 1346 means "Either a required impersonation level was not provided or the provided impersonation level is invalid." This error code may also display as "ERROR_BAD_IMPERSONATION_LEVEL" or as the value 0x542.

This points to an Error in SETADMIN (but why does the Fortran OPEN-Statement return that value?) but none of the calls in SETADMIN fails. Even GETERROR at the end of SETADMIN returns 0. Here's the source-code of setadmin (sorry Add Files didn't work). I used /iface:cvf.

#pragma warning(disable : 4996)
#include
#include
#include

void fchar2cchar(char *fchar,int lfchar, char *cchar)
{
int i;
for (i=lfchar-1;(i>0)&&(fchar==' ');i--);
i++;
strncpy(cchar,fchar,i);
cchar='\0';
}

void __stdcall SETADMIN(char clogin[], int llogin,char cpasswd[], int lpasswd, int *isw)
{
char domain[MAX_COMPUTERNAME_LENGTH + 1];
char user[256];
char pass[256];
int l;
HANDLE hToken;
BOOL IsMember = FALSE;
PSID SidUser = NULL;

*isw=-3;
if(llogin>0)
{
l=sizeof(domain);
if (GetComputerName(domain, &l)==0)
{
return;
}
strncpy(user,clogin,llogin);
user[llogin]='\0';
strncpy(pass,cpasswd,lpasswd);
pass[lpasswd]='\0';
if(LogonUser(user, domain, pass, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken) == 0)
{
switch(GetLastError())
{
case ERROR_PRIVILEGE_NOT_HELD:
case ERROR_ACCESS_DENIED:
*isw=-2; break;
default: *isw=-1;
}
return;
}
if(ImpersonateLoggedOnUser(hToken)!=0)
{
// No error. In spite of that return GetLastError to check if it is set wrong.
*isw=GetLastError();
}
}
}


Edit:
Sorry, this seems not to be an FORTRAN issue. I tried to acces the file with c low-levelIO (_open,_read) and stream IO (fopen,fread) after ImpersonateLoggedOnUser and this failed too if the user had restricted rights (Errormessage: 'Invalid Argument', whatever this does mean). After this IO GetErrorMessage returns 1346like it did after the FORTRAN open.

0 Kudos
0 Replies
Reply