my_getpwnam.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License, version 2.0,
  5. as published by the Free Software Foundation.
  6. This program is also distributed with certain software (including
  7. but not limited to OpenSSL) that is licensed under separate terms,
  8. as designated in a particular file or component or in included license
  9. documentation. The authors of MySQL hereby grant you an additional
  10. permission to link the program and your derivative works with the
  11. separately licensed software that they have included with MySQL.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License, version 2.0, for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  19. #ifndef MY_GETPWNAM_INCLUDED
  20. #define MY_GETPWNAM_INCLUDED
  21. /**
  22. @file include/my_getpwnam.h
  23. */
  24. #include <string>
  25. #include "my_config.h"
  26. #ifdef HAVE_GETPWNAM
  27. #include <pwd.h>
  28. #include <sys/types.h>
  29. /**
  30. Shadow struct for passwd which has proper value semantics, so that
  31. it can be safely copied and assigned to.
  32. */
  33. struct PasswdValue {
  34. std::string pw_name;
  35. std::string pw_passwd;
  36. uid_t pw_uid{0};
  37. gid_t pw_gid{0};
  38. std::string pw_gecos;
  39. std::string pw_dir;
  40. std::string pw_shell;
  41. /** Constructs from a passwd instance. */
  42. PasswdValue(const passwd &p)
  43. : pw_name{p.pw_name},
  44. pw_passwd{p.pw_passwd},
  45. pw_uid{p.pw_uid},
  46. pw_gid{p.pw_gid},
  47. pw_gecos{p.pw_gecos},
  48. pw_dir{p.pw_dir},
  49. pw_shell{p.pw_shell} {}
  50. /** Default constructor creates a void value. */
  51. PasswdValue() = default;
  52. /**
  53. Returns true if this PasswdValue instance does not represent a
  54. real passwd entry.
  55. */
  56. bool IsVoid() const { return pw_name.empty(); }
  57. };
  58. PasswdValue my_getpwnam(const char *);
  59. PasswdValue my_getpwuid(uid_t);
  60. #endif /* HAVE_GETPWNAM */
  61. #endif // MY_GETPWNAM_INCLUDED