Mercurial > vim
comparison src/misc1.c @ 14698:d2cfca5b178e v8.1.0361
patch 8.1.0361: remote user not used for completion
commit https://github.com/vim/vim/commit/6b0b83f768cf536b34ce4d3f2de6bf62324229aa
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 10 19:03:05 2018 +0200
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 https://github.com/vim/vim/issues/3407)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 10 Sep 2018 19:15:05 +0200 |
parents | 100a44722322 |
children | f562b9fbd0d3 |
comparison
equal
deleted
inserted
replaced
14697:3169382f089a | 14698:d2cfca5b178e |
---|---|
4715 return name; | 4715 return name; |
4716 # endif | 4716 # endif |
4717 } | 4717 } |
4718 | 4718 |
4719 /* | 4719 /* |
4720 * Add a user name to the list of users in ga_users. | |
4721 * Do nothing if user name is NULL or empty. | |
4722 */ | |
4723 static void | |
4724 add_user(char_u *user, int need_copy) | |
4725 { | |
4726 char_u *user_copy = (user != NULL && need_copy) | |
4727 ? vim_strsave(user) : user; | |
4728 | |
4729 if (user_copy == NULL || *user_copy == NUL || ga_grow(&ga_users, 1) == FAIL) | |
4730 { | |
4731 if (need_copy) | |
4732 vim_free(user); | |
4733 return; | |
4734 } | |
4735 ((char_u **)(ga_users.ga_data))[ga_users.ga_len++] = user_copy; | |
4736 } | |
4737 | |
4738 /* | |
4720 * Find all user names for user completion. | 4739 * Find all user names for user completion. |
4721 * Done only once and then cached. | 4740 * Done only once and then cached. |
4722 */ | 4741 */ |
4723 static void | 4742 static void |
4724 init_users(void) | 4743 init_users(void) |
4731 lazy_init_done = TRUE; | 4750 lazy_init_done = TRUE; |
4732 ga_init2(&ga_users, sizeof(char_u *), 20); | 4751 ga_init2(&ga_users, sizeof(char_u *), 20); |
4733 | 4752 |
4734 # if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H) | 4753 # if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H) |
4735 { | 4754 { |
4736 char_u* user; | |
4737 struct passwd* pw; | 4755 struct passwd* pw; |
4738 | 4756 |
4739 setpwent(); | 4757 setpwent(); |
4740 while ((pw = getpwent()) != NULL) | 4758 while ((pw = getpwent()) != NULL) |
4741 /* pw->pw_name shouldn't be NULL but just in case... */ | 4759 add_user((char_u *)pw->pw_name, TRUE); |
4742 if (pw->pw_name != NULL) | |
4743 { | |
4744 if (ga_grow(&ga_users, 1) == FAIL) | |
4745 break; | |
4746 user = vim_strsave((char_u*)pw->pw_name); | |
4747 if (user == NULL) | |
4748 break; | |
4749 ((char_u **)(ga_users.ga_data))[ga_users.ga_len++] = user; | |
4750 } | |
4751 endpwent(); | 4760 endpwent(); |
4752 } | 4761 } |
4753 # elif defined(WIN3264) | 4762 # elif defined(WIN3264) |
4754 { | 4763 { |
4755 char_u* user; | |
4756 DWORD nusers = 0, ntotal = 0, i; | 4764 DWORD nusers = 0, ntotal = 0, i; |
4757 PUSER_INFO_0 uinfo; | 4765 PUSER_INFO_0 uinfo; |
4758 | 4766 |
4759 if (NetUserEnum(NULL, 0, 0, (LPBYTE *) &uinfo, MAX_PREFERRED_LENGTH, | 4767 if (NetUserEnum(NULL, 0, 0, (LPBYTE *) &uinfo, MAX_PREFERRED_LENGTH, |
4760 &nusers, &ntotal, NULL) == NERR_Success) | 4768 &nusers, &ntotal, NULL) == NERR_Success) |
4761 { | 4769 { |
4762 for (i = 0; i < nusers; i++) | 4770 for (i = 0; i < nusers; i++) |
4763 { | 4771 add_user(utf16_to_enc(uinfo[i].usri0_name, NULL), FALSE); |
4764 if (ga_grow(&ga_users, 1) == FAIL) | 4772 |
4773 NetApiBufferFree(uinfo); | |
4774 } | |
4775 } | |
4776 # endif | |
4777 # if defined(HAVE_GETPWNAM) | |
4778 { | |
4779 char_u *user_env = mch_getenv((char_u *)"USER"); | |
4780 | |
4781 // The $USER environment variable may be a valid remote user name (NIS, | |
4782 // LDAP) not already listed by getpwent(), as getpwent() only lists | |
4783 // local user names. If $USER is not already listed, check whether it | |
4784 // is a valid remote user name using getpwnam() and if it is, add it to | |
4785 // the list of user names. | |
4786 | |
4787 if (user_env != NULL && *user_env != NUL) | |
4788 { | |
4789 int i; | |
4790 | |
4791 for (i = 0; i < ga_users.ga_len; i++) | |
4792 { | |
4793 char_u *local_user = ((char_u **)ga_users.ga_data)[i]; | |
4794 | |
4795 if (STRCMP(local_user, user_env) == 0) | |
4765 break; | 4796 break; |
4766 user = utf16_to_enc(uinfo[i].usri0_name, NULL); | 4797 } |
4767 if (user == NULL) | 4798 |
4768 break; | 4799 if (i == ga_users.ga_len) |
4769 ((char_u **)(ga_users.ga_data))[ga_users.ga_len++] = user; | 4800 { |
4770 } | 4801 struct passwd *pw = getpwnam((char *)user_env); |
4771 | 4802 |
4772 NetApiBufferFree(uinfo); | 4803 if (pw != NULL) |
4804 add_user((char_u *)pw->pw_name, TRUE); | |
4805 } | |
4773 } | 4806 } |
4774 } | 4807 } |
4775 # endif | 4808 # endif |
4776 } | 4809 } |
4777 | 4810 |