pwd.pp 4.7 KB

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