PageRenderTime 56ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/src/util/username.c

https://bitbucket.org/jlh/postfix-xtls_policy
C | 47 lines | 13 code | 7 blank | 27 comment | 2 complexity | 124e6fcf895def5e573765bea7b8814d MD5 | raw file
Possible License(s): IPL-1.0, AGPL-3.0
  1. /*++
  2. /* NAME
  3. /* username 3
  4. /* SUMMARY
  5. /* lookup name of real user
  6. /* SYNOPSIS
  7. /* #include <username.h>
  8. /*
  9. /* const char *username()
  10. /* DESCRIPTION
  11. /* username() jumps whatever system-specific hoops it takes to
  12. /* get the name of the user who started the process. The result
  13. /* is volatile. Make a copy if it is to be used for an appreciable
  14. /* amount of time.
  15. /* LICENSE
  16. /* .ad
  17. /* .fi
  18. /* The Secure Mailer license must be distributed with this software.
  19. /* AUTHOR(S)
  20. /* Wietse Venema
  21. /* IBM T.J. Watson Research
  22. /* P.O. Box 704
  23. /* Yorktown Heights, NY 10598, USA
  24. /*--*/
  25. /* System library. */
  26. #include <sys_defs.h>
  27. #include <unistd.h>
  28. #include <pwd.h>
  29. /* Utility library. */
  30. #include "username.h"
  31. /* username - get name of user */
  32. const char *username(void)
  33. {
  34. uid_t uid;
  35. struct passwd *pwd;
  36. uid = getuid();
  37. if ((pwd = getpwuid(uid)) == 0)
  38. return (0);
  39. return (pwd->pw_name);
  40. }