ADSI userAccountControl Furtif_00 Project

Hi everybody

I continue the last year project of Furtif_00 that you can see here :
http://www.dev-archive.com/forum/showthread.php?t=309450&page=4

and i have to modify the "change password" option of a user.
i know that this could be done with the "userAccountControl" .
I try the folowing code in c++ but it doesn't work.
is somebody know how to do this??

thanks for helping me .

here is the code :

bool CActiveDirectory::expire(CCFXRequest *pRequest)
{

USES_CONVERSION;
IADsUser *pUser;

strinExpire = pRequest->GetAttribute( "Expire" );
hr = bindToUser( &pUser, pRequest );
if( SUCCEEDED( hr ))
{
if( pUser )
{
VARIANT var;
//VariantInit(&var);
//V_BSTR(&var) =A2W(strinExpire);
//V_VT(&var)=VT_BSTR;
hr=pUser->Get(L"userAccountControl",&var);
var.intVal = var.intVal^64;
if(FAILED(hr))
{
return false;
}
pUser->Put(L"userAccountControl",var);
pUser->SetInfo();
pUser->Release();
VariantClear(&var);
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
[1293 byte] By [nander] at [2007-11-19 10:17:16]
# 1 Re: ADSI userAccountControl Furtif_00 Project
Are you trying to expire the password, force the user to change it.

If so, try ( MSDN sample )

//=======================================================
// Set the pwdLastSet property to zero, which forces the
// user to change the password the next time they log on
//=======================================================

CComVariant svar;

sbstrProp = "pwdLastSet";
svar = 0;
hr = pUser->Put(sbstrProp, svar);

hr = pUser->SetInfo();

or if you are trying to set the password so it does not expire. (also from MSDN)

//==========================================================
// Add ADS_UF_DONT_EXPIRE_PASSWD flag to the
// userAccountControl property.
//==========================================================
CComVariant svar;

sbstrProp = "userAccountControl";

hr = pUser->Get(sbstrProp, &svar);

if(SUCCEEDED(hr))
{
svar = svar.lVal & (ADS_UF_DONT_EXPIRE_PASSWD);

hr = pUser->Put(sbstrProp, svar);
hr = pUser->SetInfo();
}

hr = pUser->SetInfo();

HTH
f1shrman at 2007-11-10 3:39:11 >
# 2 Re: ADSI userAccountControl Furtif_00 Project
I tryed out your code but the setinfo function repliy with the 0x80072035 that mean that the server cannot perform the request operation.
I will search futher and repost if i have probleme thank a lot.
nander at 2007-11-10 3:40:10 >
# 3 Re: ADSI userAccountControl Furtif_00 Project
So now it works : the Never expire option can be set with this code :

IADsUser *pUser;
VARIANT var;
VariantInit(&var);

HRESULT hr = S_OK;

hr = pUser->Get(L"userAccountControl", &var);
if(FAILED(hr))
{
return false;
}
V_I4(&var) |= ADS_UF_DONT_EXPIRE_PASSWD;
hr = pUser->Put(L"userAccountControl", var);
if(FAILED(hr))
{
return false;
}
hr = pUser->SetInfo();
if(FAILED(hr))
{
return false;
}
VariantClear(&var);
pUser->Release();
return true;

ps : sorry i do not know how to put the code in a little windows !! ;-)
nander at 2007-11-10 3:41:08 >
# 4 Re: ADSI userAccountControl Furtif_00 Project
I try to reset the password never expire option with the same code but
i do like this

V_I4(&var) &= !(ADS_UF_DONT_EXPIRE_PASSWD);

but it does not work

how can i do to reset this option ??
nander at 2007-11-10 3:42:16 >
# 5 Re: ADSI userAccountControl Furtif_00 Project
Bon ba si sa marche pas demande a Dom il va te dire comment faire car lui un jour au stage d't il s prit une flute ds le cul ou demande a Gwenec de te preter une de ses chemises Fashion sa pourra t inspirer :)

Aller Homme des Cavernes a poils longs a plus. MSN ne marche plus car ils ont un routeur NetGear et sa fout la merde sur le rseau
Furtif_00 at 2007-11-10 3:43:15 >
# 6 Re: ADSI userAccountControl Furtif_00 Project
If you are trying to remove the flag try using the ~ operator

V_I4(&var) & ~ ( ADS_UF_ACCOUNTDISABLE );

HTH
f1shrman at 2007-11-10 3:44:10 >
# 7 Re: ADSI userAccountControl Furtif_00 Project
it doesn't make error just a warning : "operator & without effect, operator with secondary effect" and it does not reset the flag
i don't know the ~ operator what is it suppose to do??
nander at 2007-11-10 3:45:14 >
# 8 Re: ADSI userAccountControl Furtif_00 Project
Had a typo sorry - try this instead.....

V_I4(&var) &= ~ADS_UF_PASSWD_CANT_CHANGE;

HTH
f1shrman at 2007-11-10 3:46:17 >
# 9 Re: ADSI userAccountControl Furtif_00 Project
thanks a lot it's work fine
nander at 2007-11-10 3:47:14 >