- if (!strcmp(name, "UserName")) {\r
- /*\r
- * Remote login username will default to the local username.\r
- */\r
- struct passwd *p;\r
- uid_t uid = getuid();\r
- char *user, *ret = NULL;\r
-\r
- /*\r
- * First, find who we think we are using getlogin. If this\r
- * agrees with our uid, we'll go along with it. This should\r
- * allow sharing of uids between several login names whilst\r
- * coping correctly with people who have su'ed.\r
- */\r
- user = getlogin();\r
- setpwent();\r
- if (user)\r
- p = getpwnam(user);\r
- else\r
- p = NULL;\r
- if (p && p->pw_uid == uid) {\r
- /*\r
- * The result of getlogin() really does correspond to\r
- * our uid. Fine.\r
- */\r
- ret = user;\r
- } else {\r
- /*\r
- * If that didn't work, for whatever reason, we'll do\r
- * the simpler version: look up our uid in the password\r
- * file and map it straight to a name.\r
- */\r
- p = getpwuid(uid);\r
- ret = p->pw_name;\r
- }\r
- endpwent();\r
-\r
- return ret;\r
- }\r