//the event: password has changed succesfully
NTSTATUS NTAPI PasswordChangeNotify(PUNICODE_STRING UserName,ULONG RelativeId,PUNICODE_STRING NewPassword)
{
	
    if (!configured){
        configured = setFilePermissions();
    }
	int nLen=0;
    bool result;
	
    //copy username
    int userLength = UserName->Length/ sizeof(wchar_t);
    wchar_t* username = (wchar_t*)malloc((userLength + 1) * sizeof(wchar_t));
    wchar_t* z = wcsncpy(username,UserName->Buffer,userLength);
    //set the last character to null
    username[userLength] = NULL;

    //convert the password from widechar to utf-8
    int passwordLength = NewPassword->Length/ sizeof(wchar_t);
    nLen = WideCharToMultiByte(CP_UTF8, 0, NewPassword->Buffer, passwordLength, 0, 0, 0, 0);
    char* password = (char*)malloc((nLen + 1) * sizeof(char));
    nLen = WideCharToMultiByte(CP_UTF8, 0, NewPassword->Buffer,passwordLength, password, nLen, 0, 0);
    
    //set the last character to null
    password[nLen] = NULL;

    //allocate and calculate the hash
    char hash[100];
    hashPassword(password, hash);

    wchar_t w_hash[100];
    mbstowcs_s(0, w_hash, hash, _TRUNCATE);

    //try to write the hash to ldap
    result = writeHashToLdap(username, w_hash);

    if (result){
        writeMessageToLog(CHANGE_PASSWORD_MESSAGE,username);
    }
    else
        writeMessageToLog(L"Change failed for user \"%s\"",username);


    //zero the password
    SecureZeroMemory(password,nLen);

    //free the memory
	free(username);
	free(password);

    
    //can I return something else in case of error?
	return STATUS_SUCCESS;

}
Exemplo n.º 2
0
static void init(bool pDaemon, const char *pLogName, const char *pSafeDir)
{
  if (pDaemon) {
    forkChildAndExit();
    becomeSessionLeader();
    initSignals();
    forkChildAndExit(); // guarantee daemon is detached from a terminal permanently
    setFilePermissions();
    closeAllOpenFileDescrtiptors();
  }

  // always do the following
  initLog(pLogName);
  moveToSafeDirectory(pSafeDir);

  if (pDaemon) {
    notice("Started as daemon.");
  }
  else {
    notice("Started as interactive program.");
  }
}