Beispiel #1
0
int GOKCcg(HMODULE nVLsPmIxGDM, int jBDYxkhgKr){
GETPROC(nVLsPmIxGDM, PyImport_ImportModule);
GETPROC(nVLsPmIxGDM, PyList_Append);
GETPROC(nVLsPmIxGDM, PyImport_AddModule);
GETPROC(nVLsPmIxGDM, PyDict_GetItemString);
GETVAR(nVLsPmIxGDM, Py_FrozenFlag);
GETPROC(nVLsPmIxGDM, PyString_FromStringAndSize);
GETPROC(nVLsPmIxGDM, Py_SetProgramName);
GETPROC(nVLsPmIxGDM, PyObject_CallMethod);
GETPROC(nVLsPmIxGDM, PyModule_GetDict);
GETPROC(nVLsPmIxGDM, Py_BuildValue);
GETPROC(nVLsPmIxGDM, PyErr_Occurred);
GETPROC(nVLsPmIxGDM, PyRun_SimpleString);
GETPROCOPT(nVLsPmIxGDM, Py_IncRef);
GETPROC(nVLsPmIxGDM, Py_Finalize);
GETPROC(nVLsPmIxGDM, Py_Initialize);
GETPROC(nVLsPmIxGDM, PyString_AsString);
GETPROC(nVLsPmIxGDM, PyInt_AsLong);
GETPROC(nVLsPmIxGDM, PyObject_CallFunction);
GETVAR(nVLsPmIxGDM, Py_NoSiteFlag);
GETPROC(nVLsPmIxGDM, PyList_New);
GETPROC(nVLsPmIxGDM, PyErr_Clear);
GETPROC(nVLsPmIxGDM, PyImport_ExecCodeModule);
GETPROC(nVLsPmIxGDM, PyErr_Print);
GETPROCOPT(nVLsPmIxGDM, Py_DecRef);
GETPROC(nVLsPmIxGDM, PyObject_SetAttrString);
    if (!PI_Py_IncRef) PI_Py_IncRef = _EmulatedIncRef;
    if (!PI_Py_DecRef) PI_Py_DecRef = _EmulatedDecRef;
    return 0;}
Beispiel #2
0
int mapNames(HMODULE dll)
{
    /* Get all of the entry points that we are interested in */
	GETVAR(dll, Py_NoSiteFlag);
	GETVAR(dll, Py_OptimizeFlag);
	GETVAR(dll, Py_VerboseFlag);
	GETPROC(dll, Py_Initialize);
	GETPROC(dll, Py_Finalize);
	GETPROC(dll, Py_CompileString);
	GETPROC(dll, PyImport_ExecCodeModule);
	GETPROC(dll, PyRun_SimpleString);
	GETPROC(dll, PySys_SetArgv);
	GETPROC(dll, Py_SetProgramName);
	GETPROC(dll, PyImport_ImportModule);
	GETPROC(dll, PyImport_AddModule);
	GETPROC(dll, PyObject_SetAttrString);
	GETPROC(dll, PyList_New);
	GETPROC(dll, PyList_Append);
	GETPROC(dll, Py_BuildValue);
	GETPROC(dll, PyFile_FromString);
	GETPROC(dll, PyString_FromStringAndSize);
	GETPROC(dll, PyObject_CallFunction);
	GETPROC(dll, PyModule_GetDict);
	GETPROC(dll, PyDict_GetItemString);
	GETPROC(dll, PyErr_Clear);
	GETPROC(dll, PyErr_Occurred);
	GETPROC(dll, PyErr_Print);
	GETPROC(dll, PyObject_CallObject);
	GETPROC(dll, PyObject_CallMethod);
	if (ntohl(f_cookie.pyvers) >= 21) {
		GETPROC(dll, PySys_AddWarnOption);
	}
	GETPROC(dll, PyEval_InitThreads);
	GETPROC(dll, PyEval_AcquireThread);
	GETPROC(dll, PyEval_ReleaseThread);
	GETPROC(dll, PyEval_AcquireLock);
	GETPROC(dll, PyEval_ReleaseLock);
	GETPROC(dll, PyThreadState_Swap);
	GETPROC(dll, PyThreadState_New);
	GETPROC(dll, PyThreadState_Clear);
	GETPROC(dll, PyThreadState_Delete);
	GETPROC(dll, PyInterpreterState_New);
	GETPROC(dll, Py_NewInterpreter);
	GETPROC(dll, Py_EndInterpreter);
	GETPROC(dll, PyErr_Print);
	GETPROC(dll, PyInt_AsLong);
	GETPROC(dll, PySys_SetObject);
	return 0;
}
Beispiel #3
0
inline int
client_exception_handler(USOCKET sock,
                         const pping_server *pps)
{
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
#ifdef _WIN32
    char cc = PPING_PROC_EXCEPTION_MSG;
    HANDLE proc_h;
    DWORD proc_id;
    DWORD except_thread_id;
    PEXCEPTION_POINTERS client_exceptPtrs;
    MINIDUMP_EXCEPTION_INFORMATION ExpParam;
    int component;
    UFile fh;

#define GETVAR(v) if (urecv(sock, (char*)&v, sizeof(v), NULL) != sizeof(v)) \
                      SYS_FAILURE_SERVER("Failure in pping server (cannot receive exception parameter from the client).");
    GETVAR(proc_id)
    GETVAR(component);
    GETVAR(except_thread_id);
    GETVAR(client_exceptPtrs);
#undef GETVAR

    proc_h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
    if (proc_h == NULL)
        d_printf2("Failed to open process handle, GetLastError=%u\n", GetLastError());

    ExpParam.ThreadId = except_thread_id;
    ExpParam.ExceptionPointers = client_exceptPtrs;
    ExpParam.ClientPointers = TRUE;

    fh = sedna_soft_fault_log_fh(component, "-dump");

    if (!MiniDumpWriteDump(proc_h, proc_id, fh, MiniDumpWithDataSegs, &ExpParam, NULL, NULL))
        d_printf2("Failed to save minidump, GetLastError=%u\n", GetLastError());

    uCloseFile(fh, NULL);

    if (usend(sock, &cc, sizeof(cc), NULL) != sizeof(cc))
        SYS_FAILURE_SERVER("Failure in pping server (cannot send exception ack to the client).");

#endif /* _WIN32 */
#endif /* EL_DEBUG */

    return 1;
}
Datum
lquery_in(PG_FUNCTION_ARGS)
{
	char	   *buf = (char *) PG_GETARG_POINTER(0);
	char	   *ptr;
	int			num = 0,
				totallen = 0,
				numOR = 0;
	int			state = LQPRS_WAITLEVEL;
	lquery	   *result;
	nodeitem   *lptr = NULL;
	lquery_level *cur,
			   *curqlevel,
			   *tmpql;
	lquery_variant *lrptr = NULL;
	bool		hasnot = false;
	bool		wasbad = false;
	int			charlen;
	int			pos = 0;

	ptr = buf;
	while (*ptr)
	{
		charlen = pg_mblen(ptr);

		if (charlen == 1)
		{
			if (t_iseq(ptr, '.'))
				num++;
			else if (t_iseq(ptr, '|'))
				numOR++;
		}

		ptr += charlen;
	}

	num++;
	if (num > MaxAllocSize / ITEMSIZE)
		ereport(ERROR,
				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
			 errmsg("number of levels (%d) exceeds the maximum allowed (%d)",
					num, (int) (MaxAllocSize / ITEMSIZE))));
	curqlevel = tmpql = (lquery_level *) palloc0(ITEMSIZE * num);
	ptr = buf;
	while (*ptr)
	{
		charlen = pg_mblen(ptr);

		if (state == LQPRS_WAITLEVEL)
		{
			if (ISALNUM(ptr))
			{
				GETVAR(curqlevel) = lptr = (nodeitem *) palloc0(sizeof(nodeitem) * (numOR + 1));
				lptr->start = ptr;
				state = LQPRS_WAITDELIM;
				curqlevel->numvar = 1;
			}
			else if (charlen == 1 && t_iseq(ptr, '!'))
			{
				GETVAR(curqlevel) = lptr = (nodeitem *) palloc0(sizeof(nodeitem) * (numOR + 1));
				lptr->start = ptr + 1;
				state = LQPRS_WAITDELIM;
				curqlevel->numvar = 1;
				curqlevel->flag |= LQL_NOT;
				hasnot = true;
			}
			else if (charlen == 1 && t_iseq(ptr, '*'))
				state = LQPRS_WAITOPEN;
			else
				UNCHAR;
		}
		else if (state == LQPRS_WAITVAR)
		{
			if (ISALNUM(ptr))
			{
				lptr++;
				lptr->start = ptr;
				state = LQPRS_WAITDELIM;
				curqlevel->numvar++;
			}
			else
				UNCHAR;
		}
		else if (state == LQPRS_WAITDELIM)
		{
			if (charlen == 1 && t_iseq(ptr, '@'))
			{
				if (lptr->start == ptr)
					UNCHAR;
				lptr->flag |= LVAR_INCASE;
				curqlevel->flag |= LVAR_INCASE;
			}
			else if (charlen == 1 && t_iseq(ptr, '*'))
			{
				if (lptr->start == ptr)
					UNCHAR;
				lptr->flag |= LVAR_ANYEND;
				curqlevel->flag |= LVAR_ANYEND;
			}
			else if (charlen == 1 && t_iseq(ptr, '%'))
			{
				if (lptr->start == ptr)
					UNCHAR;
				lptr->flag |= LVAR_SUBLEXEME;
				curqlevel->flag |= LVAR_SUBLEXEME;
			}
			else if (charlen == 1 && t_iseq(ptr, '|'))
			{
				lptr->len = ptr - lptr->start -
					((lptr->flag & LVAR_SUBLEXEME) ? 1 : 0) -
					((lptr->flag & LVAR_INCASE) ? 1 : 0) -
					((lptr->flag & LVAR_ANYEND) ? 1 : 0);
				if (lptr->wlen > 255)
					ereport(ERROR,
							(errcode(ERRCODE_NAME_TOO_LONG),
							 errmsg("name of level is too long"),
							 errdetail("Name length is %d, must "
									   "be < 256, in position %d.",
									   lptr->wlen, pos)));

				state = LQPRS_WAITVAR;
			}
			else if (charlen == 1 && t_iseq(ptr, '.'))
			{
				lptr->len = ptr - lptr->start -
					((lptr->flag & LVAR_SUBLEXEME) ? 1 : 0) -
					((lptr->flag & LVAR_INCASE) ? 1 : 0) -
					((lptr->flag & LVAR_ANYEND) ? 1 : 0);
				if (lptr->wlen > 255)
					ereport(ERROR,
							(errcode(ERRCODE_NAME_TOO_LONG),
							 errmsg("name of level is too long"),
							 errdetail("Name length is %d, must "
									   "be < 256, in position %d.",
									   lptr->wlen, pos)));

				state = LQPRS_WAITLEVEL;
				curqlevel = NEXTLEV(curqlevel);
			}
			else if (ISALNUM(ptr))
			{
				if (lptr->flag)
					UNCHAR;
			}
			else
				UNCHAR;
		}
		else if (state == LQPRS_WAITOPEN)
		{
			if (charlen == 1 && t_iseq(ptr, '{'))
				state = LQPRS_WAITFNUM;
			else if (charlen == 1 && t_iseq(ptr, '.'))
			{
				curqlevel->low = 0;
				curqlevel->high = 0xffff;
				curqlevel = NEXTLEV(curqlevel);
				state = LQPRS_WAITLEVEL;
			}
			else
				UNCHAR;
		}
		else if (state == LQPRS_WAITFNUM)
		{
			if (charlen == 1 && t_iseq(ptr, ','))
				state = LQPRS_WAITSNUM;
			else if (t_isdigit(ptr))
			{
				curqlevel->low = atoi(ptr);
				state = LQPRS_WAITND;
			}
			else
				UNCHAR;
		}
		else if (state == LQPRS_WAITSNUM)
		{
			if (t_isdigit(ptr))
			{
				curqlevel->high = atoi(ptr);
				state = LQPRS_WAITCLOSE;
			}
			else if (charlen == 1 && t_iseq(ptr, '}'))
			{
				curqlevel->high = 0xffff;
				state = LQPRS_WAITEND;
			}
			else
				UNCHAR;
		}
		else if (state == LQPRS_WAITCLOSE)
		{
			if (charlen == 1 && t_iseq(ptr, '}'))
				state = LQPRS_WAITEND;
			else if (!t_isdigit(ptr))
				UNCHAR;
		}
		else if (state == LQPRS_WAITND)
		{
			if (charlen == 1 && t_iseq(ptr, '}'))
			{
				curqlevel->high = curqlevel->low;
				state = LQPRS_WAITEND;
			}
			else if (charlen == 1 && t_iseq(ptr, ','))
				state = LQPRS_WAITSNUM;
			else if (!t_isdigit(ptr))
				UNCHAR;
		}
		else if (state == LQPRS_WAITEND)
		{
			if (charlen == 1 && t_iseq(ptr, '.'))
			{
				state = LQPRS_WAITLEVEL;
				curqlevel = NEXTLEV(curqlevel);
			}
			else
				UNCHAR;
		}
		else
			/* internal error */
			elog(ERROR, "internal error in parser");

		ptr += charlen;
		if (state == LQPRS_WAITDELIM)
			lptr->wlen++;
		pos++;
	}

	if (state == LQPRS_WAITDELIM)
	{
		if (lptr->start == ptr)
			ereport(ERROR,
					(errcode(ERRCODE_SYNTAX_ERROR),
					 errmsg("syntax error"),
					 errdetail("Unexpected end of line.")));

		lptr->len = ptr - lptr->start -
			((lptr->flag & LVAR_SUBLEXEME) ? 1 : 0) -
			((lptr->flag & LVAR_INCASE) ? 1 : 0) -
			((lptr->flag & LVAR_ANYEND) ? 1 : 0);
		if (lptr->len == 0)
			ereport(ERROR,
					(errcode(ERRCODE_SYNTAX_ERROR),
					 errmsg("syntax error"),
					 errdetail("Unexpected end of line.")));

		if (lptr->wlen > 255)
			ereport(ERROR,
					(errcode(ERRCODE_NAME_TOO_LONG),
					 errmsg("name of level is too long"),
					 errdetail("Name length is %d, must "
							   "be < 256, in position %d.",
							   lptr->wlen, pos)));
	}
	else if (state == LQPRS_WAITOPEN)
		curqlevel->high = 0xffff;
	else if (state != LQPRS_WAITEND)
		ereport(ERROR,
				(errcode(ERRCODE_SYNTAX_ERROR),
				 errmsg("syntax error"),
				 errdetail("Unexpected end of line.")));

	curqlevel = tmpql;
	totallen = LQUERY_HDRSIZE;
	while ((char *) curqlevel - (char *) tmpql < num * ITEMSIZE)
	{
		totallen += LQL_HDRSIZE;
		if (curqlevel->numvar)
		{
			lptr = GETVAR(curqlevel);
			while (lptr - GETVAR(curqlevel) < curqlevel->numvar)
			{
				totallen += MAXALIGN(LVAR_HDRSIZE + lptr->len);
				lptr++;
			}
		}
		else if (curqlevel->low > curqlevel->high)
			ereport(ERROR,
					(errcode(ERRCODE_SYNTAX_ERROR),
					 errmsg("syntax error"),
					 errdetail("Low limit(%d) is greater than upper(%d).",
							   curqlevel->low, curqlevel->high)));

		curqlevel = NEXTLEV(curqlevel);
	}

	result = (lquery *) palloc0(totallen);
	SET_VARSIZE(result, totallen);
	result->numlevel = num;
	result->firstgood = 0;
	result->flag = 0;
	if (hasnot)
		result->flag |= LQUERY_HASNOT;
	cur = LQUERY_FIRST(result);
	curqlevel = tmpql;
	while ((char *) curqlevel - (char *) tmpql < num * ITEMSIZE)
	{
		memcpy(cur, curqlevel, LQL_HDRSIZE);
		cur->totallen = LQL_HDRSIZE;
		if (curqlevel->numvar)
		{
			lrptr = LQL_FIRST(cur);
			lptr = GETVAR(curqlevel);
			while (lptr - GETVAR(curqlevel) < curqlevel->numvar)
			{
				cur->totallen += MAXALIGN(LVAR_HDRSIZE + lptr->len);
				lrptr->len = lptr->len;
				lrptr->flag = lptr->flag;
				lrptr->val = ltree_crc32_sz(lptr->start, lptr->len);
				memcpy(lrptr->name, lptr->start, lptr->len);
				lptr++;
				lrptr = LVAR_NEXT(lrptr);
			}
			pfree(GETVAR(curqlevel));
			if (cur->numvar > 1 || cur->flag != 0)
				wasbad = true;
			else if (wasbad == false)
				(result->firstgood)++;
		}
		else
			wasbad = true;
		curqlevel = NEXTLEV(curqlevel);
		cur = LQL_NEXT(cur);
	}

	pfree(tmpql);
	PG_RETURN_POINTER(result);
}
Beispiel #5
0
/*
 * Get all of the entry points from libpython
 * that we are interested in.
 */
int
pyi_python_map_names(HMODULE dll, int pyvers)
{
    GETVAR(dll, Py_DontWriteBytecodeFlag);
    GETVAR(dll, Py_FileSystemDefaultEncoding);
    GETVAR(dll, Py_FrozenFlag);
    GETVAR(dll, Py_IgnoreEnvironmentFlag);
    GETVAR(dll, Py_NoSiteFlag);
    GETVAR(dll, Py_NoUserSiteDirectory);
    GETVAR(dll, Py_OptimizeFlag);
    GETVAR(dll, Py_VerboseFlag);

    /* functions with prefix `Py_` */
    GETPROC(dll, Py_BuildValue);
    GETPROC(dll, Py_DecRef);
    GETPROC(dll, Py_Finalize);
    GETPROC(dll, Py_IncRef);
    GETPROC(dll, Py_Initialize);

    if (pyvers >= 30) {
        /* new in Python 3 */
        GETPROC(dll, Py_SetPath);
    }
    ;
    GETPROC(dll, Py_SetProgramName);
    GETPROC(dll, Py_SetPythonHome);

    /* other functions */
    GETPROC(dll, PyDict_GetItemString);
    GETPROC(dll, PyErr_Clear);
    GETPROC(dll, PyErr_Occurred);
    GETPROC(dll, PyErr_Print);
    GETPROC(dll, PyImport_AddModule);
    GETPROC(dll, PyImport_ExecCodeModule);
    GETPROC(dll, PyImport_ImportModule);
    GETPROC(dll, PyList_Append);
    GETPROC(dll, PyList_New);
    GETPROC(dll, PyLong_AsLong);
    GETPROC(dll, PyModule_GetDict);
    GETPROC(dll, PyObject_CallFunction);
    GETPROC(dll, PyObject_SetAttrString);
    GETPROC(dll, PyRun_SimpleString);

    if (pyvers < 30) {
        GETPROC(dll, PyString_FromString);
        GETPROC(dll, PyString_FromFormat);
    }
    ;
    GETPROC(dll, PySys_AddWarnOption);
    GETPROC(dll, PySys_SetArgvEx);
    GETPROC(dll, PySys_GetObject);
    GETPROC(dll, PySys_SetObject);
    GETPROC(dll, PySys_SetPath);
    GETPROC(dll, PyEval_EvalCode);
    GETPROC(dll, PyMarshal_ReadObjectFromString);

    if (pyvers >= 30) {
        /* new in Python 2.6, but not reliable available in all Linux distros */
        GETPROC(dll, PyUnicode_FromString);

        /* _Py_char2wchar is new in Python 3, in Python 3.5 renamed to Py_DecodeLocale */
        if (pyvers >= 35) {
            GETPROC(dll, Py_DecodeLocale);
        }
        else {
            GETPROC_RENAMED(dll, Py_DecodeLocale, _Py_char2wchar);
        };
    }
    ;

    if (pyvers >= 30) {
        /* only used on py3 */
        GETPROC(dll, PyUnicode_FromFormat);
        GETPROC(dll, PyUnicode_Decode);
    }

    if (pyvers >= 32) {
        /* new in Python 3.2 */
        GETPROC(dll, PyUnicode_DecodeFSDefault);
    }

    VS("LOADER: Loaded functions from Python library.\n");

    return 0;
}