home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / NWTP04 / NWMISC.PAS < prev    next >
Pascal/Delphi Source File  |  1994-01-01  |  24KB  |  712 lines

  1. {$X+,B-,V-}
  2.  
  3. UNIT NWMISC;
  4.  
  5. { nwMisc unit as of 931228 / NwTP 0.4 API. (c) 1994, R.Spronk }
  6.  
  7. INTERFACE
  8.  
  9. { This unit consists of three parts:
  10.  
  11.   1.It contains some functions that perform startup checks:
  12.  
  13.     IsShellLoaded  ( moved to unit nwBindry )
  14.     IsUserLoggedOn ( moved to unit nwBindry )
  15.     IsV3Supported
  16.  
  17.   2...,some level 0 support functions, used by the other NW units:
  18.  
  19.     UpString
  20.     HexString
  21.     PStrCopy
  22.     ZStrCopy
  23.  
  24.     LoNibble
  25.     HiNibble
  26.     Lswap
  27.     HiLong
  28.     LowLong
  29.     MakeLong
  30.  
  31.     GetNWversion
  32.     NovTimeRec2String
  33.     EncryptPassword
  34.  
  35.   3...and types and constants used by more than one NW unit:
  36.  
  37.     Type
  38.      NovTimeRec
  39.      TconnectionList
  40.      TencryptionKey
  41.  
  42.      TnetworkAdress
  43.      Tnodeadress
  44.      TinternetworkAddress
  45.     Const
  46.      <error numbers>
  47. }
  48.  
  49.  
  50. Type NovTimeRec=record
  51.                 year,month,day,hour,min,sec,DayOfWeek:byte; { 0=sunday }
  52.                 end;
  53.      TconnectionList=array[1..250] of byte;
  54.  
  55.      TencryptionKey=array[0..7] of byte;
  56.  
  57.      TnetworkAddress=array[1..4] of byte; { hi-endian }
  58.      TnodeAddress   =array[1..6] of byte; { Hi-endian }
  59.      TinterNetworkAdress=record
  60.                          net   :TnetworkAddress; {hi-lo}
  61.                          node  :Tnodeaddress;    {hi-lo}
  62.                          socket:word;            {lo-hi}
  63.                          end;
  64.  
  65. Function IsV3Supported:Boolean;
  66.  
  67. Procedure NovTimeRec2String(tim:NovTimeRec;Var DateStr:string);
  68. { Puts the time/date information of a NovTimeRec into a string.
  69.   output format: 'DOW, dd mmm yyyy hh:mm:ss' DOW= day of the week. }
  70.  
  71. {============================level 0 support functions=======================}
  72.  
  73. Procedure UpString(s:string);
  74. { Converts s to upperstring.  Assembler, so it's realy a Var parameter.   }
  75.  
  76. Function HexStr(dw:LongInt;len:byte):string;
  77. { Coverts dw into a hex-string of length len                              }
  78.  
  79. procedure PStrCopy(Var dest:String;source:String;len:byte);
  80. { if length(source)>len
  81.    then Copy len bytes from source to dest.
  82.    else Copy source to dest and fill out with NULLs.
  83.   Length(Dest) will allways be set to len.                          }
  84.  
  85.  
  86. procedure ZStrCopy(dest:String;source:array of byte;len:byte);
  87. { 1. Copies len bytes form an array to a pascal type string.                }
  88. { 2. Trailing NULLs are removed from the string.                            }
  89. { consequently, the length of dest (dest[0]) will allways be <= len.        }
  90.  
  91. Procedure GetNWversion(Var version:word);
  92. { determine the version of software installed on the current file server. }
  93. { see GetFileServerInformation F217/11 for more information }
  94. { Version: MajorVersion * 100 + MinorVersion; e.g. 311 for 3.11 }
  95.  
  96. Procedure EncryptPassword(objId:longint;password:string;Var Ekey:TencryptionKey);
  97. { called by LoginToFileServer (unit nwConn),
  98.   and by VerifyBinderyObjectPassword, ChangeBinderyObjectPassword (nwBindry) }
  99. { Source of the encryption routine: LOGON.PAS by Barry Nance, [1:141/209]
  100.   BYTE March'93 }
  101.  
  102. Function LoNibble(b:Byte):Byte;
  103. { Returns the low nibble of the argument (in low nibble position),
  104.   with high nibble set to 0000                                      }
  105. Function HiNibble(b:Byte):Byte;
  106. { Returns the high nibble of the argument (in low nibble position),
  107.   with high nibble set to 0000                                      }
  108.  
  109.  
  110. Function Lswap(l:Longint):Longint;
  111. { swaps bytes in a longInt; ( reverse byte order )                  }
  112. Inline(
  113.   $5A/        {pop DX       ; low word of long }
  114.   $58/        {pop AX       ; hi word of long  }
  115.  
  116.   $86/$F2/    {xchg dl,dh   ; swap bytes       }
  117.   $86/$E0);   {xchg al,ah   ; swap bytes       }
  118.  
  119. function HiLong(Long : LongInt) : Word;
  120. { This inline directive is similar to Turbo's Hi() function, except }
  121. { it returns the high word of a LongInt                             }
  122. Inline(
  123.   $5A/       {pop      dx    ; low word of long                     }
  124.   $58);      {pop      ax    ; hi word of long                      }
  125.  
  126. function LowLong(Long : LongInt) : Word;
  127. { This inline directive is similar to Turbo's Lo() function, except }
  128. { it returns the Low word of a LongInt                              }
  129. Inline(
  130.   $5A/       {pop      dx    ; low word of long                     }
  131.   $58/       {pop      ax    ; hi word of long                      }
  132.   $89/$D0);  {mov      ax,dx ; return lo word as func. result in Ax }
  133.  
  134. function MakeLong(HiWord,LoWord : Word) : LongInt;
  135. { Takes hi and lo words and makes a longint                         }
  136. Inline(
  137.   $58/    { pop ax ; pop low word into AX                           }
  138.   $5A);   { pop dx ; pop high word into DX                          }
  139.  
  140.  
  141. CONST
  142. {** ERRORS DEFINED BY NWxxx UNITS *******}
  143.  
  144. {** STANDARD ERRORS AS USED BY NETWARE **}
  145.    HARDWARE_FAILURE                = 255;
  146.    INVALID_INITIAL_SEMAPHORE_VALUE = 255; {nwSema}
  147.    INVALID_SEMAPHORE_HANDLE        = 255; {nwSema}
  148.    BAD_PRINTER_ERROR               = 255;
  149.    QUEUE_FULL_ERROR                = 255;
  150.    NO_FILES_FOUND_ERROR            = 255;
  151.    BAD_RECORD_OFFSET               = 255;
  152.    PATH_NOT_LOCATABLE              = 255;
  153.    SOCKET_ALREADY_OPEN             = 255;
  154.    INVALID_DRIVE_NUMBER            = 255; {nwDir}
  155.    NO_RECORD_FOUND                 = 255;
  156.    NO_RESPONSE_FROM_SERVER         = 255;
  157.    REQUEST_NOT_OUTSTANDING         = 255;
  158.    NO_SUCH_OBJECT_OR_BAD_PASSWORD  = 255;
  159.    CLOSE_FCB_ERROR                 = 255;
  160.    FILE_EXTENSION_ERROR            = 255;
  161.    FILE_NAME_ERROR                 = 255;
  162.    IO_BOUND_ERROR                  = 255;
  163.    SPX_IS_INSTALLED                = 255; {nwIpx}
  164.    SPX_SOCKET_NOT_OPENED           = 255; {nwIpx}
  165.    EXPLICIT_TRANSACTION_ACTIVE     = 255; {nwTTS}
  166.    NO_EXPLICIT_TRANSACTION_ACTIVE  = 255; {nwTTS}
  167.    TRANSACTION_NOT_YET_WRITTEN     = 255; {nwTTS}
  168.    NO_MORE_MATCHING_FILES          = 255; {nwTTS}
  169.    BINDERY_FAILURE                 = 255;
  170.    OPEN_FILES                      = 255;  {3.x}
  171.    PRINT_JOB_ALREADY_QUEUED        = 255;  {3.x}
  172.    PRINT_JOB_ALREADY_SET           = 255;  {3.x}
  173.    SUPERVISOR_HAS_DISABLED_LOGIN   = 254; {nwConn}
  174.    TIMEOUT_FAILURE                 = 254;
  175.    BINDERY_LOCKED                  = 254; {nwBindry}
  176.    SERVER_BINDERY_LOCKED           = 254;
  177.    INVALID_SEMAPHORE_NAME_LENGTH   = 254; {nwSema}
  178.    PACKET_NOT_DELIVERABLE          = 254;
  179.    SOCKET_TABLE_FULL               = 254;
  180.    DIRECTORY_LOCKED                = 254;
  181.    SPOOL_DIRECTORY_ERROR           = 254;
  182.    IMPLICIT_TRANSACTION_ACTIVE     = 254; {nwTTS}
  183.    TRANSACTION_ENDS_RECORD_LOCK    = 254; {nwTTS}
  184.    IO_FAILURE                      = 254;  {3.x}
  185.    UNKNOWN_REQUEST                 = 253;
  186.    INVALID_PACKET_LENGTH           = 253;
  187.    FIELD_ALREADY_LOCKED            = 253;
  188.    BAD_STATION_NUMBER              = 253;
  189.    SPX_MALFORMED_PACKET            = 253;
  190.    SPX_PACKET_OVERFLOW             = 253;
  191.    TTS_DISABLED                    = 253;
  192.    NO_SUCH_OBJECT                  = 252;
  193.    UNKNOWN_FILE_SERVER             = 252;
  194.    INTERNET_PACKET_REQT_CANCELED   = 252;
  195.    MESSAGE_QUEUE_FULL              = 252; {nwMess}
  196.    SPX_LISTEN_CANCELED             = 252;
  197.    NO_SUCH_PROPERTY                = 251;
  198.    INVALID_PARAMETERS              = 251;
  199.    {UNKNOWN_REQUEST                 = 251; ?double see 253}
  200.    NO_MORE_SERVER_SLOTS            = 250;
  201.    TEMP_REMAP_ERROR                = 250;
  202.    NO_PROPERTY_READ_PRIVILEGE      = 249;
  203.    NO_FREE_CONNECTION_SLOTS        = 249;
  204.    NO_PROPERTY_WRITE_PRIVILEGE     = 248;
  205.    ALREADY_ATTACHED_TO_SERVER      = 248;
  206.    NOT_ATTACHED_TO_SERVER          = 248;
  207.    NO_PROPERTY_CREATE_PRIVILEGE    = 247;
  208.    TARGET_DRIVE_NOT_LOCAL          = 247;
  209.    NO_PROPERTY_DELETE_PRIVILEGE    = 246;
  210.    NOT_SAME_LOCAL_DRIVE            = 246;
  211.    NO_OBJECT_CREATE_PRIVILEGE      = 245;
  212.    NO_OBJECT_DELETE_PRIVILEGE      = 244;
  213.    NO_OBJECT_RENAME_PRIVILEGE      = 243;
  214.    NO_OBJECT_READ_PRIVILEGE        = 242;
  215.    INVALID_BINDERY_SECURITY        = 241;
  216.    WILD_CARD_NOT_ALLOWED           = 240;
  217.    IPX_NOT_INSTALLED               = 240; {nwIpx}
  218.    INVALID_NAME                    = 239;
  219.    SPX_CONNECTION_TABLE_FULL       = 239;
  220.    OBJECT_ALREADY_EXISTS           = 238;
  221.    SPX_INVALID_CONNECTION          = 238;
  222.    PROPERTY_ALREADY_EXISTS         = 237;
  223.    SPX_NO_ANSWER_FROM_TARGET       = 237;
  224.    SPX_CONNECTION_FAILED           = 237;
  225.    SPX_CONNECTION_TERMINATED       = 237;
  226.    NO_SUCH_SEGMENT                 = 236;
  227.    SPX_TERMINATED_POORLY           = 236;
  228.    NOT_GROUP_PROPERTY              = 235;
  229.    NO_SUCH_MEMBER                  = 234;
  230.    MEMBER_ALREADY_EXISTS           = 233;
  231.    NOT_ITEM_PROPERTY               = 232;
  232.    WRITE_PROPERTY_TO_GROUP         = 232;
  233.    PASSWORD_HAS_EXPIRED            = 223;
  234.    PASSWORD_HAS_EXPIRED_NO_GRACE   = 222;
  235.    ACCOUNT_DISABLED                = 220;
  236.    UNAUTHORIZED_LOGIN_STATION      = 219;
  237.    MAX_Q_SERVERS                   = 219;
  238.    UNAUTHORIZED_LOGIN_TIME         = 218;
  239.    Q_HALTED                        = 218;
  240.    LOGIN_DENIED_NO_CONNECTION      = 217;
  241.    STN_NOT_SERVER                  = 217;
  242.    PASSWORD_TOO_SHORT              = 216;
  243.    Q_NOT_ACTIVE                    = 216;
  244.    PASSWORD_NOT_UNIQUE             = 215;
  245.    Q_SERVICING                     = 215;
  246.    NO_JOB_RIGHTS                   = 214;
  247.    NO_Q_JOB                        = 213;
  248.    Q_FULL                          = 212;
  249.    NO_Q_RIGHTS                     = 211;
  250.    NO_Q_SERVER                     = 210;
  251.    NO_QUEUE                        = 209;
  252.    Q_ERROR                         = 208;
  253.    NOT_CONSOLE_OPERATOR            = 198;
  254.    INTRUDER_DETECTION_LOCK         = 197;
  255.    ACCOUNT_TOO_MANY_HOLDS          = 195;
  256.    CREDIT_LIMIT_EXCEEDED           = 194;
  257.    NO_ACCOUNT_BALANCE              = 193;
  258.    NO_ACCOUNT_PRIVILEGES           = 192;
  259.    READ_FILE_WITH_RECORD_LOCKED    = 162;
  260.    DIRECTORY_IO_ERROR              = 161;
  261.    DIRECTORY_NOT_EMPTY             = 160;
  262.    DIRECTORY_ACTIVE                = 159;
  263.    INVALID_FILENAME                = 158;
  264.    NO_MORE_DIRECTORY_HANDLES       = 157;
  265.    NO_MORE_TRUSTEES                = 156;
  266.    INVALID_PATH                    = 156;
  267.    BAD_DIRECTORY_HANDLE            = 155;
  268.    RENAMING_ACROSS_VOLUMES         = 154;
  269.    DIRECTORY_FULL                  = 153;
  270.    VOLUME_DOES_NOT_EXIST           = 152;
  271.    NO_DISK_SPACE_FOR_SPOOL_FILE    = 151;
  272.    SERVER_OUT_OF_MEMORY            = 150;
  273.    OUT_OF_DYNAMIC_WORKSPACE        = 150;
  274.    FILE_DETACHED                   = 149;
  275.    NO_WRITE_PRIVILEGES             = 148;
  276.    READ_ONLY                       = 148;
  277.    NO_READ_PRIVILEGES              = 147;
  278.    NO_FILES_RENAMED_NAME_EXISTS    = 146;
  279.    SOME_FILES_RENAMED_NAME_EXISTS  = 145;
  280.    NO_FILES_AFFECTED_READ_ONLY     = 144;
  281.    SOME_FILES_AFFECTED_READ_ONLY   = 143;
  282.    NO_FILES_AFFECTED_IN_USE        = 142;
  283.    SOME_FILES_AFFECTED_IN_USE      = 141;
  284.    NO_MODIFY_PRIVILEGES            = 140;
  285.    NO_RENAME_PRIVILEGES            = 139;
  286.    NO_DELETE_PRIVILEGES            = 138;
  287.    NO_SEARCH_PRIVILEGES            = 137;
  288.    INVALID_FILE_HANDLE             = 136;
  289.    WILD_CARDS_IN_CREATE_FILENAME   = 135;
  290.    CREATE_FILE_EXISTS_READ_ONLY    = 134;
  291.    NO_CREATE_DELETE_PRIVILEGES     = 133;
  292.    NO_CREATE_PRIVILEGES            = 132;
  293.    IO_ERROR_NETWORK_DISK           = 131;
  294.    NO_OPEN_PRIVILEGES              = 130;
  295.    NO_MORE_FILE_HANDLES            = 129;
  296.    FILE_IN_USE_ERROR               = 128;
  297.    DOS_LOCK_VIOLATION              = 33;
  298.    DOS_SHARING_VIOLATION           = 32;
  299.    DOS_NO_MORE_FILES               = 31;
  300.    DOS_NOT_SAME_DEVICE             = 30;
  301.    DOS_ATTEMT_TO_DEL_CURRENT_DIR   = 16;
  302.    DOS_INVALID_DRIVE               = 15;
  303.    DOS_INVALID_DATA                = 13;
  304.    DOS_INVALID_ACCESS_CODE         = 12;
  305.    DOS_INVALID_FORMAT              = 11;
  306.    DOS_INVALID_ENVIRONMENT         = 10;
  307.    DOS_INVALID_MEMORY_BLOCK_ADDR   = 9;
  308.    DOS_INSUFFICIENT_MEMORY         = 8;
  309.    DOS_MEMORY_BLOCKS_DESTROYED     = 7;
  310.    DOS_INVALID_FILE_HANDLE         = 6;
  311.    DOS_ACCESS_DENIED               = 5;
  312.    DOS_TOO_MANY_OPEN_FILES         = 4;
  313.    DOS_PATH_NOT_FOUND              = 3;
  314.    DOS_FILE_NOT_FOUND              = 2;
  315.    TTS_AVAILABLE                   = 1;
  316.    SERVER_IN_USE                   = 1;
  317.    SEMAPHORE_OVERFLOW              = 1;
  318.    DOS_INVALID_FUNCTION_NUMBER     = 1;
  319.    TTS_NOT_AVAILABLE               = 1;
  320.    SERVER_NOT_IN_USE               = 1;
  321.  
  322. IMPLEMENTATION{=============================================================}
  323.  
  324.  
  325. Uses dos;
  326.  
  327.  
  328. Procedure EncryptPassword(objId:longint;password:string;Var Ekey:TencryptionKey);
  329. { called by LoginTo3Xserver }
  330. { Source of the encryption routine: LOGON.PAS by Barry Nance, [1:141/209]
  331.   BYTE March'93 }
  332. TYPE
  333.   Buf32 = ARRAY [0..31] OF Byte;
  334.   Buf16 = ARRAY [0..15] OF Byte;
  335.   Buf4  = ARRAY [0..3]  OF Byte;
  336.  
  337. CONST
  338.   EncryptTable : ARRAY [Byte] OF Byte =
  339. ($7,$8,$0,$8,$6,$4,$E,$4,$5,$C,$1,$7,$B,$F,$A,$8,
  340.  $F,$8,$C,$C,$9,$4,$1,$E,$4,$6,$2,$4,$0,$A,$B,$9,
  341.  $2,$F,$B,$1,$D,$2,$1,$9,$5,$E,$7,$0,$0,$2,$6,$6,
  342.  $0,$7,$3,$8,$2,$9,$3,$F,$7,$F,$C,$F,$6,$4,$A,$0,
  343.  $2,$3,$A,$B,$D,$8,$3,$A,$1,$7,$C,$F,$1,$8,$9,$D,
  344.  $9,$1,$9,$4,$E,$4,$C,$5,$5,$C,$8,$B,$2,$3,$9,$E,
  345.  $7,$7,$6,$9,$E,$F,$C,$8,$D,$1,$A,$6,$E,$D,$0,$7,
  346.  $7,$A,$0,$1,$F,$5,$4,$B,$7,$B,$E,$C,$9,$5,$D,$1,
  347.  $B,$D,$1,$3,$5,$D,$E,$6,$3,$0,$B,$B,$F,$3,$6,$4,
  348.  $9,$D,$A,$3,$1,$4,$9,$4,$8,$3,$B,$E,$5,$0,$5,$2,
  349.  $C,$B,$D,$5,$D,$5,$D,$2,$D,$9,$A,$C,$A,$0,$B,$3,
  350.  $5,$3,$6,$9,$5,$1,$E,$E,$0,$E,$8,$2,$D,$2,$2,$0,
  351.  $4,$F,$8,$5,$9,$6,$8,$6,$B,$A,$B,$F,$0,$7,$2,$8,
  352.  $C,$7,$3,$A,$1,$4,$2,$5,$F,$7,$A,$C,$E,$5,$9,$3,
  353.  $E,$7,$1,$2,$E,$1,$F,$4,$A,$6,$C,$6,$F,$4,$3,$0,
  354.  $C,$0,$3,$6,$F,$8,$7,$B,$2,$D,$C,$6,$A,$A,$8,$D);
  355.  
  356.   EncryptKeys : Buf32 =
  357. ($48,$93,$46,$67,$98,$3D,$E6,$8D,$B7,$10,$7A,$26,$5A,$B9,$B1,$35,
  358.  $6B,$0F,$D5,$70,$AE,$FB,$AD,$11,$F4,$47,$DC,$A7,$EC,$CF,$50,$C0);
  359.  
  360. Var buf:buf32;
  361.     TobjId:Longint;
  362.     Tpassword:string;
  363.  
  364.    PROCEDURE Shuffle1(VAR temp : Buf32; VAR target);
  365.    VAR _target  :  Buf16 ABSOLUTE target;
  366.        b4 :  Word;
  367.        b3 :  Byte;
  368.        d, k, i : Word;
  369.    Begin
  370.  
  371.    {** Step 4: .. }
  372.    b4 := 0;
  373.    FOR k := 0 TO 1
  374.     DO Begin
  375.        FOR i := 0 TO 31
  376.         DO Begin
  377.            b3 := Lo( Lo(temp[i] + b4) XOR
  378.                  Lo(temp[(i + b4) AND 31] - EncryptKeys[i]));
  379.            b4 := b4 + b3;
  380.            temp[i] := b3;
  381.            End;
  382.        End;
  383.  
  384.    {*** Step 5:... }
  385.  
  386.    FOR i := 0 TO 15
  387.     DO _Target[i] := EncryptTable[temp[i Shl 1]] OR
  388.                     (EncryptTable[temp[i Shl 1 +1]] Shl 4);
  389.    End;
  390.  
  391.  
  392.    PROCEDURE Shuffle(VAR ShuffleKey, buf; buflen : Word; VAR target);
  393.    { id, password[1.. ],length(passw), OUT: buf }
  394.    VAR locShuffleKey : Buf4 ABSOLUTE ShuffleKey;
  395.        localBuf : ARRAY [0..127] OF Byte ABSOLUTE buf;
  396.        BufBytesUsed : Word;
  397.        temp : Buf32;
  398.        t, IndexOfBufBytes : Word;
  399.    Begin
  400.    { strip trailing NULLs of the to-be-encoded buf,
  401.      last element of buf must be a NULL ? }
  402.    While (buflen > 0) AND (localBuf[buflen-1] = 0)
  403.     DO buflen := buflen - 1;
  404.    { clear output of 1st shuffle }
  405.    FillChar(temp, SizeOf(temp), #0);
  406.  
  407.    {*** 1ST Step: XOR folding of first (32*(buflen DIV 32)) bytes. }
  408.  
  409.    { temp= buf[0..31] XOR buf[32..63] XOR buf[64..95] XOR etc.. }
  410.  
  411.    { IndexOfBufBytes is een 32-voud, lengte password was: IndexOfBufBytes + buflen }
  412.    { temp gevuld met XOR folding van de eerste IndexOfBufBytes bytes. }
  413.    IndexOfBufBytes := 0;
  414.    WHILE buflen >= 32
  415.     DO Begin
  416.        FOR t := 0 TO 31
  417.         DO Begin
  418.            temp[t] := temp[t] XOR localBuf[IndexOfBufBytes];
  419.            IndexOfBufBytes := IndexOfBufBytes + 1;
  420.            End;
  421.        buflen := buflen - 32;
  422.        End;
  423.  
  424.    {*** 2ND step: repetitive XOR folding with (remainder of) password
  425.  
  426.      password='hello', (BufBytesUsed=0)
  427.      or password='12345678901234567890123456789012hello' (BufBytesUsed=32)
  428.      of which the first 32 bytes were used in the 1st encryption step.
  429.  
  430.      temp=temp XOR [hellohellohellohellohellohellohe];
  431.     }
  432.    BufBytesUsed:=IndexOfBufBytes;
  433.    IF buflen > 0
  434.     Then Begin
  435.          FOR t := 0 TO 31
  436.           DO Begin
  437.              IF IndexOfBufBytes + buflen = BufBytesUsed
  438.               Then Begin
  439.                    BufBytesUsed := IndexOfBufBytes;
  440.                    temp[t] := temp[t] XOR EncryptKeys[t];
  441.                    End
  442.               Else Begin
  443.                    temp[t] := temp[t] XOR localBuf[BufBytesUsed];
  444.                    BufBytesUsed := BufBytesUsed + 1;
  445.                    End;
  446.              End;
  447.          End;
  448.    {*** 3RD step: XOR-ing with shuffleKey (bytes of a longint)}
  449.  
  450.    FOR t := 0 TO 31 DO temp[t] := temp[t] XOR locShuffleKey[t AND 3];
  451.  
  452.    {*** 4&5 TH Step: see Shuffle1 }
  453.  
  454.    Shuffle1(temp, target);
  455.    End;
  456.  
  457.  
  458.     PROCEDURE Encrypt(VAR key, buf, EncrPassword);
  459.   { The encryptionKey 'key' is encrypted with the aid of
  460.     the encrypted login name/id within 'buf'.
  461.     Result: the Password to login with (of type TencryptionKey). }
  462.   VAR _Key : TencryptionKey  ABSOLUTE Key;
  463.       _EncrKey : TencryptionKey  ABSOLUTE EncrPassword;
  464.       _LocalBuf : Buf32;
  465.       i: Byte;
  466.   Begin
  467.     Shuffle(_Key[0], buf, 16, _LocalBuf[0]);
  468.     Shuffle(_Key[4], buf, 16, _LocalBuf[16]);
  469.     FOR i := 0 TO 15 DO _LocalBuf[i] := _LocalBuf[i] XOR _LocalBuf[31-i];
  470.     FOR i := 0 TO 7 DO _EncrKey[i] := _LocalBuf[i] XOR _LocalBuf[15-i];
  471.   End;
  472.  
  473. begin
  474. TobjId:=objId;
  475. Tpassword:=password;
  476. Shuffle(TObjId,Tpassword[1],length(password),buf);
  477. Encrypt(Ekey,buf,Ekey);
  478. end;
  479.  
  480.  
  481. Procedure UpString(s : String); Assembler;
  482. { fast upcasestring by Bob Swart }
  483. ASM
  484.         PUSH   DS
  485.         LDS    SI, s
  486.         LES    DI, s
  487.         CLD
  488.         XOR    AH, AH
  489.         LODSB
  490.         STOSB
  491.         XCHG   AX, CX           { empty string? }
  492.         JCXZ   @2
  493. @1:     LODSB
  494.         SUB    AL, 'a'
  495.         CMP    AL, 'z'-'a'+1
  496.         SBB    AH, AH
  497.         AND    AH, 'a'-'A'
  498.         SUB    AL, AH
  499.         ADD    AL, 'a'
  500.         STOSB
  501.         LOOP   @1
  502. @2:     POP    DS
  503. end;
  504.  
  505.  
  506. {$IFDEF newcalls}
  507.  
  508. procedure PStrCopy(Var dest:String;source:String;len:byte);
  509. { if length(source)>len
  510.    then Copy len bytes from source to dest.
  511.    else Copy source to dest and fill out with NULLs.
  512.   Length(Dest) will allways be set to len.                          }
  513. begin
  514. FillChar(dest[1],len,#0);
  515. move(source[1],dest[1],ord(source[0]));
  516. dest[0]:=chr(len);
  517. end;
  518.  
  519. procedure ZStrCopy(Var dest:String;source:array of byte;len:byte);
  520. { 1. Copies len bytes from an array to a pascal type string.                }
  521. { 2. Trailing NULLs are removed from the string.                            }
  522. { consequently, the length of dest (dest[0]) will allways be <= len.         }
  523. begin
  524. Move(source,dest[1],len);
  525. while (dest[len]=#0) and (len>0) do dec(len);
  526. dest[0]:=chr(len);
  527. end;
  528.  
  529. {$ENDIF}
  530.  
  531.  
  532. procedure PStrCopy(Var dest:String;source:String;len:byte);
  533. Var w:byte;
  534. begin
  535. w:=1;
  536. dest[0]:=chr(len);
  537. While w<=ord(source[0])
  538.  do begin
  539.     dest[w]:=source[w];
  540.     inc(w)
  541.     end;
  542. While w<=len
  543.  do begin
  544.     dest[w]:=#0;
  545.     inc(w)
  546.     end;
  547. end;
  548.  
  549. procedure ZStrCopy(dest:String;source:array of byte;len:byte); assembler;
  550. { 1. Copies len bytes from an array to a pascal type string.                }
  551. { 2. Trailing NULLs are removed from the string.                            }
  552. { consequently, the length of det (dest[0]) will allways be <= len.         }
  553. asm
  554. mov dx,ds        { fast save current DS }
  555. les di,dest
  556. lds si,source
  557.  
  558. xor ah,ah       { ah:=0 }
  559. mov al,len
  560. mov es:[di],al  { dest[0]:=len }
  561. inc di          { es:di => dest[1] ; ds:si => source[0] }
  562.  
  563. mov cx,ax
  564. cld
  565. rep movsb
  566.  
  567. { begin DeleteTrailingNulls }
  568. les di,dest
  569. xor bh,bh
  570. mov bl,len
  571. @rep:
  572. mov al,es: [di] [bx]
  573. and al,al
  574. jne @cont
  575.  
  576. dec bl
  577. jne @rep
  578.  
  579. @cont:
  580. mov es:[di],bl   { set length of dest string }
  581. { end DeleteTrailingNulls }
  582.  
  583. mov ds,dx       { restore DS }
  584. end;
  585.  
  586. Procedure NovTimeRec2String(tim:NovTimeRec;Var DateStr:string);
  587. CONST day:array[0..6] of string[3]
  588.           =('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  589.       Month:array[1..12] of string[3]
  590.           =('Jan','Feb','Mar','Apr','May','Jun',
  591.             'Jul','Aug','Sep','Oct','Nov','Dec');
  592. Type string4=string[4];
  593. Var  sday,syear,shour,smin,ssec:string4;
  594.   Procedure zstr(n:byte;Var s:string4);
  595.   begin
  596.   str(n,s);
  597.   if s[0]=#1 then s:='0'+s;
  598.   end;
  599. begin
  600. if (tim.month>12) or (tim.month<1)
  601.    or (tim.day<1) or (tim.day>31)
  602.    or (tim.hour>23) or (tim.min>59) or (tim.sec>59)
  603.  then DateStr:='<invalid date & time>    '
  604.  else begin
  605.       zstr(tim.day,sday);
  606.       if sday[1]='0' then sday[1]:=' ';
  607.       if tim.year<80 then str(tim.year+2000,syear)
  608.                      else str(tim.year+1900,syear);
  609.       zstr(tim.hour,shour);
  610.       zstr(tim.min,smin);
  611.       zstr(tim.sec,ssec);
  612.       DateStr:=day[tim.DayOfWeek]+', '+
  613.                sday+' '+Month[tim.month]+' '+syear+' '+
  614.                shour+':'+smin+':'+ssec;
  615.       end;
  616. end;
  617.  
  618. Function LoNibble(b:Byte):Byte; assembler;
  619. asm
  620. mov al,b
  621. and al,$0F
  622. end;
  623.  
  624. Function HiNibble(b:Byte):Byte; assembler;
  625. asm
  626. mov ah,$00
  627. mov al,b
  628. shr ax,1
  629. shr ax,1
  630. shr ax,1
  631. shr ax,1
  632. end;
  633.  
  634. Function HexStr(dw:LongInt;len:byte):string;
  635. CONST n:array[0..15] of char
  636.       =('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  637. Var t:integer;
  638.     ldw:LongInt;
  639.     res:string;
  640. begin
  641. res:='';
  642. for t:=1 to len
  643. do begin
  644.    ldw:=dw AND $0000000F;
  645.    res:=n[ldw]+res;
  646.    dw:=dw SHR 4;
  647.    end;
  648. HexStr:=res;
  649. end;
  650.  
  651.  
  652. Procedure GetNWversion(Var version:word);
  653. { determine the version of the software installed on the current file server. }
  654. { see GetServerInformation F217/11 in the nwServ unit for more information }
  655.  
  656. { version : word; contains the versionnumber of the fileserver we're
  657.             currently connected to. Used by primary functions to
  658.             determine what type of calls to use to perform a certain function.
  659.  
  660.             format: (majorVersion*100)+minorVersion
  661.                     e.g. 311 for 3.11
  662.             Range: 100 (advanced netware 1.00) and upwards    }
  663. { note: you don't have to be logged in to call this function. }
  664. Var  Reg            : Registers;
  665.      RequestBuffer  : Record
  666.                       PacketLength : Word;
  667.                       FunctionVal  : Byte;
  668.                       End;
  669.      ReplyBuffer:array[1..$80] of byte;
  670.      ReplyLength:word ABSOLUTE ReplyBuffer; { not needed for F2 call }
  671. Begin
  672. With RequestBuffer
  673. Do Begin
  674.    PacketLength := 1; FunctionVal := $11;
  675.    End;
  676. With reg
  677.  do begin
  678.     ax := $f217;
  679.     ds:=SEG(requestBuffer);   si := OFs(requestBuffer);
  680.     cx:=sizeOf(requestBuffer);
  681.     es:=SEG(replyBuffer); di := OFs(replyBuffer);
  682.     dx:=sizeOf(replyBuffer);
  683.     MsDos(reg);
  684.     end;
  685. If reg.AL=0
  686.  then version:=(ReplyBuffer[49]*100)+ReplyBuffer[50]
  687.  else begin { If F217/11 failed, try old E3../11 call }
  688.       ReplyLength := $80;
  689.       With Reg
  690.       Do Begin
  691.          Ah := $e3;
  692.          Ds := Seg(RequestBuffer); Si := Ofs(RequestBuffer);
  693.          Es := Seg(ReplyBuffer);   Di := Ofs(ReplyBuffer);
  694.          End;
  695.       MsDos(Reg);
  696.       if reg.AL<>0
  697.        then version:=$00
  698.        else version:=(ReplyBuffer[51]*100)+ReplyBuffer[52];
  699.       end;
  700. End;
  701.  
  702.  
  703. Function IsV3Supported:boolean;
  704. Var version:word;
  705. begin
  706. GetNWversion(version);
  707. IsV3Supported:=(version>=300);
  708. end;
  709.  
  710.  
  711. END.
  712.