Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19651
Modified Files:
PySECURITY_ATTRIBUTES.cpp PySECURITY_DESCRIPTOR.cpp
Log Message:
Patch to fix the use of pywintypes.SECURITY_ATTRIBUTES() on Win9x; ultimately
to allow one to use the SECURITY_ATTRIBUTES.bInheritHandles boolean with
win32pipe.CreatePipe without being required to support the SECURITY_DESCRIPTOR
structure, whose use is not supported on Win9x. The breaks was in these
checkins:
http://cvs.sourceforge.net/viewcvs.py/pywin32/pywin32/win32/src/PySECURITY_ATTRIBUTES.cpp?r1=1.3&r2=1.4
http://cvs.sourceforge.net/viewcvs.py/pywin32/pywin32/win32/src/PySECURITY_DESCRIPTOR.cpp?r1=1.7&r2=1.8
Most of this patch is from Roger Upole. My change involved changing the trigger
from a failure in InitializeSecurityDescriptor (which doesn't actually fail on
Win9x) to a zero retval from GetSecurityDescriptorLength.
Index: PySECURITY_DESCRIPTOR.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PySECURITY_DESCRIPTOR.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** PySECURITY_DESCRIPTOR.cpp 19 Jan 2005 21:16:20 -0000 1.14
--- PySECURITY_DESCRIPTOR.cpp 27 Jan 2005 01:46:44 -0000 1.15
***************
*** 235,239 ****
free (this->m_psd);
DWORD sdsize = GetSecurityDescriptorLength(psd);
! if (_IsSelfRelative(psd)){
this->m_psd = malloc(sdsize);
memcpy(this->m_psd, psd, sdsize);
--- 235,244 ----
free (this->m_psd);
DWORD sdsize = GetSecurityDescriptorLength(psd);
! if (sdsize == 0){
! // GetSecurityDescriptorLength returns 0 on Win9x where the
! // SECURITY_DESCRIPTOR stuff is not supported.
! this->m_psd = NULL;
! }
! else if (_IsSelfRelative(psd)){
this->m_psd = malloc(sdsize);
memcpy(this->m_psd, psd, sdsize);
***************
*** 688,694 ****
cb = max(cb, SECURITY_DESCRIPTOR_MIN_LENGTH);
PSECURITY_DESCRIPTOR psd = malloc(cb);
- ::InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION);
this->m_psd=NULL;
! this->SetSD(psd);
free(psd);
}
--- 693,699 ----
cb = max(cb, SECURITY_DESCRIPTOR_MIN_LENGTH);
PSECURITY_DESCRIPTOR psd = malloc(cb);
this->m_psd=NULL;
! if (::InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION))
! this->SetSD(psd);
free(psd);
}
Index: PySECURITY_ATTRIBUTES.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PySECURITY_ATTRIBUTES.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** PySECURITY_ATTRIBUTES.cpp 30 Mar 2004 04:14:27 -0000 1.6
--- PySECURITY_ATTRIBUTES.cpp 27 Jan 2005 01:46:44 -0000 1.7
***************
*** 49,54 ****
*ppSECURITY_ATTRIBUTES = pysa->GetSA();
// in case the PySECURITY_DESCRIPTOR has been manipulated and points to a different address now
! ((SECURITY_ATTRIBUTES *)*ppSECURITY_ATTRIBUTES)->lpSecurityDescriptor =
! ((PySECURITY_DESCRIPTOR *)pysa->m_obSD)->GetSD();
}
return TRUE;
--- 49,56 ----
*ppSECURITY_ATTRIBUTES = pysa->GetSA();
// in case the PySECURITY_DESCRIPTOR has been manipulated and points to a different address now
! if (pysa->m_obSD==Py_None)
! (*ppSECURITY_ATTRIBUTES)->lpSecurityDescriptor=NULL;
! else
! (*ppSECURITY_ATTRIBUTES)->lpSecurityDescriptor=((PySECURITY_DESCRIPTOR *)pysa->m_obSD)->GetSD();
}
return TRUE;
***************
*** 87,93 ****
/*static*/ struct memberlist PySECURITY_ATTRIBUTES::memberlist[] = {
{"bInheritHandle", T_INT, OFF(m_sa.bInheritHandle)}, // @prop integer|bInheritHandle|Specifies whether the returned handle is inherited when a new process is created. If this member is TRUE, the new process inherits the handle.
! {"SECURITY_DESCRIPTOR", T_OBJECT, OFF(m_obSD)},
! {NULL} /* Sentinel */
};
PySECURITY_ATTRIBUTES::PySECURITY_ATTRIBUTES(void)
--- 89,102 ----
/*static*/ struct memberlist PySECURITY_ATTRIBUTES::memberlist[] = {
{"bInheritHandle", T_INT, OFF(m_sa.bInheritHandle)}, // @prop integer|bInheritHandle|Specifies whether the returned handle is inherited when a new process is created. If this member is TRUE, the new process inherits the handle.
! {"SECURITY_DESCRIPTOR", T_OBJECT, OFF(m_obSD)}, // @prop <o PySECURITY_DESCRIPTOR>|SECURITY_DESCRIPTOR|A PySECURITY_DESCRIPTOR, or None
! {NULL}
};
+ // @comm On platforms that support security descriptor operations, SECURITY_DESCRIPTOR
+ // defaults to a blank security descriptor with no owner, group, dacl, or sacl.
+ // Set to None to use a NULL security descriptor instead.
+ // When PySECURITY_ATTRIBUTES is created on Windows 95/98/Me, SECURITY_DESCRIPTOR defaults
+ // to None and should not be changed.
+ // When SECURITY_DESCRIPTOR is not None, any of its methods can be invoked directly
+ // on the PySECURITY_ATTRIBUTES object
PySECURITY_ATTRIBUTES::PySECURITY_ATTRIBUTES(void)
***************
*** 96,104 ****
_Py_NewReference(this);
m_sa.nLength = sizeof(SECURITY_ATTRIBUTES);
! m_obSD = new PySECURITY_DESCRIPTOR();
! m_sa.lpSecurityDescriptor = ((PySECURITY_DESCRIPTOR *)m_obSD)->GetSD();
m_sa.bInheritHandle = TRUE;
}
-
PySECURITY_ATTRIBUTES::PySECURITY_ATTRIBUTES(const SECURITY_ATTRIBUTES &sa)
{
--- 105,120 ----
_Py_NewReference(this);
m_sa.nLength = sizeof(SECURITY_ATTRIBUTES);
! m_obSD = new PySECURITY_DESCRIPTOR(SECURITY_DESCRIPTOR_MIN_LENGTH);
! m_sa.lpSecurityDescriptor=((PySECURITY_DESCRIPTOR *)m_obSD)->GetSD();
! // On win95/98/me (or any platform that doesn't have NT security) the
! // initialization of the SECURITY_DESCRIPTOR shoudl fail, leaving the
! // sd NULL.
! if (m_sa.lpSecurityDescriptor==NULL){
! Py_DECREF(m_obSD);
! Py_INCREF(Py_None);
! m_obSD=Py_None;
! }
m_sa.bInheritHandle = TRUE;
}
PySECURITY_ATTRIBUTES::PySECURITY_ATTRIBUTES(const SECURITY_ATTRIBUTES &sa)
{
***************
*** 106,112 ****
_Py_NewReference(this);
m_sa = sa;
! m_obSD = new PySECURITY_DESCRIPTOR(sa.lpSecurityDescriptor);
! // above creates a copy, put pointer to copy back in SECURITY_ATTRIBUTES structure
! m_sa.lpSecurityDescriptor=((PySECURITY_DESCRIPTOR *)m_obSD)->GetSD();
}
--- 122,136 ----
_Py_NewReference(this);
m_sa = sa;
! if (sa.lpSecurityDescriptor==NULL){
! // ???? could change existing behaviour - what happened with a NULL previously ????
! // This is consistent with PyWinObject_FromSECURITY_DESCRIPTOR
! Py_INCREF(Py_None);
! m_obSD=Py_None;
! }
! else{
! m_obSD = new PySECURITY_DESCRIPTOR(sa.lpSecurityDescriptor);
! // above creates a copy, put pointer to copy back in SECURITY_ATTRIBUTES structure
! m_sa.lpSecurityDescriptor=((PySECURITY_DESCRIPTOR *)m_obSD)->GetSD();
! }
}
***************
*** 129,135 ****
return res;
// let it inherit methods from PySECURITY_DESCRIPTOR for backward compatibility
- PyErr_Clear();
PySECURITY_ATTRIBUTES *This = (PySECURITY_ATTRIBUTES *)self;
! return ((PySECURITY_DESCRIPTOR *)(This->m_obSD))->getattr(This->m_obSD, name);
}
--- 153,162 ----
return res;
// let it inherit methods from PySECURITY_DESCRIPTOR for backward compatibility
PySECURITY_ATTRIBUTES *This = (PySECURITY_ATTRIBUTES *)self;
! if (This->m_obSD!=Py_None){
! PyErr_Clear();
! res=((PySECURITY_DESCRIPTOR *)(This->m_obSD))->getattr(This->m_obSD, name);
! }
! return res;
}
***************
*** 141,151 ****
}
if (strcmp(name, "SECURITY_DESCRIPTOR")==0){
! if (!PySECURITY_DESCRIPTOR_Check(v)){
! PyErr_SetString(PyExc_TypeError, "The object is not a PySECURITY_DESCRIPTOR object");
return -1;
}
- PySECURITY_ATTRIBUTES *This=(PySECURITY_ATTRIBUTES *)self;
- // Py_DECREF(This->m_obSD);
- This->m_sa.lpSecurityDescriptor=((PySECURITY_DESCRIPTOR *)This->m_obSD)->GetSD();
}
return PyMember_Set((char *)self, memberlist, name, v);
--- 168,180 ----
}
if (strcmp(name, "SECURITY_DESCRIPTOR")==0){
! PySECURITY_ATTRIBUTES *This=(PySECURITY_ATTRIBUTES *)self;
! if (v==Py_None)
! This->m_sa.lpSecurityDescriptor=NULL;
! else if (PySECURITY_DESCRIPTOR_Check(v))
! This->m_sa.lpSecurityDescriptor=((PySECURITY_DESCRIPTOR *)This->m_obSD)->GetSD();
! else{
! PyErr_SetString(PyExc_TypeError, "SECURITY_DESCRIPTOR must be a PySECURITY_DESCRIPTOR, or None");
return -1;
}
}
return PyMember_Set((char *)self, memberlist, name, v);
|