Exemplo n.º 1
0
static BOOL _FindNextArg(PCWSTR * pstrFieldSource)
{
    PCWSTR strFieldSource = *pstrFieldSource;
    WCHAR cChar = *strFieldSource;
    BOOL inQuote = FALSE;

    while (cChar)
    {
        if (!inQuote && (cChar == L'=' || cChar == L','))
            break;

        if (cChar == L'"')
            inQuote = !inQuote;

        strFieldSource = CharNextW(strFieldSource);
        cChar = *strFieldSource;
    }

    if (cChar == 0)
    {
        *pstrFieldSource = strFieldSource;
        return FALSE;
    }

    *pstrFieldSource = CharNextW(strFieldSource);
    return TRUE;
}
Exemplo n.º 2
0
static PCWSTR _FindFirstField(PCWSTR strFieldSource)
{
    //Find end of first arg, because
    // behaviour is different if the first separator is an '='
    BOOL inQuote = FALSE;
    PCWSTR tmpArgs = strFieldSource;
    WCHAR cChar = *tmpArgs;
    while (cChar)
    {
        if (cChar == L'=')
            break;

        if (cChar == L',')
            break;

        if (cChar == L'\"')
            inQuote = !inQuote;

        tmpArgs = CharNextW(tmpArgs);
        cChar = *tmpArgs;
    }

    // Skip the text before the first equal sign, if not quoted, unless the arg 0 was requested.
    if (*tmpArgs == L'=' && !inQuote)
    {
        strFieldSource = ++tmpArgs;
        TRACE("Skipped content before the first '=', remainder=%S\n", strFieldSource);
    }

    return strFieldSource;
}
Exemplo n.º 3
0
static BOOL RunHelper(const wchar_t *pEXEName)
{
	wchar_t *pFileName;
	BOOL good;
	STARTUPINFOW si;
	PROCESS_INFORMATION pi;

	{
		DWORD moduleFileNameSize=32768;
		wchar_t *pModuleFileName=LocalAlloc(0,moduleFileNameSize*sizeof *pModuleFileName);
		wchar_t *p;
		wchar_t *pLastSep=pModuleFileName;
		DWORD fileNameSize;

		GetModuleFileNameW(NULL,pModuleFileName,moduleFileNameSize);
		pModuleFileName[moduleFileNameSize-1]=0;

		for(p=pModuleFileName;*p!=0;p=CharNextW(p))
		{
			if(*p==L'\\'||*p==L'/')
				pLastSep=p;
		}

		*pLastSep=0;

		fileNameSize=lstrlenW(pModuleFileName)+1+lstrlenW(pEXEName)+1;
		pFileName=LocalAlloc(0,fileNameSize*sizeof pFileName);

		lstrcpyW(pFileName,pModuleFileName);
		lstrcatW(pFileName,L"\\");
		lstrcatW(pFileName,pEXEName);

		LocalFree(pModuleFileName);
		pModuleFileName=NULL;
	}

	si=SI_ZERO;
	si.cb=sizeof si;

	good=CreateProcessW(pFileName,NULL,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi);
	if(!good)
	{
		DWORD err=GetLastError();
		wchar_t msg[500];

		FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,NULL,err,0,msg,sizeof msg/sizeof msg[0],NULL);

		MessageBoxW(NULL,msg,pFileName,MB_OK|MB_ICONERROR);
	}

	LocalFree(pFileName);
	pFileName=NULL;

	return good;
}
Exemplo n.º 4
0
// wchar_t version.
wchar_t* my_strstrW(wchar_t *i, wchar_t *s)
{
    size_t ilen = lstrlenW(i);
    size_t slen = lstrlenW(s);

    wchar_t *i_iter;
    wchar_t *s_iter;

    wchar_t *rval = NULL;

    while (ilen >= slen)
    {
        i_iter = i;
        s_iter = s;

        while (*s_iter != L'\0')
        {
            if (*i_iter != *s_iter)
            {
                break;
            }
            i_iter = CharNextW(i_iter);
            s_iter = CharNextW(i_iter);
        }

        if (*s_iter == L'\0')
        {
            rval = i;
            break;
        }

        i = CharNextW(i);
        --ilen;
    }

    return rval;
}
Exemplo n.º 5
0
static inline UINT WINAPI GetDirLen(LPCOLESTR lpszPathName) throw()
{
	ATLASSERT(lpszPathName != NULL);

	// always capture the complete file name including extension (if present)
	LPCOLESTR lpszTemp = lpszPathName;
	for (LPCOLESTR lpsz = lpszPathName; *lpsz != NULL; )
	{
		LPCOLESTR lp = CharNextW(lpsz);
		// remember last directory/drive separator
		if (*lpsz == OLESTR('\\') || *lpsz == OLESTR('/') || *lpsz == OLESTR(':'))
			lpszTemp = lp;
		lpsz = lp;
	}

	return UINT( lpszTemp-lpszPathName );
}
Exemplo n.º 6
0
// wchar_t version.
wchar_t *my_strrchrW(wchar_t *string, const wchar_t c)
{
    wchar_t  sch;
    wchar_t* rval = NULL;

    while ((sch = *string) != L'\0')
    {
        if (sch == c)
        {
            rval = string;
            break;
        }
        string = CharNextW(string);
    }

    return rval;
}
Exemplo n.º 7
0
static const wchar_t *scanstr_backW(const wchar_t *str, const wchar_t *toscan, const wchar_t *defval)
{
	const wchar_t *s = GetLastCharactercW(str);
	if (!str[0]) return defval;
	if (!toscan || !toscan[0]) return defval; 
	while (1)
	{
		const wchar_t *t = toscan;
		while (*t)
		{
			if (*t == *s) return s;
			t = CharNextW(t);
		}
		t = CharPrevW(str, s);
		if (t == s)
			return defval;
		s = t;
	}
}
Exemplo n.º 8
0
const WChar * String::NextCharW( const WChar * inStr ) const
{
    return CharNextW( inStr );
}
Exemplo n.º 9
0
//----------------------------------------------------------------------------
//
//  RestoreDeletedObject()
//
//  Restores a deleted object. 
//
//  pwszDeletedDN - Contains the fully-qualified distinguished name of the 
//  deleted object.
//
//  pwszDestContainerDN - Contains the fully-qualified distinguished name of 
//  the folder that the delted object should be moved to.
//
//  Returns S_OK if successful or an HRESULT or LDAP error code otherwise.
//
//----------------------------------------------------------------------------
HRESULT RestoreDeletedObject(LPCWSTR pwszDeletedDN, LPCWSTR pwszDestContainerDN)
{
    if((NULL == pwszDeletedDN) || (NULL == pwszDestContainerDN))
    {
        return E_POINTER;
    }
    
    HRESULT hr = E_FAIL;

    // Build the new distinguished name.
    LPWSTR pwszNewDN = new WCHAR[lstrlenW(pwszDeletedDN) + lstrlenW(pwszDestContainerDN) + 1];
    if(pwszNewDN)
    {
        lstrcpyW(pwszNewDN, pwszDeletedDN);

        // Search for the first 0x0A character. This is the delimiter in the deleted object name.
        LPWSTR pwszChar;
        for(pwszChar = pwszNewDN; *pwszChar; pwszChar = CharNextW(pwszChar))
        {
            if(('\\' == *pwszChar) && ('0' == *(pwszChar + 1)) && ('A' == *(pwszChar + 2)))
            {
                break;
            }
            
        }

        if(0 != *pwszChar)
        {
            // Truncate the name string at the delimiter.
            *pwszChar = 0;

            // Add the last known parent DN to complete the DN.
            lstrcatW(pwszNewDN, L",");
            lstrcatW(pwszNewDN, pwszDestContainerDN);

            PLDAP	ld;

            // Initialize LDAP.
            ld = ldap_init(NULL, LDAP_PORT);
            if(NULL != ld) 
            {
                ULONG ulRC;
                ULONG version = LDAP_VERSION3;

                // Set the LDAP version.
                ulRC = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, (void*)&version);
                if(LDAP_SUCCESS == ulRC)
                {
                    // Establish a connection with the server.
                    ulRC = ldap_connect(ld, NULL);
                    if(LDAP_SUCCESS == ulRC)
                    {                    
                        // Bind to the LDAP server.
                        ulRC = ldap_bind_s(ld, NULL, NULL, LDAP_AUTH_NEGOTIATE);
                        if(LDAP_SUCCESS == ulRC)
                        {
                            // Setup the new values.
                            LPWSTR rgNewVals[] = {pwszNewDN, NULL};

                            /*
                            Remove the isDeleted attribute. This cannot be set 
                            to FALSE or the restore operation will not work.
                            */
                            LDAPModW modIsDeleted = { LDAP_MOD_DELETE, L"isDeleted", NULL };

                            /*
                            Set the new DN, in effect, moving the deleted 
                            object to where it resided before the deletion.
                            */
                            LDAPModW modDN = { LDAP_MOD_REPLACE, L"distinguishedName", rgNewVals };
                            
                            // Initialize the LDAPMod structure.
                            PLDAPModW ldapMods[] = 
                            {
                                &modIsDeleted,
                                &modDN,
                                NULL
                            };

                            /*
                            Use the LDAP_SERVER_SHOW_DELETED_OID control to 
                            modify deleted objects.
                            */
                            LDAPControlW showDeletedControl;
                            showDeletedControl.ldctl_oid = LDAP_SERVER_SHOW_DELETED_OID_W;
                            showDeletedControl.ldctl_value.bv_len = 0;
                            showDeletedControl.ldctl_value.bv_val = NULL;
                            showDeletedControl.ldctl_iscritical = TRUE;

                            // Initialzie the LDAPControl structure
                            PLDAPControlW ldapControls[] = { &showDeletedControl, NULL };

                            /*
                            Modify the specified attributes. This must performed 
                            in one step, which is why the LDAP APIs must be used 
                            to restore a deleted object.
                            */
                            ulRC = ldap_modify_ext_sW(ld, (PWCHAR)pwszDeletedDN, ldapMods, ldapControls, NULL);
                            if(LDAP_SUCCESS == ulRC)
                            {
                                hr = S_OK;
                            }
                            else if(LDAP_ALREADY_EXISTS == ulRC)
                            {
                                /*
                                An object already exists with the specified name 
                                in the specified target container. At this point, 
                                a new name must be selected.
                                */
                            }
                        }
                    }
                }

                if(LDAP_SUCCESS != ulRC)
                {
                    hr = ulRC;
                    
                    OutputDebugString(ldap_err2string(ulRC));
                }

                // Release the LDAP session.
                ldap_unbind(ld);
            }
        }
        else
        {
            /*
            If the end of the string is reached before the delimiter is found, just 
            end and fail.
            */
            hr = E_INVALIDARG;
        }
    
        delete pwszNewDN;
    }
    else
    {
        hr = E_OUTOFMEMORY;
    }

    return hr;
}
Exemplo n.º 10
0
static BOOL _CopyAndUnquoteText(LPCWSTR strFieldSource, LPWSTR strField, size_t cchField)
{
    WCHAR cChar;
    PWSTR tmpField = strField;
    size_t lenField = 1;
    BOOL inQuote = FALSE;

    // Remove leading whitespace
    cChar = *strFieldSource;
    while (cChar == L' ' || cChar == L'\t' || cChar == L'\n' || cChar == L'\r')
    {
        strFieldSource = CharNextW(strFieldSource);
        cChar = *strFieldSource;
    }

    while (cChar && cChar != L'=' && cChar != L',')
    {
        if (cChar == L'"')
        {
            // [1] is always valid read because of null-termination
            if (inQuote && strFieldSource[1] == L'"')
            {
                if (lenField < cchField)
                {
                    // Append
                    *(tmpField++) = L'"';
                    ++lenField;
                }

                // Skip second quote
                strFieldSource++;
            }
            else
            {
                inQuote = !inQuote;
            }
        }
        else
        {
            if (inQuote || (cChar != L'=' && cChar != L','))
            {
                if (lenField < cchField)
                {
                    // Append
                    *(tmpField++) = cChar;
                    ++lenField;
                }
            }
        }

        strFieldSource = CharNextW(strFieldSource);
        cChar = *strFieldSource;
    }

    // Remove trailing whitespace
    while (tmpField > strField)
    {
        tmpField = CharPrevW(strField, tmpField);
        cChar = *tmpField;
        if (cChar != L' ' && cChar != L'\t' && cChar != L'\n' && cChar != L'\r')
        {
            tmpField = CharNextW(tmpField);
            break;
        }
    }

    // Terminate output string
    *tmpField = 0;

    return TRUE;
}