RE: How to reobtain a file handle from file object pointe r in driver?

So, I cann’t create a object in user process context and obtain a handle in
a system thread context from this object by
using: ObOpenObjectByPointer?

I did so but failed when obtain handle in system context. Is that the
reason?

Thank you for your help.

Laura.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Ilya Levin
Sent: Tuesday, June 25, 2002 5:50 PM
To: File Systems Developers
Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe r
in driver?

Laura,

what you can do is always open a handle and its object in a system context.

Next time you have to use it, if you are called not in system context,
you can call ObOpenObjectByPointer, that will give you context safe handle.
Note that you have to close this handle once you opened it.

When you are done with the handle, you can close it in the system context.

Note, that you do not have to open handle in the system context, but you
have to open
it in the known context so you can close it in the same context, and also
determine if
you have to call ObOpenObjectByPointer, when you need to use this handle
again.

-Ilya.

-----Original Message-----
From: gaoren [mailto:xxxxx@yahoo.ca]
Sent: Tuesday, June 25, 2002 11:10 AM
To: File Systems Developers
Subject: [ntfsd] How to reobtain a file handle from file object pointer in
driver?

Hi all,
Did any one know how to reobtain a handle from file object in different
context other than the one that the file was created and Obreferenced.

Thanks for your help.

Laura.


Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com


You are currently subscribed to ntfsd as: xxxxx@softricity.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
To unsubscribe send a blank email to %%email.unsub%%


Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com

You can. If you provide more information, like at least the returned status
code from ObOpenObjectByPointer, maybe will be able to help you track your
problem. And never forget that you can use a plain file object, and not
necessarely a handle, to perform IO.

Dan

----- Original Message -----
From: “gaoren”
To: “File Systems Developers”
Sent: Wednesday, June 26, 2002 6:09 PM
Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe r
in driver?

> So, I cann’t create a object in user process context and obtain a handle
in
> a system thread context from this object by
> using: ObOpenObjectByPointer?
>
> I did so but failed when obtain handle in system context. Is that the
> reason?
>
> Thank you for your help.
>
> Laura.
>
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Ilya Levin
> Sent: Tuesday, June 25, 2002 5:50 PM
> To: File Systems Developers
> Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe
r
> in driver?
>
>
> Laura,
>
> what you can do is always open a handle and its object in a system
context.
>
> Next time you have to use it, if you are called not in system context,
> you can call ObOpenObjectByPointer, that will give you context safe
handle.
> Note that you have to close this handle once you opened it.
>
> When you are done with the handle, you can close it in the system context.
>
> Note, that you do not have to open handle in the system context, but you
> have to open
> it in the known context so you can close it in the same context, and also
> determine if
> you have to call ObOpenObjectByPointer, when you need to use this handle
> again.
>
> -Ilya.
>
>
> -----Original Message-----
> From: gaoren [mailto:xxxxx@yahoo.ca]
> Sent: Tuesday, June 25, 2002 11:10 AM
> To: File Systems Developers
> Subject: [ntfsd] How to reobtain a file handle from file object pointer in
> driver?
>
>
> Hi all,
> Did any one know how to reobtain a handle from file object in different
> context other than the one that the file was created and Obreferenced.
>
> Thanks for your help.
>
> Laura.
>
>
>
>
>
> Do You Yahoo!?
>
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@softricity.com
> To unsubscribe send a blank email to %%email.unsub%%
>
> —
> You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
> To unsubscribe send a blank email to %%email.unsub%%
>
>
>
>

>
> Do You Yahoo!?
>
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
> To unsubscribe send a blank email to %%email.unsub%%
>

Hi Dan,
Thank you for your answer. But I’m still stuck here.
This is the my code.
I create a file object by using ZwCreateFile and ObReferenceObjectByHandle()
in IRP_MJ_CREATE routine and save the object in and hash table.

Then in IRP_MJ_SET_INFORMATION routine, I need use this file object to get a
file handle:

The file in a network file, so I use impersonate function every time when i
need to manipulate this file.

I cannot get the status code, the return value" status" is big minus
integer.
And the nwFile is NULL.

case IRP_MJ_SET_INFORMATION:
if(IsTarget(fullPathName))
{
DbgPrint((“%s, IRP_MJ_SET_INFORMATION!\n”,fullPathName));
KeEnterCriticalRegion();
ExAcquireResourceSharedLite( &TargetHashResource, TRUE );
targetEntry=LookingForTarget(FileObject);
if(targetEntry!=NULL)
{
SeImpersonateClientEx(hookExt->security_client_context, NULL);
FileAttributes=(UCHAR)(currentIrpStack->Parameters.Create.FileAttributes &
~FILE_ATTRIBUTE_NORMAL);
status=ObOpenObjectByPointer(
targetEntry->TargetFileObject,
0,
NULL,
FILE_ALL_ACCESS,
NULL,
KernelMode,
&nwFile);
ExReleaseResourceLite( &TargetHashResource );
KeLeaveCriticalRegion();
if(NT_SUCCESS(status))
{
status=ZwSetInformationFile(
nwFile,
&ioStatus,
Irp->AssociatedIrp.SystemBuffer,
currentIrpStack->Parameters.SetFile.Length,
currentIrpStack->Parameters.SetFile.FileInformationClass
);
if(!NT_SUCCESS(status)){
DbgPrint((“Set Information to remote file failed\n”));
}
else
{
DbgPrint((“Set Information to Remote File OK!!\n”));
}
ZwClose(nwFile);
}
PsRevertToSelf();
}
else
{
//something wrong
ExReleaseResourceLite( &TargetHashResource );
KeLeaveCriticalRegion();
}
}

Laura.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Dan Partelly
Sent: Wednesday, June 26, 2002 11:13 AM
To: File Systems Developers
Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe r
in driver?

You can. If you provide more information, like at least the returned status
code from ObOpenObjectByPointer, maybe will be able to help you track your
problem. And never forget that you can use a plain file object, and not
necessarely a handle, to perform IO.

Dan

----- Original Message -----
From: “gaoren”
To: “File Systems Developers”
Sent: Wednesday, June 26, 2002 6:09 PM
Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe r
in driver?

> So, I cann’t create a object in user process context and obtain a handle
in
> a system thread context from this object by
> using: ObOpenObjectByPointer?
>
> I did so but failed when obtain handle in system context. Is that the
> reason?
>
> Thank you for your help.
>
> Laura.
>
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Ilya Levin
> Sent: Tuesday, June 25, 2002 5:50 PM
> To: File Systems Developers
> Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe
r
> in driver?
>
>
> Laura,
>
> what you can do is always open a handle and its object in a system
context.
>
> Next time you have to use it, if you are called not in system context,
> you can call ObOpenObjectByPointer, that will give you context safe
handle.
> Note that you have to close this handle once you opened it.
>
> When you are done with the handle, you can close it in the system context.
>
> Note, that you do not have to open handle in the system context, but you
> have to open
> it in the known context so you can close it in the same context, and also
> determine if
> you have to call ObOpenObjectByPointer, when you need to use this handle
> again.
>
> -Ilya.
>
>
> -----Original Message-----
> From: gaoren [mailto:xxxxx@yahoo.ca]
> Sent: Tuesday, June 25, 2002 11:10 AM
> To: File Systems Developers
> Subject: [ntfsd] How to reobtain a file handle from file object pointer in
> driver?
>
>
> Hi all,
> Did any one know how to reobtain a handle from file object in different
> context other than the one that the file was created and Obreferenced.
>
> Thanks for your help.
>
> Laura.
>
>
>
>
>
> Do You Yahoo!?
>
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@softricity.com
> To unsubscribe send a blank email to %%email.unsub%%
>
> —
> You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
> To unsubscribe send a blank email to %%email.unsub%%
>
>
>
>

>
> Do You Yahoo!?
>
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
> To unsubscribe send a blank email to %%email.unsub%%
>


You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
To unsubscribe send a blank email to %%email.unsub%%

_________________________________________________________

Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com

Cast the status to an unsigned int. in the debugger window.

Pete

Peter Scott
xxxxx@KernelDrivers.com
http://www.KernelDrivers.com

>-----Original Message-----
>From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
>xxxxx@lists.osr.com] On Behalf Of gaoren
>Sent: Wednesday, June 26, 2002 12:40 PM
>To: File Systems Developers
>Subject: [ntfsd] RE: How to reobtain a file handle from file object
pointe
>r in driver?
>
>Hi Dan,
>Thank you for your answer. But I’m still stuck here.
>This is the my code.
>I create a file object by using ZwCreateFile and
>ObReferenceObjectByHandle()
>in IRP_MJ_CREATE routine and save the object in and hash table.
>
>Then in IRP_MJ_SET_INFORMATION routine, I need use this file object to
get
>a
>file handle:
>
>The file in a network file, so I use impersonate function every time
when
>i
>need to manipulate this file.
>
>I cannot get the status code, the return value" status" is big minus
>integer.
>And the nwFile is NULL.
>
>case IRP_MJ_SET_INFORMATION:
>if(IsTarget(fullPathName))
>{
>DbgPrint((“%s, IRP_MJ_SET_INFORMATION!\n”,fullPathName));
>KeEnterCriticalRegion();
>ExAcquireResourceSharedLite( &TargetHashResource, TRUE );
>targetEntry=LookingForTarget(FileObject);
>if(targetEntry!=NULL)
>{
> SeImpersonateClientEx(hookExt->security_client_context, NULL);
> FileAttributes=(UCHAR)(currentIrpStack-
>>Parameters.Create.FileAttributes &
>~FILE_ATTRIBUTE_NORMAL);
> status=ObOpenObjectByPointer(
> targetEntry->TargetFileObject,
> 0,
> NULL,
> FILE_ALL_ACCESS,
> NULL,
> KernelMode,
> &nwFile);
> ExReleaseResourceLite( &TargetHashResource );
> KeLeaveCriticalRegion();
> if(NT_SUCCESS(status))
> {
> status=ZwSetInformationFile(
> nwFile,
> &ioStatus,
> Irp->AssociatedIrp.SystemBuffer,
> currentIrpStack->Parameters.SetFile.Leng
th,
> currentIrpStack-
>>Parameters.SetFile.FileInformationClass
> );
> if(!NT_SUCCESS(status)){
> DbgPrint((“Set Information to remote file
failed\n”));
> }
> else
> {
> DbgPrint((“Set Information to Remote File
OK!!\n”));
> }
> ZwClose(nwFile);
> }
> PsRevertToSelf();
>}
>else
>{
>//something wrong
> ExReleaseResourceLite( &TargetHashResource );
> KeLeaveCriticalRegion();
>}
>}
>
>
>Laura.
>
>-----Original Message-----
>From: xxxxx@lists.osr.com
>[mailto:xxxxx@lists.osr.com]On Behalf Of Dan Partelly
>Sent: Wednesday, June 26, 2002 11:13 AM
>To: File Systems Developers
>Subject: [ntfsd] RE: How to reobtain a file handle from file object
pointe
>r
>in driver?
>
>
>You can. If you provide more information, like at least the returned
>status
>code from ObOpenObjectByPointer, maybe will be able to help you track
your
>problem. And never forget that you can use a plain file object, and
not
>necessarely a handle, to perform IO.
>
>Dan
>
>----- Original Message -----
>From: “gaoren”
>>To: “File Systems Developers”
>>Sent: Wednesday, June 26, 2002 6:09 PM
>>Subject: [ntfsd] RE: How to reobtain a file handle from file object
pointe
>>r
>>in driver?
>>
>>
>>> So, I cann’t create a object in user process context and obtain a
handle
>>in
>>> a system thread context from this object by
>>> using: ObOpenObjectByPointer?
>>>
>>> I did so but failed when obtain handle in system context. Is that
the
>>> reason?
>>>
>>> Thank you for your help.
>>>
>>> Laura.
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: xxxxx@lists.osr.com
>>> [mailto:xxxxx@lists.osr.com]On Behalf Of Ilya Levin
>>> Sent: Tuesday, June 25, 2002 5:50 PM
>>> To: File Systems Developers
>>> Subject: [ntfsd] RE: How to reobtain a file handle from file object
>>pointe
>>r
>>> in driver?
>>>
>>>
>>> Laura,
>>>
>>> what you can do is always open a handle and its object in a system
>>context.
>>>
>>> Next time you have to use it, if you are called not in system
context,
>>> you can call ObOpenObjectByPointer, that will give you context safe
>>handle.
>>> Note that you have to close this handle once you opened it.
>>>
>>> When you are done with the handle, you can close it in the system
>>context.
>>>
>>> Note, that you do not have to open handle in the system context, but
you
>>> have to open
>>> it in the known context so you can close it in the same context, and
>>also
>>> determine if
>>> you have to call ObOpenObjectByPointer, when you need to use this
handle
>>> again.
>>>
>>> -Ilya.
>>>
>>>
>>> -----Original Message-----
>>> From: gaoren [mailto:xxxxx@yahoo.ca]
>>> Sent: Tuesday, June 25, 2002 11:10 AM
>>> To: File Systems Developers
>>> Subject: [ntfsd] How to reobtain a file handle from file object
pointer
>>in
>>> driver?
>>>
>>>
>>> Hi all,
>>> Did any one know how to reobtain a handle from file object in
different
>>> context other than the one that the file was created and
Obreferenced.
>>>
>>> Thanks for your help.
>>>
>>> Laura.
>>>
>>>
>>>
>>>
>>>
>>> Do You Yahoo!?
>>>
>>> Get your free @yahoo.com address at http://mail.yahoo.com
>>>
>>>
>>>
>>>
>>> —
>>> You are currently subscribed to ntfsd as: xxxxx@softricity.com
>>> To unsubscribe send a blank email to %%email.unsub%%
>>>
>>> —
>>> You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
>>> To unsubscribe send a blank email to %%email.unsub%%
>>>
>>>
>>>
>>>

>>>
>>> Do You Yahoo!?
>>>
>>> Get your free @yahoo.com address at http://mail.yahoo.com
>>>
>>>
>>>
>>>
>>> —
>>> You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
>>> To unsubscribe send a blank email to %%email.unsub%%
>>>
>>
>>
>>—
>>You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
>>To unsubscribe send a blank email to %%email.unsub%%
>>
>>
>>
>> _________________________________________________________
>>
>>Do You Yahoo!?
>>
>>Get your free @yahoo.com address at http://mail.yahoo.com
>>
>>
>>
>>
>>—
>>You are currently subscribed to ntfsd as: xxxxx@KernelDrivers.com
>>To unsubscribe send a blank email to %%email.unsub%%

>> I cannot get the status code, the return value" status" is big minus

> integer.

That big negative number is exactly the status code. Its a very valuable
indication of why the call fails, so dont neglect it.

Also, it seems that your code does not really need ObOpenObjectByPointer(),
since you can perform a set size very simple on the file object, rolling
your own IRP.

Dan

----- Original Message -----
From: “gaoren”
To: “File Systems Developers”
Sent: Wednesday, June 26, 2002 9:40 PM
Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe r
in driver?

> Hi Dan,
> Thank you for your answer. But I’m still stuck here.
> This is the my code.
> I create a file object by using ZwCreateFile and
ObReferenceObjectByHandle()
> in IRP_MJ_CREATE routine and save the object in and hash table.
>
> Then in IRP_MJ_SET_INFORMATION routine, I need use this file object to get
a
> file handle:
>
> The file in a network file, so I use impersonate function every time when
i
> need to manipulate this file.
>
> I cannot get the status code, the return value" status" is big minus
> integer.
> And the nwFile is NULL.
>
> case IRP_MJ_SET_INFORMATION:
> if(IsTarget(fullPathName))
> {
> DbgPrint((“%s, IRP_MJ_SET_INFORMATION!\n”,fullPathName));
> KeEnterCriticalRegion();
> ExAcquireResourceSharedLite( &TargetHashResource, TRUE );
> targetEntry=LookingForTarget(FileObject);
> if(targetEntry!=NULL)
> {
> SeImpersonateClientEx(hookExt->security_client_context, NULL);
> FileAttributes=(UCHAR)(currentIrpStack->Parameters.Create.FileAttributes &
> ~FILE_ATTRIBUTE_NORMAL);
> status=ObOpenObjectByPointer(
> targetEntry->TargetFileObject,
> 0,
> NULL,
> FILE_ALL_ACCESS,
> NULL,
> KernelMode,
> &nwFile);
> ExReleaseResourceLite( &TargetHashResource );
> KeLeaveCriticalRegion();
> if(NT_SUCCESS(status))
> {
> status=ZwSetInformationFile(
> nwFile,
> &ioStatus,
> Irp->AssociatedIrp.SystemBuffer,
> currentIrpStack->Parameters.SetFile.Length,
> currentIrpStack->Parameters.SetFile.FileInformationClass
> );
> if(!NT_SUCCESS(status)){
> DbgPrint((“Set Information to remote file failed\n”));
> }
> else
> {
> DbgPrint((“Set Information to Remote File OK!!\n”));
> }
> ZwClose(nwFile);
> }
> PsRevertToSelf();
> }
> else
> {
> //something wrong
> ExReleaseResourceLite( &TargetHashResource );
> KeLeaveCriticalRegion();
> }
> }
>
>
> Laura.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Dan Partelly
> Sent: Wednesday, June 26, 2002 11:13 AM
> To: File Systems Developers
> Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe
r
> in driver?
>
>
> You can. If you provide more information, like at least the returned
status
> code from ObOpenObjectByPointer, maybe will be able to help you track your
> problem. And never forget that you can use a plain file object, and not
> necessarely a handle, to perform IO.
>
> Dan
>
> ----- Original Message -----
> From: “gaoren”
> To: “File Systems Developers”
> Sent: Wednesday, June 26, 2002 6:09 PM
> Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe
r
> in driver?
>
>
> > So, I cann’t create a object in user process context and obtain a handle
> in
> > a system thread context from this object by
> > using: ObOpenObjectByPointer?
> >
> > I did so but failed when obtain handle in system context. Is that the
> > reason?
> >
> > Thank you for your help.
> >
> > Laura.
> >
> >
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com]On Behalf Of Ilya Levin
> > Sent: Tuesday, June 25, 2002 5:50 PM
> > To: File Systems Developers
> > Subject: [ntfsd] RE: How to reobtain a file handle from file object
pointe
> r
> > in driver?
> >
> >
> > Laura,
> >
> > what you can do is always open a handle and its object in a system
> context.
> >
> > Next time you have to use it, if you are called not in system context,
> > you can call ObOpenObjectByPointer, that will give you context safe
> handle.
> > Note that you have to close this handle once you opened it.
> >
> > When you are done with the handle, you can close it in the system
context.
> >
> > Note, that you do not have to open handle in the system context, but you
> > have to open
> > it in the known context so you can close it in the same context, and
also
> > determine if
> > you have to call ObOpenObjectByPointer, when you need to use this handle
> > again.
> >
> > -Ilya.
> >
> >
> > -----Original Message-----
> > From: gaoren [mailto:xxxxx@yahoo.ca]
> > Sent: Tuesday, June 25, 2002 11:10 AM
> > To: File Systems Developers
> > Subject: [ntfsd] How to reobtain a file handle from file object pointer
in
> > driver?
> >
> >
> > Hi all,
> > Did any one know how to reobtain a handle from file object in different
> > context other than the one that the file was created and Obreferenced.
> >
> > Thanks for your help.
> >
> > Laura.
> >
> >
> >
> >
> >
> > Do You Yahoo!?
> >
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@softricity.com
> > To unsubscribe send a blank email to %%email.unsub%%
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
> > To unsubscribe send a blank email to %%email.unsub%%
> >
> >
> >
> >

> >
> > Do You Yahoo!?
> >
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
> > To unsubscribe send a blank email to %%email.unsub%%
> >
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
> To unsubscribe send a blank email to %%email.unsub%%
>
>
>
> _________________________________________________________
>
> Do You Yahoo!?
>
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
> To unsubscribe send a blank email to %%email.unsub%%
>

Hi Dan,

I use ObOpenObjectByPointer because my target file object is on network.
I don’t know send irp to which driver device who response for network file.
( Mup is not response IRP_MJ_WRITE or others after it parsed the file name,
and I tried to send to LanManRedirector, it does not work.)

The status code is: 0xc0000001: STATUS_UNSUCCESSFUL.

Any idea about this?

Thanks all.

Laura
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Dan Partelly
Sent: Thursday, June 27, 2002 7:58 AM
To: File Systems Developers
Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe r
in driver?

> I cannot get the status code, the return value" status" is big minus
> integer.

That big negative number is exactly the status code. Its a very valuable
indication of why the call fails, so dont neglect it.

Also, it seems that your code does not really need ObOpenObjectByPointer(),
since you can perform a set size very simple on the file object, rolling
your own IRP.

Dan

----- Original Message -----
From: “gaoren”
To: “File Systems Developers”
Sent: Wednesday, June 26, 2002 9:40 PM
Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe r
in driver?

> Hi Dan,
> Thank you for your answer. But I’m still stuck here.
> This is the my code.
> I create a file object by using ZwCreateFile and
ObReferenceObjectByHandle()
> in IRP_MJ_CREATE routine and save the object in and hash table.
>
> Then in IRP_MJ_SET_INFORMATION routine, I need use this file object to get
a
> file handle:
>
> The file in a network file, so I use impersonate function every time when
i
> need to manipulate this file.
>
> I cannot get the status code, the return value" status" is big minus
> integer.
> And the nwFile is NULL.
>
> case IRP_MJ_SET_INFORMATION:
> if(IsTarget(fullPathName))
> {
> DbgPrint((“%s, IRP_MJ_SET_INFORMATION!\n”,fullPathName));
> KeEnterCriticalRegion();
> ExAcquireResourceSharedLite( &TargetHashResource, TRUE );
> targetEntry=LookingForTarget(FileObject);
> if(targetEntry!=NULL)
> {
> SeImpersonateClientEx(hookExt->security_client_context, NULL);
> FileAttributes=(UCHAR)(currentIrpStack->Parameters.Create.FileAttributes &
> ~FILE_ATTRIBUTE_NORMAL);
> status=ObOpenObjectByPointer(
> targetEntry->TargetFileObject,
> 0,
> NULL,
> FILE_ALL_ACCESS,
> NULL,
> KernelMode,
> &nwFile);
> ExReleaseResourceLite( &TargetHashResource );
> KeLeaveCriticalRegion();
> if(NT_SUCCESS(status))
> {
> status=ZwSetInformationFile(
> nwFile,
> &ioStatus,
> Irp->AssociatedIrp.SystemBuffer,
> currentIrpStack->Parameters.SetFile.Length,
> currentIrpStack->Parameters.SetFile.FileInformationClass
> );
> if(!NT_SUCCESS(status)){
> DbgPrint((“Set Information to remote file failed\n”));
> }
> else
> {
> DbgPrint((“Set Information to Remote File OK!!\n”));
> }
> ZwClose(nwFile);
> }
> PsRevertToSelf();
> }
> else
> {
> //something wrong
> ExReleaseResourceLite( &TargetHashResource );
> KeLeaveCriticalRegion();
> }
> }
>
>
> Laura.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Dan Partelly
> Sent: Wednesday, June 26, 2002 11:13 AM
> To: File Systems Developers
> Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe
r
> in driver?
>
>
> You can. If you provide more information, like at least the returned
status
> code from ObOpenObjectByPointer, maybe will be able to help you track your
> problem. And never forget that you can use a plain file object, and not
> necessarely a handle, to perform IO.
>
> Dan
>
> ----- Original Message -----
> From: “gaoren”
> To: “File Systems Developers”
> Sent: Wednesday, June 26, 2002 6:09 PM
> Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe
r
> in driver?
>
>
> > So, I cann’t create a object in user process context and obtain a handle
> in
> > a system thread context from this object by
> > using: ObOpenObjectByPointer?
> >
> > I did so but failed when obtain handle in system context. Is that the
> > reason?
> >
> > Thank you for your help.
> >
> > Laura.
> >
> >
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com]On Behalf Of Ilya Levin
> > Sent: Tuesday, June 25, 2002 5:50 PM
> > To: File Systems Developers
> > Subject: [ntfsd] RE: How to reobtain a file handle from file object
pointe
> r
> > in driver?
> >
> >
> > Laura,
> >
> > what you can do is always open a handle and its object in a system
> context.
> >
> > Next time you have to use it, if you are called not in system context,
> > you can call ObOpenObjectByPointer, that will give you context safe
> handle.
> > Note that you have to close this handle once you opened it.
> >
> > When you are done with the handle, you can close it in the system
context.
> >
> > Note, that you do not have to open handle in the system context, but you
> > have to open
> > it in the known context so you can close it in the same context, and
also
> > determine if
> > you have to call ObOpenObjectByPointer, when you need to use this handle
> > again.
> >
> > -Ilya.
> >
> >
> > -----Original Message-----
> > From: gaoren [mailto:xxxxx@yahoo.ca]
> > Sent: Tuesday, June 25, 2002 11:10 AM
> > To: File Systems Developers
> > Subject: [ntfsd] How to reobtain a file handle from file object pointer
in
> > driver?
> >
> >
> > Hi all,
> > Did any one know how to reobtain a handle from file object in different
> > context other than the one that the file was created and Obreferenced.
> >
> > Thanks for your help.
> >
> > Laura.
> >
> >
> >
> >
> >
> > Do You Yahoo!?
> >
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@softricity.com
> > To unsubscribe send a blank email to %%email.unsub%%
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
> > To unsubscribe send a blank email to %%email.unsub%%
> >
> >
> >
> >

> >
> > Do You Yahoo!?
> >
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
> > To unsubscribe send a blank email to %%email.unsub%%
> >
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
> To unsubscribe send a blank email to %%email.unsub%%
>
>
>
>
>
> Do You Yahoo!?
>
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
> To unsubscribe send a blank email to %%email.unsub%%
>


You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
To unsubscribe send a blank email to %%email.unsub%%



Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com

I have a vague memory of a long painful experience debugging something like this. Some of the code executed during an ObOpenObjectByPointer sends an IRP_MJ_QUERY_SECURITY to the FSD in order to determine whether or not the caller has the appropriate permissions for the requested access. IIRC, in this case the kernel uses an arbitrarily sized buffer to query the security descriptor. If the buffer is too small, the FSD returns STATUS_BUFFER_TOO_SMALL or one of its relatives. A higher level function then translates this to the not so helpful error code STATUS_UNSUCCESSFUL returned by ObOpenObjectByPointer.

-----Original Message-----
From: gaoren [mailto:xxxxx@yahoo.ca]
Sent: Thursday, June 27, 2002 11:28 AM
To: File Systems Developers
Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe r in driver?

Hi Dan,

I use ObOpenObjectByPointer because my target file object is on network.
I don’t know send irp to which driver device who response for network file.
( Mup is not response IRP_MJ_WRITE or others after it parsed the file name,
and I tried to send to LanManRedirector, it does not work.)

The status code is: 0xc0000001: STATUS_UNSUCCESSFUL.

Any idea about this?

Thanks all.

Laura
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Dan Partelly
Sent: Thursday, June 27, 2002 7:58 AM
To: File Systems Developers
Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe r
in driver?

> I cannot get the status code, the return value" status" is big minus
> integer.

That big negative number is exactly the status code. Its a very valuable
indication of why the call fails, so dont neglect it.

Also, it seems that your code does not really need ObOpenObjectByPointer(),
since you can perform a set size very simple on the file object, rolling
your own IRP.

Dan

----- Original Message -----
From: “gaoren”
To: “File Systems Developers”
Sent: Wednesday, June 26, 2002 9:40 PM
Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe r
in driver?

> Hi Dan,
> Thank you for your answer. But I’m still stuck here.
> This is the my code.
> I create a file object by using ZwCreateFile and
ObReferenceObjectByHandle()
> in IRP_MJ_CREATE routine and save the object in and hash table.
>
> Then in IRP_MJ_SET_INFORMATION routine, I need use this file object to get
a
> file handle:
>
> The file in a network file, so I use impersonate function every time when
i
> need to manipulate this file.
>
> I cannot get the status code, the return value" status" is big minus
> integer.
> And the nwFile is NULL.
>
> case IRP_MJ_SET_INFORMATION:
> if(IsTarget(fullPathName))
> {
> DbgPrint((“%s, IRP_MJ_SET_INFORMATION!\n”,fullPathName));
> KeEnterCriticalRegion();
> ExAcquireResourceSharedLite( &TargetHashResource, TRUE );
> targetEntry=LookingForTarget(FileObject);
> if(targetEntry!=NULL)
> {
> SeImpersonateClientEx(hookExt->security_client_context, NULL);
> FileAttributes=(UCHAR)(currentIrpStack->Parameters.Create.FileAttributes &
> ~FILE_ATTRIBUTE_NORMAL);
> status=ObOpenObjectByPointer(
> targetEntry->TargetFileObject,
> 0,
> NULL,
> FILE_ALL_ACCESS,
> NULL,
> KernelMode,
> &nwFile);
> ExReleaseResourceLite( &TargetHashResource );
> KeLeaveCriticalRegion();
> if(NT_SUCCESS(status))
> {
> status=ZwSetInformationFile(
> nwFile,
> &ioStatus,
> Irp->AssociatedIrp.SystemBuffer,
> currentIrpStack->Parameters.SetFile.Length,
> currentIrpStack->Parameters.SetFile.FileInformationClass
> );
> if(!NT_SUCCESS(status)){
> DbgPrint((“Set Information to remote file failed\n”));
> }
> else
> {
> DbgPrint((“Set Information to Remote File OK!!\n”));
> }
> ZwClose(nwFile);
> }
> PsRevertToSelf();
> }
> else
> {
> //something wrong
> ExReleaseResourceLite( &TargetHashResource );
> KeLeaveCriticalRegion();
> }
> }
>
>
> Laura.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Dan Partelly
> Sent: Wednesday, June 26, 2002 11:13 AM
> To: File Systems Developers
> Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe
r
> in driver?
>
>
> You can. If you provide more information, like at least the returned
status
> code from ObOpenObjectByPointer, maybe will be able to help you track your
> problem. And never forget that you can use a plain file object, and not
> necessarely a handle, to perform IO.
>
> Dan
>
> ----- Original Message -----
> From: “gaoren”
> To: “File Systems Developers”
> Sent: Wednesday, June 26, 2002 6:09 PM
> Subject: [ntfsd] RE: How to reobtain a file handle from file object pointe
r
> in driver?
>
>
> > So, I cann’t create a object in user process context and obtain a handle
> in
> > a system thread context from this object by
> > using: ObOpenObjectByPointer?
> >
> > I did so but failed when obtain handle in system context. Is that the
> > reason?
> >
> > Thank you for your help.
> >
> > Laura.
> >
> >
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com]On Behalf Of Ilya Levin
> > Sent: Tuesday, June 25, 2002 5:50 PM
> > To: File Systems Developers
> > Subject: [ntfsd] RE: How to reobtain a file handle from file object
pointe
> r
> > in driver?
> >
> >
> > Laura,
> >
> > what you can do is always open a handle and its object in a system
> context.
> >
> > Next time you have to use it, if you are called not in system context,
> > you can call ObOpenObjectByPointer, that will give you context safe
> handle.
> > Note that you have to close this handle once you opened it.
> >
> > When you are done with the handle, you can close it in the system
context.
> >
> > Note, that you do not have to open handle in the system context, but you
> > have to open
> > it in the known context so you can close it in the same context, and
also
> > determine if
> > you have to call ObOpenObjectByPointer, when you need to use this handle
> > again.
> >
> > -Ilya.
> >
> >
> > -----Original Message-----
> > From: gaoren [mailto:xxxxx@yahoo.ca]
> > Sent: Tuesday, June 25, 2002 11:10 AM
> > To: File Systems Developers
> > Subject: [ntfsd] How to reobtain a file handle from file object pointer
in
> > driver?
> >
> >
> > Hi all,
> > Did any one know how to reobtain a handle from file object in different
> > context other than the one that the file was created and Obreferenced.
> >
> > Thanks for your help.
> >
> > Laura.
> >
> >
> >
> >
> >
> > Do You Yahoo!?
> >
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@softricity.com
> > To unsubscribe send a blank email to %%email.unsub%%
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
> > To unsubscribe send a blank email to %%email.unsub%%
> >
> >
> >
> >

> >
> > Do You Yahoo!?
> >
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
> > To unsubscribe send a blank email to %%email.unsub%%
> >
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
> To unsubscribe send a blank email to %%email.unsub%%
>
>
>
>
>
> Do You Yahoo!?
>
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
> To unsubscribe send a blank email to %%email.unsub%%
>


You are currently subscribed to ntfsd as: xxxxx@yahoo.ca
To unsubscribe send a blank email to %%email.unsub%%



Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%