pwd.pp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. unit pwd;
  2. interface
  3. uses
  4. initc,unixtype,baseunix,ctypes;
  5. {$IFDEF FPC}
  6. {$PACKRECORDS C}
  7. {$ENDIF}
  8. const
  9. External_library= clib; {Setup as you need}
  10. const
  11. _PATH_PWD = '/etc';
  12. _PATH_PASSWD = '/etc/passwd';
  13. _PASSWD = 'passwd';
  14. _PATH_MASTERPASSWD = '/etc/master.passwd';
  15. {$ifdef Darwin}
  16. _PATH_MASTERPASSWD_LOCK = '/etc/ptmp';
  17. {$endif}
  18. _MASTERPASSWD = 'master.passwd';
  19. _PATH_MP_DB = '/etc/pwd.db';
  20. _MP_DB = 'pwd.db';
  21. _PATH_SMP_DB = '/etc/spwd.db';
  22. _SMP_DB = 'spwd.db';
  23. _PATH_PWD_MKDB = '/usr/sbin/pwd_mkdb';
  24. {$ifdef BSD}
  25. _PW_VERSION_MASK = #$F0;
  26. function _PW_VERSIONED(x,v : longint) : cuchar; inline;
  27. const
  28. _PW_KEYBYNAME = #$31; { stored by name }
  29. _PW_KEYBYNUM = #$32; { stored by entry in the "file"}
  30. _PW_KEYBYUID = #$33; { stored by uid }
  31. {$ifdef FreeBSD}
  32. _PW_KEYYPENABLED = #$34; { YP is enabled }
  33. _PW_KEYYPBYNUM = #$35; { special +@netgroup entries }
  34. {$endif}
  35. { The database also contains a key to indicate the format version of
  36. * the entries therein. There may be other, older versioned entries
  37. * as well. }
  38. const
  39. {$ifdef FreeBSD}
  40. _PWD_VERSION_KEY = #$FF+'VERSION';
  41. _PWD_CURRENT_VERSION = #$4;
  42. {$endif}
  43. _PASSWORD_EFMT1 = '_'; { extended encryption format }
  44. _PASSWORD_LEN = 128; { max length, not counting NULL }
  45. {$ifdef Darwin}
  46. _PASSWORD_NOUID = $01; (* flag for no specified uid. *)
  47. _PASSWORD_NOGID = $02; (* flag for no specified gid. *)
  48. _PASSWORD_NOCHG = $04; (* flag for no specified change. *)
  49. _PASSWORD_NOEXP =$08; (* flag for no specified expire. *)
  50. _PASSWORD_WARNDAYS = 14; (* days to warn about expiry *)
  51. _PASSWORD_CHGNOW = -1; (* special day to force password
  52. * change at next login *)
  53. {$endif}
  54. {$endif}
  55. type
  56. { Darwin uses __darwin_time_t, but that is an alias for time_t }
  57. PPasswd = ^TPasswd;
  58. PPPasswd = ^PPasswd;
  59. Passwd = record
  60. pw_name : pchar; { user name }
  61. pw_passwd : pchar; { encrypted password }
  62. pw_uid : Tuid; { user uid }
  63. pw_gid : Tgid; { user gid }
  64. {$ifdef bsd}
  65. pw_change : Ttime platform; { password change time }
  66. pw_class : pchar platform; { user access class }
  67. {$endif}
  68. pw_gecos : pchar; { Honeywell login info }
  69. pw_dir : pchar; { home directory }
  70. pw_shell : pchar; { default shell }
  71. {$ifdef bsd}
  72. pw_expire : Ttime platform; { account expiration }
  73. {$ifdef FreeBSD}
  74. pw_fields : cint platform; { internal: fields filled in }
  75. {$endif}
  76. {$endif}
  77. end;
  78. TPasswd = Passwd;
  79. {$ifdef FreeBSD}
  80. const
  81. _PWF_NAME = 1;
  82. _PWF_PASSWD = 2;
  83. _PWF_UID = 4;
  84. _PWF_GID = 8;
  85. _PWF_CHANGE = $10;
  86. _PWF_CLASS = $20;
  87. _PWF_GECOS = $40;
  88. _PWF_DIR = $80;
  89. _PWF_SHELL = $100;
  90. _PWF_EXPIRE = $200;
  91. _PWF_SOURCE = $3000;
  92. _PWF_FILES = $1000;
  93. _PWF_NIS = $2000;
  94. _PWF_HESIOD = $3000;
  95. {$endif}
  96. function fpgetpwnam (name:pchar):PPasswd; cdecl;external External_library name 'getpwnam';
  97. function fpgetpwuid (id:tuid):PPasswd;cdecl;external External_library name 'getpwuid';
  98. procedure fpendpwent;cdecl;external External_library name 'endpwent';
  99. function fpgetpwent:ppasswd;cdecl;external External_library name 'getpwent';
  100. procedure fpsetpwent;cdecl;external External_library name 'setpwent';
  101. function fpgetpwnam_r (namepara1:pchar; pwd:Ppasswd; buffer:pchar; bufsize:size_t; pwresult:PPpasswd):cint;cdecl;external External_library name 'getpwnam_r';
  102. function fpgetpwuid_r (uid:uid_t; pwd:Ppasswd; buffer:pchar; buffersize:size_t; pwresult:PPpasswd):cint;cdecl;external External_library name 'getpwuid_r';
  103. {$ifndef Darwin}
  104. function fpgetpwent_r (pwd:Ppasswd; buffer:pchar; buffersize:size_t; pwresult:PPpasswd):cint;cdecl;external External_library name 'getpwent_r';
  105. {$endif}
  106. implementation
  107. {$ifdef BSD}
  108. function _PW_VERSIONED (x,v : longint) : cuchar; inline;
  109. begin
  110. _PW_VERSIONED:= (x and $CF) or (v shl 4);
  111. end;
  112. {$endif}
  113. end.