grp.pp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. {$IFNDEF FPC_DOTTEDUNITS}
  2. unit grp;
  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. _PATH_GROUP = '/etc/group';
  18. Type
  19. PGroup = ^TGroup;
  20. PPGroup = ^PGroup;
  21. TGroup = record
  22. gr_name : PAnsiChar; { group name }
  23. gr_passwd : PAnsiChar; { group password }
  24. gr_gid : gid_t; { group id }
  25. gr_mem : PPAnsiChar; { group members }
  26. end;
  27. procedure fpendgrent; cdecl;external External_library name 'endgrent';
  28. function fpgetgrent:pgroup; cdecl;external External_library name 'getgrent';
  29. function fpgetgrgid (id:gid_t):pgroup; cdecl;external External_library name 'getgrgid';
  30. function fpgetgrnam (name:PAnsiChar):pgroup; cdecl;external External_library name 'getgrnam';
  31. {$ifdef BSD}
  32. function fpgroup_from_gid (gid:gid_t; nogrup:cint):PAnsiChar; cdecl;external External_library name 'group_from_gid';
  33. {$endif}
  34. function fpsetgrent:cint;cdecl;external External_library name 'setgrent';
  35. function fpgetgrgid_r (id:gid_t; grp:Pgroup; buffer:PAnsiChar; buffersize:size_t; grresult:PPgroup):cint;cdecl;external External_library name 'getgrgid_r';
  36. function fpgetgrnam_r (nam:PAnsiChar; grp:Pgroup; buffer:PAnsiChar; buffersize:size_t; grresult:PPgroup):cint;cdecl;external External_library name 'getgrnam_r';
  37. {$ifndef Darwin}
  38. function fpgetgrent_r (grp:Pgroup; buffer:PAnsiChar; buffersize:size_t; grresult:PPgroup):cint;cdecl;external External_library name 'getgrent_r';
  39. {$endif}
  40. function fpsetgroupent (stayopen:cint):cint;cdecl;external External_library name 'setgroupent';
  41. {$ifdef Darwin}
  42. procedure fpsetgrfile(name:PAnsiChar); cdecl; external external_library name 'setgrfile';
  43. {$endif}
  44. // FreeBSD has these, Linux too if USE_BSD is defined. Darwin too.
  45. // Darwin uses ints instead of gid's though, except for setgroups.
  46. function fpsetgroups(n:size_t;groups:pgid):cint; cdecl; external External_Library name 'setgroups';
  47. function fpgetgrouplist(user:PAnsiChar;group:tgid;groups:pgid;ngroups:pcint):cint; cdecl; external External_Library name 'getgrouplist';
  48. function fpinitgroups(user:PAnsiChar;group:tgid):cint;cdecl; external External_Library name 'initgroups';
  49. implementation
  50. end.