_pwdgrp_build.py 906 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from cffi import FFI
  2. ffi = FFI()
  3. ffi.set_source("_pwdgrp_cffi", """
  4. #include <sys/types.h>
  5. #include <pwd.h>
  6. #include <grp.h>
  7. """)
  8. ffi.cdef("""
  9. typedef int... uid_t;
  10. typedef int... gid_t;
  11. struct passwd {
  12. char *pw_name;
  13. char *pw_passwd;
  14. uid_t pw_uid;
  15. gid_t pw_gid;
  16. char *pw_gecos;
  17. char *pw_dir;
  18. char *pw_shell;
  19. ...;
  20. };
  21. struct group {
  22. char *gr_name; /* group name */
  23. char *gr_passwd; /* group password */
  24. gid_t gr_gid; /* group ID */
  25. char **gr_mem; /* group members */
  26. };
  27. struct passwd *getpwuid(uid_t uid);
  28. struct passwd *getpwnam(const char *name);
  29. struct passwd *getpwent(void);
  30. void setpwent(void);
  31. void endpwent(void);
  32. struct group *getgrgid(gid_t gid);
  33. struct group *getgrnam(const char *name);
  34. struct group *getgrent(void);
  35. void setgrent(void);
  36. void endgrent(void);
  37. """)
  38. if __name__ == "__main__":
  39. ffi.compile()