aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorerw7 <erw7.github@gmail.com>2019-10-14 14:44:18 +0900
committererw7 <erw7.github@gmail.com>2019-10-14 15:07:10 +0900
commit8add4cb8fd39b0f6462f0dc064c7534d66326faf (patch)
treea3edb70642f4c773ccc4e1ebc02cf17dc54b7f15 /src
parentb89e970cfb472af021e56438a5147dd698e66376 (diff)
downloadrneovim-8add4cb8fd39b0f6462f0dc064c7534d66326faf.tar.gz
rneovim-8add4cb8fd39b0f6462f0dc064c7534d66326faf.tar.bz2
rneovim-8add4cb8fd39b0f6462f0dc064c7534d66326faf.zip
vim-patch 8.1.0361: remote user not used for completion
Problem: Remote user not used for completion. (Stucki) Solution: Use $USER too. (Dominique Pelle, closes #3407) https://github.com/vim/vim/commit/6b0b83f768cf536b34ce4d3f2de6bf62324229aa
Diffstat (limited to 'src')
-rw-r--r--src/nvim/os/users.c62
1 files changed, 54 insertions, 8 deletions
diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c
index b24232b680..9374693550 100644
--- a/src/nvim/os/users.c
+++ b/src/nvim/os/users.c
@@ -17,6 +17,22 @@
# include <lm.h>
#endif
+// Add a user name to the list of users in garray_T *users.
+// Do nothing if user name is NULL or empty.
+static void add_user(garray_T *users, char *user, bool need_copy)
+{
+ char *user_copy = (user != NULL && need_copy)
+ ? xstrdup(user) : user;
+
+ if (user_copy == NULL || *user_copy == NUL) {
+ if (need_copy) {
+ xfree(user);
+ }
+ return;
+ }
+ GA_APPEND(char *, users, user_copy);
+}
+
// Initialize users garray and fill it with os usernames.
// Return Ok for success, FAIL for failure.
int os_get_usernames(garray_T *users)
@@ -27,16 +43,15 @@ int os_get_usernames(garray_T *users)
ga_init(users, sizeof(char *), 20);
# if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H)
- struct passwd *pw;
+ {
+ struct passwd *pw;
- setpwent();
- while ((pw = getpwent()) != NULL) {
- // pw->pw_name shouldn't be NULL but just in case...
- if (pw->pw_name != NULL) {
- GA_APPEND(char *, users, xstrdup(pw->pw_name));
+ setpwent();
+ while ((pw = getpwent()) != NULL) {
+ add_user(users, pw->pw_name, true);
}
+ endpwent();
}
- endpwent();
# elif defined(WIN32)
{
DWORD nusers = 0, ntotal = 0, i;
@@ -51,13 +66,44 @@ int os_get_usernames(garray_T *users)
EMSG2("utf16_to_utf8 failed: %d", conversion_result);
break;
}
- GA_APPEND(char *, users, user);
+ add_user(users, user, false);
}
NetApiBufferFree(uinfo);
}
}
# endif
+# if defined(HAVE_GETPWNAM)
+ {
+ const char *user_env = os_getenv("USER");
+
+ // The $USER environment variable may be a valid remote user name (NIS,
+ // LDAP) not already listed by getpwent(), as getpwent() only lists
+ // local user names. If $USER is not already listed, check whether it
+ // is a valid remote user name using getpwnam() and if it is, add it to
+ // the list of user names.
+
+ if (user_env != NULL && *user_env != NUL) {
+ int i;
+
+ for (i = 0; i < users->ga_len; i++) {
+ char *local_user = ((char **)users->ga_data)[i];
+
+ if (STRCMP(local_user, user_env) == 0) {
+ break;
+ }
+ }
+
+ if (i == users->ga_len) {
+ struct passwd *pw = getpwnam(user_env); // NOLINT
+
+ if (pw != NULL) {
+ add_user(users, pw->pw_name, true);
+ }
+ }
+ }
+ }
+# endif
return OK;
}