// @pymethod <o PyIStorage>|pythoncom|StgOpenStorage|Opens an existing root storage object in the file system.
PyObject *pythoncom_StgOpenStorage(PyObject *self, PyObject *args)
{
	PyObject *temp = NULL;
	DWORD reserved = 0;
	PyObject *obName;
	DWORD mode;
	IStorage *pResult;
	PyObject *obOther;

	if (!PyArg_ParseTuple(args, "OOi|Oi:StgOpenStorage",
		               &obName, // @pyparm string|name||Name of the stream, or possibly None if storageOther is non None.
					   &obOther, // @pyparm <o PyIStorage>|other||Usually None, or another parent storage.
					   &mode, // @pyparm int|mode||Specifies the access mode used to open the storage.  A combination of the storagecon.STGM_* constants.
					   &temp, // @pyparm object|snbExclude|None|Not yet supported - must be None
					   &reserved)) // @pyparm int|reserved|0|A reserved value
		return NULL;
	PyWin_AutoFreeBstr bstrName;
	if ( !PyWinObject_AsAutoFreeBstr(obName, &bstrName, TRUE) )
		return NULL;
	IStorage *pOther;
	if (!PyCom_InterfaceFromPyObject(obOther, IID_IStorage, (void **)&pOther, TRUE))
		return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = StgOpenStorage(bstrName, pOther, mode, NULL, reserved, &pResult);
	if (pOther) pOther->Release();
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr)) return PyCom_BuildPyException(hr);
	return PyCom_PyObjectFromIUnknown(pResult, IID_IStorage, FALSE);
}
// @pymethod int|pythoncom|StgIsStorageFile|Indicates whether a particular disk file contains a storage object.
PyObject *pythoncom_StgIsStorageFile(PyObject *self, PyObject *args)
{
	PyObject *obName;
	if (!PyArg_ParseTuple(args, "O:StgIsStorageFile",
		               &obName)) // @pyparm string|name||The path to the file to check.
		return NULL;
	PyWin_AutoFreeBstr bstrName;
	if ( !PyWinObject_AsAutoFreeBstr(obName, &bstrName) )
		return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = StgIsStorageFile(bstrName);
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr)) return PyCom_BuildPyException(hr);
	// @rdesc The return value is 1 if a storage file, else 0.  This
	// method will also raise com_error if the StgIsStorageFile function
	// returns a failure HRESULT.
	return PyInt_FromLong(hr==0);
}
Exemple #3
0
// @pymethod |PyIDispatchEx|DeleteMemberByName|
PyObject *PyIDispatchEx::DeleteMemberByName(PyObject *self, PyObject *args)
{
	long fdex;
	PyObject *obName;
	if (!PyArg_ParseTuple(args, "Ol:DeleteMemberByName",
		&obName, // @pyparm <o PyUnicode>|name||Passed in name to be mapped
		&fdex)) // @pyparm int|fdex||Determines the options 
		return NULL;
	PyWin_AutoFreeBstr name;
	if (!PyWinObject_AsAutoFreeBstr(obName, &name))
		return NULL;
	IDispatchEx *pMyDispatchEx = GetI(self);
	if (pMyDispatchEx==NULL) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pMyDispatchEx->DeleteMemberByName(name, (DWORD)fdex);
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr)) return SetPythonCOMError(self, hr);
	Py_INCREF(Py_None);
	return Py_None;
}
Exemple #4
0
// @pymethod int|PyIDispatchEx|GetDispID|Returns the member id for a name
PyObject *PyIDispatchEx::GetDispID(PyObject *self, PyObject *args)
{
	long fdex;
	PyObject *obName;
	if (!PyArg_ParseTuple(args, "Ol:GetDispId",
		&obName, // @pyparm <o PyUnicode>|name||Passed in name to be mapped
		&fdex)) // @pyparm int|fdex||Determines the options for obtaining the member identifier. This can be a combination of the fdex* constants:
		return NULL;
	PyWin_AutoFreeBstr name;
	if (!PyWinObject_AsAutoFreeBstr(obName, &name))
		return NULL;
	IDispatchEx *pMyDispatchEx = GetI(self);
	if (pMyDispatchEx==NULL) return NULL;
	DISPID dispid;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pMyDispatchEx->GetDispID(name, (DWORD)fdex, &dispid);
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr)) return SetPythonCOMError(self, hr);
	return PyInt_FromLong(dispid);
}
// @pymethod <o PyIStorage>|pythoncom|StgCreateDocfile|Creates a new compound file storage object using the OLE-provided compound file implementation for the <o PyIStorage> interface.
PyObject *pythoncom_StgCreateDocfile(PyObject *self, PyObject *args)
{
	DWORD reserved = 0;
	PyObject *obName;
	DWORD mode;
	IStorage *pResult;

	if (!PyArg_ParseTuple(args, "Oi|i:StgCreateDocfile",
		&obName, // @pyparm string|name||the path of the compound file to create. It is passed uninterpreted to the file system. This can be a relative name or None.  If None, a temporary stream is created.
		&mode, // @pyparm int|mode||Specifies the access mode used to open the storage.
		&reserved)) // @pyparm int|reserved|0|A reserved value
		return NULL;
	PyWin_AutoFreeBstr bstrName;
	if ( !PyWinObject_AsAutoFreeBstr(obName, &bstrName, TRUE) )
		return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = StgCreateDocfile(bstrName, mode, reserved, &pResult);
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr)) return PyCom_BuildPyException(hr);
	return PyCom_PyObjectFromIUnknown(pResult, IID_IStorage, FALSE);
}
Exemple #6
0
// @pymethod [groupName, ...]|win32net|NetUserGetLocalGroups|Retrieves a list of local groups to which a specified user belongs.
// @todo This needs to be extended to support the new model, while
// not breaking existing code.  A default arg would be perfect.
PyObject *
PyNetUserGetLocalGroups( PyObject *self, PyObject *args)
{
	DWORD dwFlags = LG_INCLUDE_INDIRECT;
	DWORD dwBuffsize = 0xFFFFFFFF;	// request it all baby! 
	PyWin_AutoFreeBstr wzServerName;		// storage for incoming domain string pointer
	PyWin_AutoFreeBstr wzUserName;			// incoming username
	PyObject *obServerName;
	PyObject *obUserName;

	if (!PyArg_ParseTuple(args, "OO|i:NetUserGetLocalGroups",
			&obServerName, // @pyparm string|serverName||The name of the remote server on which the function is to execute. None or an empty string specifies the server program running on the local computer.
			&obUserName, // @pyparm string|userName||The name of the user to search for in each group account. This parameter can be of the form \<UserName\>, in which case the username is expected to be found on servername. The user name can also be of the form \<DomainName\>\\\<UserName\> in which case \<DomainName\> is associated with servername and \<UserName\> is expected to be to be found on that domain. 
			&dwFlags)) // @pyparm int|flags|LG_INCLUDE_INDIRECT|Flags for the call.
		return NULL;

	if (!PyWinObject_AsAutoFreeBstr(obServerName, &wzServerName, TRUE))
		return NULL;
	if (!PyWinObject_AsAutoFreeBstr(obUserName, &wzUserName, FALSE))
		return NULL;

	DWORD dwMaxCount, dwCount;		// see the win32api call for how these are used.
	LOCALGROUP_USERS_INFO_0 *lpBuffer;
	NET_API_STATUS Errno;

	dwMaxCount = dwCount = 0;

	PyObject * pRetlist = PyList_New(0);	//create a return list of 0 size
	if (pRetlist==NULL) return NULL; // did we err?
	
	Py_BEGIN_ALLOW_THREADS
	Errno = NetUserGetLocalGroups(wzServerName, wzUserName, 0, dwFlags, (LPBYTE *)&lpBuffer, dwBuffsize, &dwCount, &dwMaxCount);	// do the enumeration
    Py_END_ALLOW_THREADS

	if (Errno == NERR_Success)	// if no error, then build the list
	{

		LOCALGROUP_USERS_INFO_0 *p_nr = lpBuffer;	// Enum Resource returns a buffer of successive structs

		if (dwCount > 0)	// we actually got something
		{
			do
			{
				PyObject *t_ob = PyWinObject_FromWCHAR(p_nr->lgrui0_name);

				int listerr = PyList_Append(pRetlist,t_ob);				// append our obj...Append does an INCREF!

				Py_DECREF(t_ob);

				if (listerr)	// or bail
				{
					Py_DECREF(pRetlist);	// free the Python List
					NetApiBufferFree((LPVOID)lpBuffer);
					return NULL;
				}

				p_nr++;	// next object (its a ++ because it is a typed pointer!)
				dwCount--;
			} while (dwCount);
		}; // if (dwCount > 0)

	}	
	else	// ERROR Occurred
	{
		Py_DECREF(pRetlist);
		return ReturnNetError("NetUserGetLocalGroups", Errno);
	}

	NetApiBufferFree((LPVOID)lpBuffer);
	return pRetlist;
}
Exemple #7
0
// @pymethod [(groupName, attribute), ...]|win32net|NetUserGetGroups|Returns a list of groups,attributes for all groups for the user.
// @todo This needs to be extended to support the new model, while
// not breaking existing code.  A default arg would be perfect.
PyObject *
PyNetUserGetGroups( PyObject *self, PyObject *args)
{
	DWORD dwBuffsize = MAX_PREFERRED_LENGTH;	
	PyWin_AutoFreeBstr	wzServerName;		// storage for incoming servername string pointer
	PyWin_AutoFreeBstr	wzUserName;			// incoming username
	PyObject *		obServerName;
	PyObject *              obUserName;

	
	if (!PyArg_ParseTuple(args, "OO:NetUserGetGroups",
			&obServerName, // @pyparm string|serverName||The name of the remote server on which the function is to execute. None or an empty string specifies the server program running on the local computer.
			&obUserName)) // @pyparm string|userName||The name of the user to search for in each group account.
		return NULL;

	if (!PyWinObject_AsAutoFreeBstr(obServerName, &wzServerName, TRUE))
		return NULL;
	if (!PyWinObject_AsAutoFreeBstr(obUserName, &wzUserName, FALSE))
		return NULL;

	DWORD dwMaxCount, dwCount;		// see the win32api call for how these are used.
	GROUP_USERS_INFO_1 *lpBuffer;
	NET_API_STATUS Errno;

	dwMaxCount = dwCount = 0;

	PyObject * pRetlist = PyList_New(0);	//create a return list of 0 size
	if (pRetlist==NULL) return NULL; // did we err?
	
	Py_BEGIN_ALLOW_THREADS
	Errno = NetUserGetGroups((BSTR)wzServerName, (BSTR)wzUserName, 1, (LPBYTE *)&lpBuffer, dwBuffsize, &dwCount, &dwMaxCount);
	Py_END_ALLOW_THREADS

	if (Errno == NERR_Success)	// if no error, then build the list
	{

		GROUP_USERS_INFO_1 *p_nr = lpBuffer;	// Enum Resource returns a buffer of successive structs

		if (dwCount > 0)	// we actually got something
		{
			do
			{
				PyObject *obName = PyWinObject_FromWCHAR(p_nr->grui1_name);
				PyObject *t_ob = Py_BuildValue("(Oi)",obName, p_nr->grui1_attributes);	
				Py_XDECREF(obName);

				int listerr = PyList_Append(pRetlist,t_ob);				// append our obj...Append does an INCREF!
				Py_DECREF(t_ob);
				if (listerr)	// or bail
				{
					Py_DECREF(pRetlist);	// free the Python List
					NetApiBufferFree((LPVOID)lpBuffer);
					return NULL;
				}

				p_nr++;	// next object (its a ++ because it is a typed pointer!)
				dwCount--;
			} while (dwCount);
		}; // if (dwCount > 0)

	}	
	else {	// ERROR Occurred
		Py_DECREF(pRetlist);
		return ReturnNetError("NetUserGetGroups", Errno);
	}
	// @rdesc Always makes the level 1 call and returns all data.
	// Data return format is a Python List.  Each "Item"
	// is a tuple of (groupname, attributes).  "(s,i)" respectively.  In NT 4 the attributes seem to be hardcoded to 7.
	// Earlier version of NT have not been tested.
	NetApiBufferFree((LPVOID)lpBuffer);
	return pRetlist;

}
// ---------------------------------------------------
//
// Gateway Implementation
STDMETHODIMP PyGOleCommandTarget::QueryStatus(
		/* [unique][in] */ const GUID * pguidCmdGroup,
		/* [in] */ ULONG cCmds,
		/* [out][in][size_is] */ OLECMD prgCmds[],
		/* [unique][out][in] */ OLECMDTEXT * pCmdText)
{
	PY_GATEWAY_METHOD;
	PyObject *obGUID;
	if (pguidCmdGroup == NULL) {
		obGUID = Py_None;
		Py_INCREF(obGUID);
	} else {
		obGUID = PyWinObject_FromIID(*pguidCmdGroup);
	}
	PyObject *cmds = PyList_New(cCmds);
	if (!cmds) {
		Py_DECREF(obGUID);
		MAKE_PYCOM_GATEWAY_FAILURE_CODE("QueryStatus");
	}
	for (ULONG i=0;i<cCmds;i++) {
		PyList_SET_ITEM(cmds, i,
				Py_BuildValue("ll", prgCmds[i].cmdID, prgCmds[i].cmdf));
	}
	PyObject *obText;
	if (!pCmdText) {
		obText = Py_None;
		Py_INCREF(Py_None);
	} else
		obText = PyInt_FromLong(pCmdText->cmdtextf);
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("QueryStatus", &result, "NNN", obGUID, cmds, obText);
	if (FAILED(hr)) return hr;

	BOOL ok = PyArg_ParseTuple(result, "OO", &cmds, &obText);
	if (ok) {
		if (pCmdText == NULL) {
			if (obText != Py_None) {
				PyErr_SetString(PyExc_ValueError,
						"String value returned but caller didn't request it (check the 3rd param!)");
				ok = FALSE;
			}
		} else {
			PyWin_AutoFreeBstr tempString;
			ok = PyWinObject_AsAutoFreeBstr(obText, &tempString);
			if (ok) {
				UINT strLen = SysStringLen(tempString);
				UINT nwrite = min(strLen, pCmdText->cwBuf);
				wcsncpy(pCmdText->rgwz, (WCHAR *)(BSTR)tempString,
					nwrite);
				pCmdText->cwActual = nwrite;
			}
		}
	}
	if (ok) {
		if (!PySequence_Check(cmds)) {
			PyErr_SetString(PyExc_TypeError, "OLECMD objects must be a sequence");
			ok = FALSE;
		}
		if (ok && (UINT)PySequence_Length(cmds) != cCmds) {
			PyErr_Format(PyExc_ValueError, "Sequence must have %d items (got %d)",
				     cCmds, PySequence_Length(cmds));
			ok = FALSE;
			
		}
		if (ok)
			ok = FillOLECMDsWithSequence(prgCmds, cCmds, cmds);
	}
	Py_DECREF(result);
	if (!ok)
		hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("QueryStatus");
	return hr;
}