Beispiel #1
0
bool COutFile::SetTime(const FILETIME *lpCreationTime,
  const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime)
{
  LARGE_INTEGER  ltime;
  DWORD dw;

  if (_fd == -1) {
     SetLastError( ERROR_INVALID_HANDLE );
     return false;
  }

  /* On some OS (cygwin, MacOSX ...), you must close the file before updating times */
  if (lpLastAccessTime) {
     ltime.QuadPart = lpLastAccessTime->dwHighDateTime;
     ltime.QuadPart = (ltime.QuadPart << 32) | lpLastAccessTime->dwLowDateTime;
     RtlTimeToSecondsSince1970( &ltime, &dw );
     _lastAccessTime = dw;
  }
  if (lpLastWriteTime) {
     ltime.QuadPart = lpLastWriteTime->dwHighDateTime;
     ltime.QuadPart = (ltime.QuadPart << 32) | lpLastWriteTime->dwLowDateTime;
     RtlTimeToSecondsSince1970( &ltime, &dw );
     _lastWriteTime = dw;
  }

  return true;
}
Beispiel #2
0
BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, WORD *fatdate, WORD *fattime ) {
  LARGE_INTEGER       li;
  ULONG               t;
  time_t              unixtime;
  struct tm*          tm;
  WORD fat_d,fat_t;

  TRACEN((printf("FileTimeToDosDateTime\n")))
  li.QuadPart = ft->dwHighDateTime;
  li.QuadPart = (li.QuadPart << 32) | ft->dwLowDateTime;
  RtlTimeToSecondsSince1970( &li, &t );
  unixtime = t; /* unixtime = t; * FIXME unixtime = t - TIME_GetBias(); */

  tm = gmtime( &unixtime );

  fat_t = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
  fat_d = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday;
  if (fattime)
    *fattime = fat_t;
  if (fatdate)
    *fatdate = fat_d;

  TRACEN((printf("FileTimeToDosDateTime : %lx %lx => %d %d\n",
	(long)ft->dwHighDateTime,(long)ft->dwLowDateTime,(unsigned)fat_d,(unsigned)fat_t)))

  return TRUE;
}
Beispiel #3
0
time_t
time_now(
    VOID
    )
/*++

Routine Description:

    This function returns the UTC time in seconds since 1970.

Arguments:

    None.

Return Value:

    None.

--*/
{

   LARGE_INTEGER Time;
   time_t CurrentTime;

   // Get the 64-bit system time.
   // Convert the system time to the number of seconds
   // since 1-1-1970.
   //

   NtQuerySystemTime(&Time);
   RtlTimeToSecondsSince1970(&Time, (PVOID) &CurrentTime);
   return(CurrentTime);

}
Beispiel #4
0
VOID
NetpFileTimeToSecondsSince1970(
    IN  LPFILETIME FileTime,
    OUT LPDWORD    SecondsSince1970     // Round UP if needed.
    )
{
    LARGE_INTEGER LargeInteger;

    NetpAssert( FileTime != NULL );
    NetpAssert( SecondsSince1970 != NULL );

    //
    // BUGBUG: This assumes that FILETIME and LARGE_INTEGER have same
    // precision.  Is this guaranteed?
    //

    NetpAssert( sizeof(LARGE_INTEGER) == sizeof(FILETIME) );
    LargeInteger.HighPart = FileTime->dwHighDateTime;

    LargeInteger.LowPart  = FileTime->dwLowDateTime;

    // Round LargeInteger UP to 1 second.
    NetpRoundUpLargeIntegerTimeToOneSecond( &LargeInteger );

    // Convert to seconds since 1970.
    NetpAssert( sizeof(DWORD) == sizeof(ULONG) );
    RtlTimeToSecondsSince1970(
            &LargeInteger,
            (PVOID) SecondsSince1970);

} // NetpFileTimeToSecondsSince1970
Beispiel #5
0
VOID
LogfReportEvent(USHORT wType,
                USHORT wCategory,
                ULONG  dwEventId,
                USHORT wNumStrings,
                PWSTR  pStrings,
                ULONG  dwDataSize,
                PVOID  pRawData)
{
    NTSTATUS Status;
    UNICODE_STRING SourceName, ComputerName;
    PEVENTLOGRECORD LogBuffer;
    LARGE_INTEGER SystemTime;
    ULONG Time;
    SIZE_T RecSize;
    DWORD dwComputerNameLength;
    WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];

    if (!EventLogSource)
        return;

    RtlInitUnicodeString(&SourceName, EventLogSource->szName);

    dwComputerNameLength = ARRAYSIZE(szComputerName);
    if (!GetComputerNameW(szComputerName, &dwComputerNameLength))
        szComputerName[0] = L'\0';

    RtlInitUnicodeString(&ComputerName, szComputerName);

    NtQuerySystemTime(&SystemTime);
    RtlTimeToSecondsSince1970(&SystemTime, &Time);

    LogBuffer = LogfAllocAndBuildNewRecord(&RecSize,
                                           Time,
                                           wType,
                                           wCategory,
                                           dwEventId,
                                           &SourceName,
                                           &ComputerName,
                                           0,
                                           NULL,
                                           wNumStrings,
                                           pStrings,
                                           dwDataSize,
                                           pRawData);
    if (LogBuffer == NULL)
    {
        DPRINT1("LogfAllocAndBuildNewRecord failed!\n");
        return;
    }

    Status = LogfWriteRecord(EventLogSource->LogFile, LogBuffer, RecSize);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("ERROR writing to event log `%S' (Status 0x%08lx)\n",
                EventLogSource->LogFile->LogName, Status);
    }

    LogfFreeRecord(LogBuffer);
}
Beispiel #6
0
bool create_bad_block_inode( PEXT2_FILESYS Ext2Sys,
                             PEXT2_BADBLK_LIST bb_list)
{
    bool            retval;
    EXT2_INODE      inode;
    LARGE_INTEGER   SysTime;
    
    NtQuerySystemTime(&SysTime);

    ext2_mark_inode_bitmap(Ext2Sys->inode_map, EXT2_BAD_INO);

    Ext2Sys->group_desc[0].bg_free_inodes_count--;
    Ext2Sys->ext2_sb->s_free_inodes_count--;

    memset(&inode, 0, sizeof(EXT2_INODE));
    inode.i_mode = (USHORT)((0777 & ~Ext2Sys->umask));
    inode.i_uid = inode.i_gid = 0;
    inode.i_blocks = 0;
    inode.i_block[0] = 0;
    inode.i_links_count = 2;
    RtlTimeToSecondsSince1970(&SysTime, &inode.i_mtime);
    inode.i_ctime = inode.i_atime = inode.i_mtime;
    inode.i_size = 0;

    retval = ext2_save_inode(Ext2Sys, EXT2_BAD_INO, &inode);

    return retval;
}
Beispiel #7
0
/***********************************************************************
 *           FileTimeToDosDateTime   (KERNEL32.@)
 */
BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
                                     LPWORD fattime )
{
    LARGE_INTEGER       li;
    ULONG               t;
    time_t              unixtime;
    struct tm*          tm;

    if (!fatdate || !fattime)
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }
    li.u.LowPart = ft->dwLowDateTime;
    li.u.HighPart = ft->dwHighDateTime;
    if (!RtlTimeToSecondsSince1970( &li, &t ))
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }
    unixtime = t;
    tm = gmtime( &unixtime );
    if (fattime)
        *fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
    if (fatdate)
        *fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5)
                   + tm->tm_mday;
    return TRUE;
}
Beispiel #8
0
/* INTERNAL: Translate WIN32_FIND_DATAW to wfinddata32_t  */
static void msvcrt_wfttofd32(const WIN32_FIND_DATAW *fd, struct MSVCRT__wfinddata32_t* ft)
{
  DWORD dw;

  if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
    ft->attrib = 0;
  else
    ft->attrib = fd->dwFileAttributes;

  RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
  ft->time_create = dw;
  RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
  ft->time_access = dw;
  RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
  ft->time_write = dw;
  ft->size = fd->nFileSizeLow;
  strcpyW(ft->name, fd->cFileName);
}
ULONG GetCurrentTime()
{
	LARGE_INTEGER currentSystemTime;
	LARGE_INTEGER currentLocalTime;
	ULONG time;

	KeQuerySystemTime(&currentSystemTime);
	ExSystemTimeToLocalTime(&currentSystemTime,&currentLocalTime);
	RtlTimeToSecondsSince1970(&currentLocalTime, &time);
	return time;
}
bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds)
{
#ifdef _WIN32
  s[0] = '\0';
  SYSTEMTIME st;
  if (!BOOLToBool(FileTimeToSystemTime(&ft, &st)))
    return false;
  s = UIntToStringSpec(0, st.wYear, s, 4);
  s = UIntToStringSpec('-', st.wMonth, s, 2);
  s = UIntToStringSpec('-', st.wDay, s, 2);
  if (includeTime)
  {
    s = UIntToStringSpec(' ', st.wHour, s, 2);
    s = UIntToStringSpec(':', st.wMinute, s, 2);
    if (includeSeconds)
      UIntToStringSpec(':', st.wSecond, s, 2);
  }
  /*
  sprintf(s, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);
  if (includeTime)
  {
    sprintf(s + strlen(s), " %02d:%02d", st.wHour, st.wMinute);
    if (includeSeconds)
      sprintf(s + strlen(s), ":%02d", st.wSecond);
  }
  */
#else
  BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *Time, DWORD *Seconds );

  FILETIME filetime;
  LocalFileTimeToFileTime(&ft, &filetime);

  LARGE_INTEGER  ltime;

  ltime.QuadPart = filetime.dwHighDateTime;
  ltime.QuadPart = (ltime.QuadPart << 32) | filetime.dwLowDateTime;

  DWORD dw;
  RtlTimeToSecondsSince1970(&ltime, &dw );
  time_t timep = (time_t)dw;

  struct tm * date = localtime(&timep);

  sprintf(s, "%04d-%02d-%02d", date->tm_year+1900, date->tm_mon+1,date->tm_mday);
  if (includeTime)
  {
    sprintf(s + strlen(s), " %02d:%02d", date->tm_hour,date->tm_min);
    if (includeSeconds)
      sprintf(s + strlen(s), ":%02d", date->tm_sec);
  }
#endif
  return true;
}
Beispiel #11
0
NET_API_STATUS
NetpSystemTimeToGmtTime(
    IN LPSYSTEMTIME WinSplitTime,
    OUT LPDWORD GmtTime         // seconds since 1970 (GMT).
    )
{
    TIME_FIELDS NtSplitTime;
    LARGE_INTEGER NtPreciseTime;

    if ( (WinSplitTime==NULL) || (GmtTime==NULL) ) {
        return (ERROR_INVALID_PARAMETER);
    }

    NtSplitTime.Year         = (CSHORT) WinSplitTime->wYear;
    NtSplitTime.Month        = (CSHORT) WinSplitTime->wMonth;
    NtSplitTime.Day          = (CSHORT) WinSplitTime->wDay;
    NtSplitTime.Hour         = (CSHORT) WinSplitTime->wHour;
    NtSplitTime.Minute       = (CSHORT) WinSplitTime->wMinute;
    NtSplitTime.Second       = (CSHORT) WinSplitTime->wSecond;
    NtSplitTime.Milliseconds = (CSHORT) WinSplitTime->wMilliseconds;
    NtSplitTime.Weekday      = (CSHORT) WinSplitTime->wDayOfWeek;

    if ( !RtlTimeFieldsToTime (
            & NtSplitTime,    // input
            & NtPreciseTime   // output
            ) ) {

        NetpKdPrint(( PREFIX_NETLIB
                "NetpSystemTimeToGmtTime: RtlTimeFieldsToTime failed.\n" ));

        // BUGBUG: Better error code?  Log this?
        return (NERR_InternalError);
    }

    if ( !RtlTimeToSecondsSince1970 (
            & NtPreciseTime,   // input
            (PULONG) GmtTime ) ) {

        NetpKdPrint(( PREFIX_NETLIB
                "NetpSystemTimeToGmtTime: "
                "RtlTimeToSecondsSince1970 failed.\n" ));

        // BUGBUG: Better error code?  Log this?
        return (NERR_InternalError);
    }

    return (NO_ERROR);

} // NetpSystemTimeToGmtTime
Beispiel #12
0
/***********************************************************************
 *        NtSetSystemTime [NTDLL.@]
 *        ZwSetSystemTime [NTDLL.@]
 *
 * Set the system time.
 *
 * PARAMS
 *   NewTime [I] The time to set.
 *   OldTime [O] Optional destination for the previous system time.
 *
 * RETURNS
 *   Success: STATUS_SUCCESS.
 *   Failure: An NTSTATUS error code indicating the problem.
 */
NTSTATUS WINAPI NtSetSystemTime(const LARGE_INTEGER *NewTime, LARGE_INTEGER *OldTime)
{
    struct timeval tv;
    time_t tm_t;
    DWORD sec, oldsec;
    LARGE_INTEGER tm;

    /* Return the old time if necessary */
    if (!OldTime) OldTime = &tm;

    NtQuerySystemTime( OldTime );
    RtlTimeToSecondsSince1970( OldTime, &oldsec );

    RtlTimeToSecondsSince1970( NewTime, &sec );

    /* set the new time */
    tv.tv_sec = sec;
    tv.tv_usec = 0;

#ifdef HAVE_SETTIMEOFDAY
    if (!settimeofday(&tv, NULL)) /* 0 is OK, -1 is error */
        return STATUS_SUCCESS;
    tm_t = sec;
    ERR("Cannot set time to %s, time adjustment %ld: %s\n",
        ctime(&tm_t), (long)(sec-oldsec), strerror(errno));
    if (errno == EPERM)
        return STATUS_PRIVILEGE_NOT_HELD;
    else
        return STATUS_INVALID_PARAMETER;
#else
    tm_t = sec;
    FIXME("setting time to %s not implemented for missing settimeofday\n",
        ctime(&tm_t));
    return STATUS_NOT_IMPLEMENTED;
#endif
}
Beispiel #13
0
static
DWORD
GetTimeInSeconds(VOID)
{
    LARGE_INTEGER Time;
    FILETIME FileTime;
    DWORD dwSeconds;

    GetSystemTimeAsFileTime(&FileTime);
    Time.u.LowPart = FileTime.dwLowDateTime;
    Time.u.HighPart = FileTime.dwHighDateTime;
    RtlTimeToSecondsSince1970(&Time, &dwSeconds);

    return dwSeconds;
}
Beispiel #14
0
BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, WORD *fatdate, WORD *fattime ) {
  LARGE_INTEGER       li;
  ULONG               t;
  time_t              unixtime;
  struct tm*          tm;

  TRACEN((printf("FileTimeToDosDateTime\n")))
  li.QuadPart = ft->dwHighDateTime;
  li.QuadPart = (li.QuadPart << 32) | ft->dwLowDateTime;
  RtlTimeToSecondsSince1970( &li, &t );
  unixtime = t;
  tm = gmtime( &unixtime );
  if (fattime)
    *fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
  if (fatdate)
    *fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday;
  return TRUE;
}
Beispiel #15
0
/***********************************************************************
 *           FileTimeToDosDateTime   (KERNEL32.@)
 */
BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
                                     LPWORD fattime )
{
    LARGE_INTEGER       li;
    ULONG               t;
    time_t              unixtime;
    struct tm*          tm;

    li.u.LowPart = ft->dwLowDateTime;
    li.u.HighPart = ft->dwHighDateTime;
    RtlTimeToSecondsSince1970( &li, &t );
    unixtime = t;
    tm = gmtime( &unixtime );
    if (fattime)
        *fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
    if (fatdate)
        *fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5)
                   + tm->tm_mday;
    return TRUE;
}
Beispiel #16
0
NTSTATUS
LogfWriteRecord(PLOGFILE LogFile,
                PEVENTLOGRECORD Record,
                SIZE_T BufSize)
{
    NTSTATUS Status;
    LARGE_INTEGER SystemTime;

    // ASSERT(sizeof(*Record) == sizeof(RecBuf));

    if (!Record || BufSize < sizeof(*Record))
        return STATUS_INVALID_PARAMETER;

    /* Lock the log file exclusive */
    RtlAcquireResourceExclusive(&LogFile->Lock, TRUE);

    /*
     * Retrieve the record written time now, that will also be compared
     * with the existing events timestamps in case the log is wrapping.
     */
    NtQuerySystemTime(&SystemTime);
    RtlTimeToSecondsSince1970(&SystemTime, &Record->TimeWritten);

    Status = ElfWriteRecord(&LogFile->LogFile, Record, BufSize);
    if (Status == STATUS_LOG_FILE_FULL)
    {
        /* The event log file is full, queue a message box for the user and exit */
        // TODO!
        DPRINT1("Log file `%S' is full!\n", LogFile->LogName);
    }

    /* Unlock the log file */
    RtlReleaseResource(&LogFile->Lock);

    return Status;
}
Beispiel #17
0
NTSTATUS
NlCheckAuthenticator(
    IN OUT PSERVER_SESSION ServerSession,
    IN PNETLOGON_AUTHENTICATOR Authenticator,
    OUT PNETLOGON_AUTHENTICATOR ReturnAuthenticator
    )
/*++

Routine Description:

    Verify that supplied Authenticator is valid.
    It is intended for use by the server side after initial authentication
    has succeeded. This routine will modify the seed by
    first adding the time-of-day received from the Authenticator
    and then by incrementing it.

    A ReturnAuthenticator is built based on the final seed.

Arguments:

    ServerSession - Pointer to the ServerSession structure.  The following
        fields are used:

        SsAuthenticationSeed - Supplies the seed used for authentication and
            returns the updated seed.

        SsSessionKey - The session key used for encryption.

        SsCheck - Is zeroed to indicate successful communication with the client.

    Authenticator - The authenticator passed by the caller.

    ReturnAuthenticator - The authenticator we'll return to the caller.

Return Value:

    STATUS_SUCCESS;
    STATUS_ACCESS_DENIED;
    STATUS_TIME_DIFFERENCE_AT_DC;

--*/
{

    NETLOGON_CREDENTIAL TargetCredential;


#ifdef notdef   // Doesn't work if caller in different time zone

    LARGE_INTEGER TimeNow;
    long timeofday;
    long timediff;

    //
    // First check if time-of-day is rational.
    //

    NtQuerySystemTime( &TimeNow );
    RtlTimeToSecondsSince1970( &TimeNow, &timeofday );

    timediff = timeofday - Authenticator->timestamp;
    if (timediff < 0) {
        timediff = Authenticator->timestamp - timeofday;
    }

    if (timediff > RATIONAL_TIME) {
        return STATUS_TIME_DIFFERENCE_AT_DC;
    }
#endif // notdef


#ifdef BAD_ALIGNMENT
    NlPrint((NL_CHALLENGE_RES,"NlCheckAuthenticator: Seed = %lx %lx\n",
            ((DWORD *) (&ServerSession->SsAuthenticationSeed))[0],
            ((DWORD *) (&ServerSession->SsAuthenticationSeed))[1]));


    NlPrint((NL_CHALLENGE_RES,
            "NlCheckAuthenticator: SessionKey = %lx %lx %lx %lx\n",
                    ((DWORD *) (&ServerSession->SsSessionKey))[0],
                    ((DWORD *) (&ServerSession->SsSessionKey))[1],
                    ((DWORD *) (&ServerSession->SsSessionKey))[2],
                    ((DWORD *) (&ServerSession->SsSessionKey))[3]));

    NlPrint((NL_CHALLENGE_RES,
            "NlCheckAuthenticator: Client Authenticator GOT  = %lx %lx\n",
                    ((DWORD *) (&Authenticator->Credential))[0],
                    ((DWORD *) (&Authenticator->Credential))[1]));

    NlPrint((NL_CHALLENGE_RES,
            "NlCheckAuthenticator: Time = %lx\n",
                    ((DWORD *) (&Authenticator->timestamp))[0] ));
#endif // BAD_ALIGNMENT



    //
    // modify the seed before computing auth_credential for verification
    // Two long words are added and overflow carry (if any) ignored
    // This will leave upper 4 bytes unchanged
    //

    *((unsigned long * ) &ServerSession->SsAuthenticationSeed) += Authenticator->timestamp;


#ifdef BAD_ALIGNMENT
    NlPrint((NL_CHALLENGE_RES,
            "NlCheckAuthenticator: Seed + TIME = %lx %lx\n",
            ((DWORD *) (&ServerSession->SsAuthenticationSeed))[0],
            ((DWORD *) (&ServerSession->SsAuthenticationSeed))[1]));
#endif // BAD_ALIGNMENT


    //
    // Compute TargetCredential to verify the one supplied in the Authenticator
    //

    NlComputeCredentials( &ServerSession->SsAuthenticationSeed,
                          &TargetCredential,
                          &ServerSession->SsSessionKey );


#ifdef BAD_ALIGNMENT
    NlPrint((NL_CHALLENGE_RES,
            "NlCheckAuthenticator: Client Authenticator MADE = %lx %lx\n",
                    ((DWORD *) (&TargetCredential))[0],
                    ((DWORD *) (&TargetCredential))[1]));
#endif // BAD_ALIGNMENT

    //
    // verify the computed credentials with those supplied
    // Authenticator must have used seed + time_of_day as seed
    //

    if (RtlCompareMemory( &Authenticator->Credential,
                          &TargetCredential,
                          sizeof(TargetCredential)) !=
                          sizeof(TargetCredential)) {
        return STATUS_ACCESS_DENIED;
    }

    //
    // modify our seed before computing the ReturnAuthenticator.
    // The requestor will increment his seed if he matches this credentials.
    //

    (*((unsigned long * ) &ServerSession->SsAuthenticationSeed))++;

    //
    // compute ClientCredential to send back to requestor
    //

    NlComputeCredentials( &ServerSession->SsAuthenticationSeed,
                          &ReturnAuthenticator->Credential,
                          &ServerSession->SsSessionKey);


#ifdef BAD_ALIGNMENT
    NlPrint((NL_CHALLENGE_RES,
            "NlCheckAuthenticator: Server Authenticator SEND = %lx %lx\n",
                    ((DWORD *) (&ReturnAuthenticator->Credential))[0],
                    ((DWORD *) (&ReturnAuthenticator->Credential))[1]));


    NlPrint((NL_CHALLENGE_RES,
            "NlCheckAuthenticator: Seed + time + 1= %lx %lx\n",
            ((DWORD *) (&ServerSession->SsAuthenticationSeed))[0],
            ((DWORD *) (&ServerSession->SsAuthenticationSeed))[1]));
#endif // BAD_ALIGNMENT


    //
    // Indicate successful communication with the client
    //

    ServerSession->SsCheck = 0;
    ServerSession->SsPulseTimeoutCount = 0;
    ServerSession->SsFlags &= ~SS_PULSE_SENT;

    return STATUS_SUCCESS;

}
Beispiel #18
0
VOID
NlBuildAuthenticator(
    IN OUT PNETLOGON_CREDENTIAL AuthenticationSeed,
    IN PNETLOGON_SESSION_KEY SessionKey,
    OUT PNETLOGON_AUTHENTICATOR Authenticator
    )
/*++

Routine Description:

    Build the authenticator to be sent to primary.
    This routine will modify the seed by adding the
    time-of-day before computing the credentials.

Arguments:

    AuthenticationSeed -- The current authentication seed.  This seed will
        have the current time of day added to it prior to building the
        Authenticator.

    SessionKey - The Session Key used for encrypting the Authenticator.

    Authenticator - The Authenticator to pass to the PDC for the current
        call.

Return Value:

    NT Status code

--*/
{
    NTSTATUS Status;
    LARGE_INTEGER TimeNow;

    //
    // Use the current time of day to modify the authentication seed
    //

    RtlZeroMemory(Authenticator, sizeof(*Authenticator));

    Status = NtQuerySystemTime( &TimeNow );
    NlAssert( NT_SUCCESS(Status) );

    Status = RtlTimeToSecondsSince1970( &TimeNow, &Authenticator->timestamp );
    NlAssert( NT_SUCCESS(Status) );

    //
    // Modify the AuthenticationSeed before computing auth_credential for
    // verification .
    //
    // Two long words are added and overflow carry (if any) ignored
    // This will leave upper 4 bytes unchanged
    //


#ifdef BAD_ALIGNMENT
    NlPrint((NL_CHALLENGE_RES,"NlBuildAuthenticator: Old Seed = %lx %lx\n",
                    ((DWORD *) (AuthenticationSeed))[0],
                    ((DWORD *) (AuthenticationSeed))[1]));

    NlPrint((NL_CHALLENGE_RES,"NlBuildAuthenticator: Time = %lx\n",
                    ((DWORD *) (&Authenticator->timestamp))[0] ));
#endif // BAD_ALIGNMENT



    *((unsigned long * ) AuthenticationSeed) += Authenticator->timestamp;


#ifdef BAD_ALIGNMENT
    NlPrint((NL_CHALLENGE_RES,"NlBuildAuthenticator: New Seed = %lx %lx\n",
                    ((DWORD *) (AuthenticationSeed))[0],
                    ((DWORD *) (AuthenticationSeed))[1]));


    NlPrint((NL_CHALLENGE_RES,
            "NlBuildAuthenticator: SessionKey = %lx %lx %lx %lx\n",
                    ((DWORD *) (SessionKey))[0],
                    ((DWORD *) (SessionKey))[1],
                    ((DWORD *) (SessionKey))[2],
                    ((DWORD *) (SessionKey))[3]));
#endif // BAD_ALIGNMENT


    //
    // compute AuthenticationSeed to verify the one supplied by Requestor
    //

    NlComputeCredentials( AuthenticationSeed,
                               &Authenticator->Credential,
                               SessionKey);


#ifdef BAD_ALIGNMENT
    NlPrint((NL_CHALLENGE_RES,"NlBuildAuthenticator: Client Authenticator = %lx %lx\n",
                    ((DWORD *) (&Authenticator->Credential))[0],
                    ((DWORD *) (&Authenticator->Credential))[1]));
#endif // BAD_ALIGNMENT


    return;

}
Beispiel #19
0
/* Function 28 */
NET_API_STATUS
__stdcall
NetrRemoteTOD(
    SRVSVC_HANDLE ServerName,
    LPTIME_OF_DAY_INFO *BufferPtr)
{
    SYSTEMTIME SystemTime;
    LARGE_INTEGER Time;
    TIME_ZONE_INFORMATION TimeZoneInfo;
    DWORD TimeZoneId;
    LPTIME_OF_DAY_INFO lpTod;

    TRACE("NetrRemoteTOD(%p %p)\n", ServerName, BufferPtr);

    *BufferPtr = midl_user_allocate(sizeof(TIME_OF_DAY_INFO));
    if (*BufferPtr == NULL)
        return ERROR_NOT_ENOUGH_MEMORY;

    lpTod = *BufferPtr;

    /* Set the seconds since 1970 */
    NtQuerySystemTime(&Time);
    RtlTimeToSecondsSince1970(&Time,
                              &lpTod->tod_elapsedt);

    /* Set the tick count */
    lpTod->tod_msecs = GetTickCount();

    /* Set the timezone */
    TimeZoneId = GetTimeZoneInformation(&TimeZoneInfo);

    switch (TimeZoneId)
    {
        case TIME_ZONE_ID_UNKNOWN:
            lpTod->tod_timezone = TimeZoneInfo.Bias;
            break;

        case TIME_ZONE_ID_STANDARD:
            lpTod->tod_timezone = TimeZoneInfo.Bias + TimeZoneInfo.StandardBias;
            break;

        case TIME_ZONE_ID_DAYLIGHT:
            lpTod->tod_timezone = TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias;
            break;

        default:
            lpTod->tod_timezone = 0;
    }

    /* Set the ??? */
    lpTod->tod_tinterval = 310;

    /* Set the date and time */
    GetSystemTime(&SystemTime);
    lpTod->tod_hours = SystemTime.wHour;
    lpTod->tod_mins = SystemTime.wMinute;
    lpTod->tod_secs = SystemTime.wSecond;
    lpTod->tod_hunds = SystemTime.wMilliseconds / 10;
    lpTod->tod_day = SystemTime.wDay;
    lpTod->tod_month = SystemTime.wMonth;
    lpTod->tod_year = SystemTime.wYear;
    lpTod->tod_weekday = SystemTime.wDayOfWeek;

    return NERR_Success;
}
Beispiel #20
0
int
main(
    int argc,
    char *argv[]
    )
{
    ULONG i;

    //
    //  We're starting the test
    //

    DbgPrint("Start Time Test\n");

    //
    //  Start by initializing some constants and making sure they
    //  are correct
    //

    Zero.QuadPart = 0;
    OneSecond.QuadPart = 10000000;
    OneMinute.QuadPart = OneSecond.QuadPart * 60;
    OneHour.QuadPart = OneMinute.QuadPart * 60;
    OneDay.QuadPart = OneHour.QuadPart * 24;
    OneWeek.QuadPart = OneDay.QuadPart * 7;
    OneNormalYear.QuadPart = OneDay.QuadPart * 365;
    OneLeapYear.QuadPart = OneDay.QuadPart * 366;
    OneCentury.QuadPart =  (OneNormalYear.QuadPart * 76) + (OneLeapYear.QuadPart * 24);
    TwoCenturies.QuadPart = OneCentury.QuadPart * 2;
    ThreeCenturies.QuadPart = OneCentury.QuadPart * 3;
    FourCenturies.QuadPart = (OneCentury.QuadPart * 4) + OneDay.QuadPart;

    Sum.QuadPart   = Zero.QuadPart +
                     OneSecond.QuadPart +
                     OneMinute.QuadPart +
                     OneHour.QuadPart +
                     OneDay.QuadPart +
                     OneWeek.QuadPart +
                     OneNormalYear.QuadPart +
                     ThreeCenturies.QuadPart;


    RtlTimeToTimeFields( (PLARGE_INTEGER)&Zero, &TimeFields );
    DbgPrint("StartOf1601     = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to Zero\n");
    }
    if ((Time.LowPart != Zero.LowPart) || (Time.HighPart != Zero.HighPart)) {
        DbgPrint("****ERROR Time != Zero\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&OneSecond, &TimeFields );
    DbgPrint(" + 1 Second     = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to OneSecond\n");
    }
    if ((Time.LowPart != OneSecond.LowPart) || (Time.HighPart != OneSecond.HighPart)) {
        DbgPrint("****ERROR Time != OneSecond\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&OneMinute, &TimeFields );
    DbgPrint(" + 1 Minute     = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to OneMinute\n");
    }
    if ((Time.LowPart != OneMinute.LowPart) || (Time.HighPart != OneMinute.HighPart)) {
        DbgPrint("****ERROR Time != OneMinute\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&OneHour, &TimeFields );
    DbgPrint(" + 1 Hour       = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to OneHour\n");
    }
    if ((Time.LowPart != OneHour.LowPart) || (Time.HighPart != OneHour.HighPart)) {
        DbgPrint("****ERROR Time != OneHour\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&OneDay, &TimeFields );
    DbgPrint(" + 1 Day        = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to OneDay\n");
    }
    if ((Time.LowPart != OneDay.LowPart) || (Time.HighPart != OneDay.HighPart)) {
        DbgPrint("****ERROR Time != OneDay\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&OneWeek, &TimeFields );
    DbgPrint(" + 1 Week       = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to OneWeek\n");
    }
    if ((Time.LowPart != OneWeek.LowPart) || (Time.HighPart != OneWeek.HighPart)) {
        DbgPrint("****ERROR Time != OneWeek\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&OneNormalYear, &TimeFields );
    DbgPrint(" + 1 NormalYear = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to OneNormalYear\n");
    }
    if ((Time.LowPart != OneNormalYear.LowPart) || (Time.HighPart != OneNormalYear.HighPart)) {
        DbgPrint("****ERROR Time != OneNormalYear\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&OneLeapYear, &TimeFields );
    DbgPrint(" + 1 LeapYear   = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to OneLeapYear\n");
    }
    if ((Time.LowPart != OneLeapYear.LowPart) || (Time.HighPart != OneLeapYear.HighPart)) {
        DbgPrint("****ERROR Time != OneLeapYear\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&OneCentury, &TimeFields );
    DbgPrint(" + 1 Century    = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to OneCentury\n");
    }
    if ((Time.LowPart != OneCentury.LowPart) || (Time.HighPart != OneCentury.HighPart)) {
        DbgPrint("****ERROR Time != OneCentury\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&TwoCenturies, &TimeFields );
    DbgPrint(" + 2 Centuries  = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to TwoCenturies\n");
    }
    if ((Time.LowPart != TwoCenturies.LowPart) || (Time.HighPart != TwoCenturies.HighPart)) {
        DbgPrint("****ERROR Time != TwoCenturies\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&ThreeCenturies, &TimeFields );
    DbgPrint(" + 3 Centuries  = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to ThreeCenturies\n");
    }
    if ((Time.LowPart != ThreeCenturies.LowPart) || (Time.HighPart != ThreeCenturies.HighPart)) {
        DbgPrint("****ERROR Time != ThreeCenturies\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&FourCenturies, &TimeFields );
    DbgPrint(" + 4 Centuries  = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to FourCenturies\n");
    }
    if ((Time.LowPart != FourCenturies.LowPart) || (Time.HighPart != FourCenturies.HighPart)) {
        DbgPrint("****ERROR Time != FourCenturies\n");
    }

    RtlTimeToTimeFields( (PLARGE_INTEGER)&Sum, &TimeFields );
    DbgPrint(" + sum          = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to Sum\n");
    }
    if ((Time.LowPart != Sum.LowPart) || (Time.HighPart != Sum.HighPart)) {
        DbgPrint("****ERROR Time != Sum\n");
    }

    DbgPrint("\n");

    //
    //  Setup and test the start 1970 time
    //

    RtlSecondsSince1970ToTime( 0, &StartOf1970 );
    RtlTimeToTimeFields( &StartOf1970, &TimeFields );
    DbgPrint(" Start of 1970  = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to start of 1970\n");
    }
    if ((Time.LowPart != StartOf1970.LowPart) || (Time.HighPart != StartOf1970.HighPart)) {
        DbgPrint("****ERROR Time != StartOf1970\n");
    }
    if (!RtlTimeToSecondsSince1970( &StartOf1970, &i )) {
        DbgPrint("****ERROR converting time to seconds since 1970\n");
    }
    if (i != 0) {
        DbgPrint("****ERROR seconds since 1970 != 0\n");
    }

    //
    //  Setup and test the start 1980 time
    //

    RtlSecondsSince1980ToTime( 0, &StartOf1980 );
    RtlTimeToTimeFields( &StartOf1980, &TimeFields );
    DbgPrint(" Start of 1980  = "); PrintTimeFields( &TimeFields ); DbgPrint("\n");
    if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
        DbgPrint("****ERROR converting TimeFields back to start of 1980\n");
    }
    if ((Time.LowPart != StartOf1980.LowPart) || (Time.HighPart != StartOf1980.HighPart)) {
        DbgPrint("****ERROR Time != StartOf1980\n");
    }
    if (!RtlTimeToSecondsSince1980( &StartOf1980, &i )) {
        DbgPrint("****ERROR converting time to seconds since 1980\n");
    }
    if (i != 0) {
        DbgPrint("****ERROR seconds since 1980 != 0\n");
    }

    //
    //  Lets try to print the Christmas when Santa arrives for 1901 to 2001
    //  every 10 years
    //

    TimeFields.Month = 12;
    TimeFields.Day = 25;
    TimeFields.Hour = 3;
    TimeFields.Minute = 30;
    TimeFields.Second = 15;
    TimeFields.Milliseconds = 250;

    for (i = 1901; i < 2002; i += 10) {

        TimeFields.Year = i;

        if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
            DbgPrint("****ERROR converting TimeFields to Christmas %4d\n", TimeFields.Year);
        }
        RtlTimeToTimeFields( &Time, &TimeFields );
        DbgPrint(" Christmas %4d = ", i); PrintTimeFields( &TimeFields ); DbgPrint("\n");

    }

    //
    //  Let's see how old I really am, when I turn 10, 20, 30, ...
    //

    TimeFields.Month = 12;
    TimeFields.Day = 5;
    TimeFields.Hour = 3;
    TimeFields.Minute = 14;
    TimeFields.Second = 0;
    TimeFields.Milliseconds = 0;

    for (i = 1956; i <= 1956+60; i += 10) {

        TimeFields.Year = i;

        if (!RtlTimeFieldsToTime( &TimeFields, &Time )) {
            DbgPrint("****ERROR converting TimeFields to DOB %4d\n", TimeFields.Year);
        }
        RtlTimeToTimeFields( &Time, &TimeFields );
        DbgPrint(" DOB + %4d = ", i-1956); PrintTimeFields( &TimeFields ); DbgPrint("\n");

    }

    DbgPrint("End Time Test\n");

    return TRUE;
}
Beispiel #21
0
NTSTATUS
timesvc_RemoteTimeOfDay(
    OUT LPTIME_OF_DAY_INFO  *lpTimeOfDayInfo
    )

/*++

Routine Description:

    This routine calls the Win32 and NT base timer APIs to get the
    relevant time/date information. It also calls the Rtl routine to
    convert the time elapsed since 1-1-1970.

    The routine allocates a buffer to contain the time of day information
    and returns a pointer to that buffer to the caller.

Arguments:

    lpTimeOfDayInfo        - Location of where to place pointer to buffer.

Return Value:

    NTSTATUS - STATUS_SUCCESS or reason for failure.

--*/

{
    SYSTEMTIME SystemTime;
    LARGE_INTEGER Time;
    DWORD TickCount;
    LPTIME_OF_DAY_INFO        lpTimeOfDay;
    LONG LocalTimeZoneOffsetSecs;  // offset (+ for West of GMT, etc).

    if (lpTimeOfDayInfo == NULL) {
        return (STATUS_INVALID_PARAMETER);
    }

    //
    // Call the appropriate routines to collect the time information
    //

    GetSystemTime(&SystemTime);

    //
    // Get number of seconds from UTC.  Positive values for west of Greenwich,
    // negative values for east of Greenwich.
    //
    LocalTimeZoneOffsetSecs = NetpLocalTimeZoneOffset();

    //
    // Allocate a TimeOfDay_INFO structure that is to be returned to the
    // caller and fill it with the relevant data.
    //

    *lpTimeOfDayInfo = (TIME_OF_DAY_INFO *) MIDL_user_allocate(
                            sizeof (struct _TIME_OF_DAY_INFO)
                            );

    if (*lpTimeOfDayInfo == NULL) {
        SS_PRINT((
                "SRVSVC: timesvc_RemoteTimeOfDay"
                "got NULL from MIDL_user_allocate!\n" ));
        return(STATUS_NO_MEMORY);
    }

    lpTimeOfDay = (LPTIME_OF_DAY_INFO)(*lpTimeOfDayInfo);

    lpTimeOfDay->tod_hours         = SystemTime.wHour;
    lpTimeOfDay->tod_mins         = SystemTime.wMinute;
    lpTimeOfDay->tod_secs         = SystemTime.wSecond;
    lpTimeOfDay->tod_hunds         = SystemTime.wMilliseconds/10;
    lpTimeOfDay->tod_tinterval = TOD_DEFAULT_INTERVAL;
    lpTimeOfDay->tod_day         = SystemTime.wDay;
    lpTimeOfDay->tod_month         = SystemTime.wMonth;
    lpTimeOfDay->tod_year         = SystemTime.wYear;
    lpTimeOfDay->tod_weekday         = SystemTime.wDayOfWeek;

    // tod_timezone is + for west of GMT, - for east of it.
    // tod_timezone is in minutes.
    lpTimeOfDay->tod_timezone    = LocalTimeZoneOffsetSecs / 60;

    // Get the 64-bit system time.
    // Convert the system time to the number of miliseconds
    // since 1-1-1970.
    //

    NtQuerySystemTime(&Time);
    RtlTimeToSecondsSince1970(&Time,
                              &(lpTimeOfDay->tod_elapsedt)
                             );

    // Get the free running counter value
    //
    TickCount = GetTickCount();
    lpTimeOfDay->tod_msecs = TickCount;

    return(STATUS_SUCCESS);

} // timesvc_RemoteTimeOfDay
Beispiel #22
0
VOID RplAlertRaise( IN DWORD ErrorCode)
/*++

Routine Description:

    Sends an ADMIN alert. The input is a LanManager error message.

    This is a combination of the original Send_alert() routine &&
    RaiseAlert() routine from logonsrv\server\error.c

Arguments:
    ErrorCode - the alert to be raised, text in alertmsg.h

Return Value:
    None.

Notes:
    Failing to post an alert is considered unimportant.  This is why this
    function is VOID.

--*/
{
    char        message[ ALERTSZ + sizeof(STD_ALERT) + sizeof(ADMIN_OTHER_INFO)];
    PSTD_ALERT          alert = (PSTD_ALERT)message;
    PADMIN_OTHER_INFO   other = (PADMIN_OTHER_INFO)ALERT_OTHER_INFO( alert);
    LARGE_INTEGER       time;
    HANDLE              fileHandle;
    DWORD               inBytes;
    DWORD               outBytes;

    NtQuerySystemTime( &time);
    RtlTimeToSecondsSince1970( &time, &alert->alrt_timestamp );

    //  Original code used alrt_servicename == SERVICE_SERVER
    wcscpy( alert->alrt_servicename, SERVICE_RIPL);
    wcscpy( alert->alrt_eventname, ALERT_ADMIN_EVENT );

    other->alrtad_errcode = ErrorCode;
    other->alrtad_numstrings = 0;


    //  NetAlertRaise() is gone, must use mailslots instead.  So, first
    //  open the Alerter mailslot to write to it.

    fileHandle = CreateFile(
            ALERTER_MAILSLOT,
            GENERIC_WRITE,
            FILE_SHARE_WRITE | FILE_SHARE_READ,
            (LPSECURITY_ATTRIBUTES) NULL,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            NULL);
    if ( fileHandle == INVALID_HANDLE_VALUE) {
        RplDump( RG_DebugLevel & RPL_DEBUG_MISC,(
            "AlertRaise: Error opening alerter mailslot, error=%d",
            GetLastError()));
        return;
    }

    inBytes = min( sizeof( message),
                   (DWORD)( (PCHAR)ALERT_VAR_DATA(other) - (PCHAR)message));

    // Write alert notification to mailslot to be read by Alerter service
    if ( !WriteFile(
                    fileHandle,
                    message,
                    inBytes,
                    &outBytes,
                    NULL)       ||      inBytes != outBytes) {

        RplDump( RG_DebugLevel & RPL_DEBUG_MISC,(
            "AlertRaise: Error writing to alerter mailslot %d",
            GetLastError()));

    } else if ( ! CloseHandle( fileHandle)) {

        RplDump( RG_DebugLevel & RPL_DEBUG_MISC,(
            "AlertRaise: Error closing alerter mailslot %d",
            GetLastError()
            ));
    }
    (VOID)CloseHandle( fileHandle);
}
Beispiel #23
0
/******************************************************************************
 * ReportEventW [ADVAPI32.@]
 *
 * PARAMS
 *   hEventLog   []
 *   wType       []
 *   wCategory   []
 *   dwEventID   []
 *   lpUserSid   []
 *   wNumStrings []
 *   dwDataSize  []
 *   lpStrings   []
 *   lpRawData   []
 */
BOOL WINAPI
ReportEventW(IN HANDLE hEventLog,
             IN WORD wType,
             IN WORD wCategory,
             IN DWORD dwEventID,
             IN PSID lpUserSid,
             IN WORD wNumStrings,
             IN DWORD dwDataSize,
             IN LPCWSTR *lpStrings,
             IN LPVOID lpRawData)
{
    NTSTATUS Status;
    PUNICODE_STRING *Strings;
    UNICODE_STRING ComputerName;
    WORD i;
    WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
    DWORD dwSize;
    LARGE_INTEGER SystemTime;
    ULONG Seconds;

    TRACE("%p, %u, %u, %lu, %p, %u, %lu, %p, %p\n",
          hEventLog, wType, wCategory, dwEventID, lpUserSid,
          wNumStrings, dwDataSize, lpStrings, lpRawData);

    Strings = HeapAlloc(GetProcessHeap(),
                        0,
                        wNumStrings * sizeof(PUNICODE_STRING));
    if (!Strings)
    {
        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
        return FALSE;
    }

    for (i = 0; i < wNumStrings; i++)
    {
        Strings[i] = HeapAlloc(GetProcessHeap(),
                               HEAP_ZERO_MEMORY,
                               sizeof(ANSI_STRING));
        if (Strings[i])
        {
            RtlInitUnicodeString(Strings[i], lpStrings[i]);
        }
    }

    dwSize = MAX_COMPUTERNAME_LENGTH + 1;
    GetComputerNameW(szComputerName, &dwSize);
    RtlInitUnicodeString(&ComputerName, szComputerName);

    NtQuerySystemTime(&SystemTime);
    RtlTimeToSecondsSince1970(&SystemTime, &Seconds);

    RpcTryExcept
    {
        Status = ElfrReportEventW(hEventLog,
        Seconds,
        wType,
        wCategory,
        dwEventID,
        wNumStrings,
        dwDataSize,
        (PRPC_UNICODE_STRING)&ComputerName,
        lpUserSid,
        (PRPC_UNICODE_STRING*)Strings,
        lpRawData,
        0,
        NULL,
        NULL);
    }
    RpcExcept(EXCEPTION_EXECUTE_HANDLER)
    {
        Status = I_RpcMapWin32Status(RpcExceptionCode());
    }
    RpcEndExcept;

    for (i = 0; i < wNumStrings; i++)
    {
        if (Strings[i] != NULL)
            HeapFree(GetProcessHeap(), 0, Strings[i]);
    }

    HeapFree(GetProcessHeap(), 0, Strings);

    if (!NT_SUCCESS(Status))
    {
        SetLastError(RtlNtStatusToDosError(Status));
        return FALSE;
    }

    return TRUE;
}
Beispiel #24
0
static
BOOL
ParseDate(
    PWSTR s,
    PULONG pSeconds)
{
    SYSTEMTIME SystemTime = {0};
    FILETIME LocalFileTime, FileTime;
    LARGE_INTEGER Time;
    INT nDateFormat = 0;
    PWSTR p = s;

    if (!*s)
        return FALSE;

    GetLocaleInfoW(LOCALE_USER_DEFAULT,
                   LOCALE_IDATE,
                   (PWSTR)&nDateFormat,
                   sizeof(INT));

    switch (nDateFormat)
    {
        case 0: /* mmddyy */
        default:
            if (!ReadNumber(&p, &SystemTime.wMonth))
                return FALSE;
            if (!ReadSeparator(&p))
                return FALSE;
            if (!ReadNumber(&p, &SystemTime.wDay))
                return FALSE;
            if (!ReadSeparator(&p))
                return FALSE;
            if (!ReadNumber(&p, &SystemTime.wYear))
                return FALSE;
            break;

        case 1: /* ddmmyy */
            if (!ReadNumber(&p, &SystemTime.wDay))
                return FALSE;
            if (!ReadSeparator(&p))
                return FALSE;
            if (!ReadNumber(&p, &SystemTime.wMonth))
                return FALSE;
            if (!ReadSeparator(&p))
                return FALSE;
            if (!ReadNumber(&p, &SystemTime.wYear))
                return FALSE;
            break;

        case 2: /* yymmdd */
            if (!ReadNumber(&p, &SystemTime.wYear))
                return FALSE;
            if (!ReadSeparator(&p))
                return FALSE;
            if (!ReadNumber(&p, &SystemTime.wMonth))
                return FALSE;
            if (!ReadSeparator(&p))
                return FALSE;
            if (!ReadNumber(&p, &SystemTime.wDay))
                return FALSE;
            break;
    }

    /* if only entered two digits: */
    /*   assume 2000's if value less than 80 */
    /*   assume 1900's if value greater or equal 80 */
    if (SystemTime.wYear <= 99)
    {
        if (SystemTime.wYear >= 80)
            SystemTime.wYear += 1900;
        else
            SystemTime.wYear += 2000;
    }

    if (!SystemTimeToFileTime(&SystemTime, &LocalFileTime))
        return FALSE;

    if (!LocalFileTimeToFileTime(&LocalFileTime, &FileTime))
        return FALSE;

    Time.u.LowPart = FileTime.dwLowDateTime;
    Time.u.HighPart = FileTime.dwHighDateTime;

    if (!RtlTimeToSecondsSince1970(&Time, pSeconds))
        return FALSE;

    return TRUE;
}
Beispiel #25
0
VOID
NlComputeChallenge(
    OUT PNETLOGON_CREDENTIAL Challenge
    )

/*++

Routine Description:

    Generates a 64 bit challenge

    Make an 8 byte seed by filling in BigTime i.e. seconds
    since Jan 1 1970 in lower four bytes and a counter in
    upper four bytes. Counter is incremented after each use.
    This seed is used as encryption key to encrypt standard
    text which will be used as challenge.

Arguments:

    Challenge - Returns the computed challenge

Return Value:

    None.

--*/
{
    NTSTATUS Status;
    char    Seed[PWLEN];
    LM_OWF_PASSWORD BigChallenge;
    LARGE_INTEGER TimeNow;


    RtlZeroMemory(Seed, sizeof(Seed) );

    //
    // we need to remember ClientChallenge and RequestorName for future use
    // put these into shared seg SSISEG
    // NlGlobalSessionCounter is a global initialized to 0 at UAS init time
    //


    Status = NtQuerySystemTime( &TimeNow );
    NlAssert( NT_SUCCESS(Status) );

    Status = RtlTimeToSecondsSince1970( &TimeNow, ((unsigned long * ) Seed) );
    NlAssert( NT_SUCCESS(Status) );

    *((unsigned long * ) & Seed[4]) = NlGlobalSessionCounter++;

    //
    // Create ClientChallenge
    //
    // NOTE: RtlCalculateLmOwfPassword() will generate 16 byte txt
    //

    Status = RtlCalculateLmOwfPassword(Seed, &BigChallenge);
    NlAssert( NT_SUCCESS(Status) );

    //
    // we need (or will use) only 8 bytes of this info
    //

    RtlCopyMemory(Challenge, &BigChallenge, sizeof(Challenge) );

    return;
}