We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
conda env list behavior is inconsistent between Linux/macOS and Windows
## Current Behavior

On UNIX-family operating systems (Linux and macOS), `conda env list` generates a list of all environments belonging to the current user. This behavior changes if `conda` is executed with UID 0, in which case `conda` attempts to find all user home directories on the system and list all environments belonging to all users.

This is not consistent with the behavior on Windows. On Windows, `conda env list` always attempts to find all user home directories on the system, and displays all environments belonging to all users. This occurs whether or not the current user is an administrator.

This behavior is not documented in the Conda user guide, which just says that `conda env list` is used "to see a list of all your environments." https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-your-environments

### Steps to Reproduce

On macOS/Linux, this will list the current user's environments only:

```
conda env list
```

Running this command with `sudo` will list all environments on the system:

```
sudo conda env list
```

On Windows, running this command from either a standard prompt or from an administrative prompts with elevated permissions will list all environments on the system (as long as the executing user can read the environment configuration file for the user that actually owns the environment):

```
conda env list
```

## Expected Behavior

I would expect one of the two following behaviors:

1. `conda env list` only lists the current user's environment on any operating system.
2. `conda env list` only lists the current user's environment, unless it is executed as an administrator. This behavior should be consistent between Windows and macOS. 

The current behavior on Windows (all users) and macOS/Linux (admins) should only be executed for administrators, if at all. In particular, the current Windows code finds all sibling directories of the current user's home folder and tries to check each one of them for an environment configuration file. In environments where Windows home directories are redirected onto a common network share, this may result in `conda env list` firing off a large number of I/O operations as it tries to access all home directories on the network share.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `conda/core/envs_manager.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2012 Anaconda, Inc
3 # SPDX-License-Identifier: BSD-3-Clause
4 from __future__ import absolute_import, division, print_function, unicode_literals
5 
6 from errno import EACCES, EROFS, ENOENT
7 from logging import getLogger
8 from os import devnull, listdir
9 from os.path import dirname, isdir, isfile, join, normpath
10 
11 from .prefix_data import PrefixData
12 from ..base.context import context
13 from ..common.compat import ensure_text_type, on_win, open
14 from ..common.path import expand
15 from ..gateways.disk.read import yield_lines
16 from ..gateways.disk.test import is_conda_environment
17 
18 log = getLogger(__name__)
19 
20 # The idea is to mock this to return '/dev/null' (or some temp file) instead.
21 def get_user_environments_txt_file(userhome='~'):
22     return expand(join(userhome, '.conda', 'environments.txt'))
23 
24 
25 def register_env(location):
26     user_environments_txt_file = get_user_environments_txt_file()
27     location = normpath(location)
28 
29     if ("placehold_pl" in location or "skeleton_" in location
30        or user_environments_txt_file == devnull):
31         # Don't record envs created by conda-build.
32         return
33 
34     if location in yield_lines(user_environments_txt_file):
35         # Nothing to do. Location is already recorded in a known environments.txt file.
36         return
37 
38     try:
39         with open(user_environments_txt_file, 'a') as fh:
40             fh.write(ensure_text_type(location))
41             fh.write('\n')
42     except EnvironmentError as e:
43         if e.errno in (EACCES, EROFS, ENOENT):
44             log.warn("Unable to register environment. Path not writable or missing.\n"
45                      "  environment location: %s\n"
46                      "  registry file: %s", location, user_environments_txt_file)
47         else:
48             raise
49 
50 
51 def unregister_env(location):
52     if isdir(location):
53         meta_dir = join(location, 'conda-meta')
54         if isdir(meta_dir):
55             meta_dir_contents = listdir(meta_dir)
56             if len(meta_dir_contents) > 1:
57                 # if there are any files left other than 'conda-meta/history'
58                 #   then don't unregister
59                 return
60 
61     _clean_environments_txt(get_user_environments_txt_file(), location)
62 
63 
64 def list_all_known_prefixes():
65     all_env_paths = set()
66     if on_win:
67         home_dir_dir = dirname(expand('~'))
68         for home_dir in listdir(home_dir_dir):
69             environments_txt_file = get_user_environments_txt_file(join(home_dir_dir, home_dir))
70             if isfile(environments_txt_file):
71                 all_env_paths.update(_clean_environments_txt(environments_txt_file))
72     else:
73         from os import geteuid
74         from pwd import getpwall
75         if geteuid() == 0:
76             search_dirs = tuple(pwentry.pw_dir for pwentry in getpwall()) or (expand('~'),)
77         else:
78             search_dirs = (expand('~'),)
79         for home_dir in search_dirs:
80             environments_txt_file = get_user_environments_txt_file(home_dir)
81             if isfile(environments_txt_file):
82                 all_env_paths.update(_clean_environments_txt(environments_txt_file))
83 
84     # in case environments.txt files aren't complete, also add all known conda environments in
85     # all envs_dirs
86     envs_dirs = (envs_dir for envs_dir in context.envs_dirs if isdir(envs_dir))
87     all_env_paths.update(path for path in (
88         join(envs_dir, name) for envs_dir in envs_dirs for name in listdir(envs_dir)
89     ) if path not in all_env_paths and is_conda_environment(path))
90 
91     all_env_paths.add(context.root_prefix)
92     return sorted(all_env_paths)
93 
94 
95 def query_all_prefixes(spec):
96     for prefix in list_all_known_prefixes():
97         prefix_recs = tuple(PrefixData(prefix).query(spec))
98         if prefix_recs:
99             yield prefix, prefix_recs
100 
101 
102 def _clean_environments_txt(environments_txt_file, remove_location=None):
103     if not isfile(environments_txt_file):
104         return ()
105 
106     if remove_location:
107         remove_location = normpath(remove_location)
108     environments_txt_lines = tuple(yield_lines(environments_txt_file))
109     environments_txt_lines_cleaned = tuple(
110         prefix for prefix in environments_txt_lines
111         if prefix != remove_location and is_conda_environment(prefix)
112     )
113     if environments_txt_lines_cleaned != environments_txt_lines:
114         _rewrite_environments_txt(environments_txt_file, environments_txt_lines_cleaned)
115     return environments_txt_lines_cleaned
116 
117 
118 def _rewrite_environments_txt(environments_txt_file, prefixes):
119     try:
120         with open(environments_txt_file, 'w') as fh:
121             fh.write('\n'.join(prefixes))
122             fh.write('\n')
123     except EnvironmentError as e:
124         log.info("File not cleaned: %s", environments_txt_file)
125         log.debug('%r', e, exc_info=True)
126
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/conda/core/envs_manager.py b/conda/core/envs_manager.py
--- a/conda/core/envs_manager.py
+++ b/conda/core/envs_manager.py
@@ -11,6 +11,7 @@
 from .prefix_data import PrefixData
 from ..base.context import context
 from ..common.compat import ensure_text_type, on_win, open
+from ..common._os import is_admin
 from ..common.path import expand
 from ..gateways.disk.read import yield_lines
 from ..gateways.disk.test import is_conda_environment
@@ -63,23 +64,21 @@
 
 def list_all_known_prefixes():
     all_env_paths = set()
-    if on_win:
-        home_dir_dir = dirname(expand('~'))
-        for home_dir in listdir(home_dir_dir):
-            environments_txt_file = get_user_environments_txt_file(join(home_dir_dir, home_dir))
-            if isfile(environments_txt_file):
-                all_env_paths.update(_clean_environments_txt(environments_txt_file))
-    else:
-        from os import geteuid
-        from pwd import getpwall
-        if geteuid() == 0:
-            search_dirs = tuple(pwentry.pw_dir for pwentry in getpwall()) or (expand('~'),)
+    # If the user is an admin, load environments from all user home directories
+    if is_admin():
+        if on_win:
+            home_dir_dir = dirname(expand('~'))
+            search_dirs = tuple(join(home_dir_dir, d) for d in listdir(home_dir_dir))
         else:
-            search_dirs = (expand('~'),)
-        for home_dir in search_dirs:
-            environments_txt_file = get_user_environments_txt_file(home_dir)
-            if isfile(environments_txt_file):
-                all_env_paths.update(_clean_environments_txt(environments_txt_file))
+            from pwd import getpwall
+            search_dirs = tuple(pwentry.pw_dir for pwentry in getpwall()) or (expand('~'),)
+    else:
+        search_dirs = (expand('~'),)
+    for home_dir in search_dirs:
+        environments_txt_file = get_user_environments_txt_file(home_dir)
+        if isfile(environments_txt_file):
+            all_env_paths.update(_clean_environments_txt(environments_txt_file))
+
 
     # in case environments.txt files aren't complete, also add all known conda environments in
     # all envs_dirs

{"golden_diff": "diff --git a/conda/core/envs_manager.py b/conda/core/envs_manager.py\n--- a/conda/core/envs_manager.py\n+++ b/conda/core/envs_manager.py\n@@ -11,6 +11,7 @@\n from .prefix_data import PrefixData\n from ..base.context import context\n from ..common.compat import ensure_text_type, on_win, open\n+from ..common._os import is_admin\n from ..common.path import expand\n from ..gateways.disk.read import yield_lines\n from ..gateways.disk.test import is_conda_environment\n@@ -63,23 +64,21 @@\n \n def list_all_known_prefixes():\n     all_env_paths = set()\n-    if on_win:\n-        home_dir_dir = dirname(expand('~'))\n-        for home_dir in listdir(home_dir_dir):\n-            environments_txt_file = get_user_environments_txt_file(join(home_dir_dir, home_dir))\n-            if isfile(environments_txt_file):\n-                all_env_paths.update(_clean_environments_txt(environments_txt_file))\n-    else:\n-        from os import geteuid\n-        from pwd import getpwall\n-        if geteuid() == 0:\n-            search_dirs = tuple(pwentry.pw_dir for pwentry in getpwall()) or (expand('~'),)\n+    # If the user is an admin, load environments from all user home directories\n+    if is_admin():\n+        if on_win:\n+            home_dir_dir = dirname(expand('~'))\n+            search_dirs = tuple(join(home_dir_dir, d) for d in listdir(home_dir_dir))\n         else:\n-            search_dirs = (expand('~'),)\n-        for home_dir in search_dirs:\n-            environments_txt_file = get_user_environments_txt_file(home_dir)\n-            if isfile(environments_txt_file):\n-                all_env_paths.update(_clean_environments_txt(environments_txt_file))\n+            from pwd import getpwall\n+            search_dirs = tuple(pwentry.pw_dir for pwentry in getpwall()) or (expand('~'),)\n+    else:\n+        search_dirs = (expand('~'),)\n+    for home_dir in search_dirs:\n+        environments_txt_file = get_user_environments_txt_file(home_dir)\n+        if isfile(environments_txt_file):\n+            all_env_paths.update(_clean_environments_txt(environments_txt_file))\n+\n \n     # in case environments.txt files aren't complete, also add all known conda environments in\n     # all envs_dirs\n", "issue": "conda env list behavior is inconsistent between Linux/macOS and Windows\n## Current Behavior\r\n\r\nOn UNIX-family operating systems (Linux and macOS), `conda env list` generates a list of all environments belonging to the current user. This behavior changes if `conda` is executed with UID 0, in which case `conda` attempts to find all user home directories on the system and list all environments belonging to all users.\r\n\r\nThis is not consistent with the behavior on Windows. On Windows, `conda env list` always attempts to find all user home directories on the system, and displays all environments belonging to all users. This occurs whether or not the current user is an administrator.\r\n\r\nThis behavior is not documented in the Conda user guide, which just says that `conda env list` is used \"to see a list of all your environments.\" https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-your-environments\r\n\r\n### Steps to Reproduce\r\n\r\nOn macOS/Linux, this will list the current user's environments only:\r\n\r\n```\r\nconda env list\r\n```\r\n\r\nRunning this command with `sudo` will list all environments on the system:\r\n\r\n```\r\nsudo conda env list\r\n```\r\n\r\nOn Windows, running this command from either a standard prompt or from an administrative prompts with elevated permissions will list all environments on the system (as long as the executing user can read the environment configuration file for the user that actually owns the environment):\r\n\r\n```\r\nconda env list\r\n```\r\n\r\n## Expected Behavior\r\n\r\nI would expect one of the two following behaviors:\r\n\r\n1. `conda env list` only lists the current user's environment on any operating system.\r\n2. `conda env list` only lists the current user's environment, unless it is executed as an administrator. This behavior should be consistent between Windows and macOS. \r\n\r\nThe current behavior on Windows (all users) and macOS/Linux (admins) should only be executed for administrators, if at all. In particular, the current Windows code finds all sibling directories of the current user's home folder and tries to check each one of them for an environment configuration file. In environments where Windows home directories are redirected onto a common network share, this may result in `conda env list` firing off a large number of I/O operations as it tries to access all home directories on the network share.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright (C) 2012 Anaconda, Inc\n# SPDX-License-Identifier: BSD-3-Clause\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom errno import EACCES, EROFS, ENOENT\nfrom logging import getLogger\nfrom os import devnull, listdir\nfrom os.path import dirname, isdir, isfile, join, normpath\n\nfrom .prefix_data import PrefixData\nfrom ..base.context import context\nfrom ..common.compat import ensure_text_type, on_win, open\nfrom ..common.path import expand\nfrom ..gateways.disk.read import yield_lines\nfrom ..gateways.disk.test import is_conda_environment\n\nlog = getLogger(__name__)\n\n# The idea is to mock this to return '/dev/null' (or some temp file) instead.\ndef get_user_environments_txt_file(userhome='~'):\n    return expand(join(userhome, '.conda', 'environments.txt'))\n\n\ndef register_env(location):\n    user_environments_txt_file = get_user_environments_txt_file()\n    location = normpath(location)\n\n    if (\"placehold_pl\" in location or \"skeleton_\" in location\n       or user_environments_txt_file == devnull):\n        # Don't record envs created by conda-build.\n        return\n\n    if location in yield_lines(user_environments_txt_file):\n        # Nothing to do. Location is already recorded in a known environments.txt file.\n        return\n\n    try:\n        with open(user_environments_txt_file, 'a') as fh:\n            fh.write(ensure_text_type(location))\n            fh.write('\\n')\n    except EnvironmentError as e:\n        if e.errno in (EACCES, EROFS, ENOENT):\n            log.warn(\"Unable to register environment. Path not writable or missing.\\n\"\n                     \"  environment location: %s\\n\"\n                     \"  registry file: %s\", location, user_environments_txt_file)\n        else:\n            raise\n\n\ndef unregister_env(location):\n    if isdir(location):\n        meta_dir = join(location, 'conda-meta')\n        if isdir(meta_dir):\n            meta_dir_contents = listdir(meta_dir)\n            if len(meta_dir_contents) > 1:\n                # if there are any files left other than 'conda-meta/history'\n                #   then don't unregister\n                return\n\n    _clean_environments_txt(get_user_environments_txt_file(), location)\n\n\ndef list_all_known_prefixes():\n    all_env_paths = set()\n    if on_win:\n        home_dir_dir = dirname(expand('~'))\n        for home_dir in listdir(home_dir_dir):\n            environments_txt_file = get_user_environments_txt_file(join(home_dir_dir, home_dir))\n            if isfile(environments_txt_file):\n                all_env_paths.update(_clean_environments_txt(environments_txt_file))\n    else:\n        from os import geteuid\n        from pwd import getpwall\n        if geteuid() == 0:\n            search_dirs = tuple(pwentry.pw_dir for pwentry in getpwall()) or (expand('~'),)\n        else:\n            search_dirs = (expand('~'),)\n        for home_dir in search_dirs:\n            environments_txt_file = get_user_environments_txt_file(home_dir)\n            if isfile(environments_txt_file):\n                all_env_paths.update(_clean_environments_txt(environments_txt_file))\n\n    # in case environments.txt files aren't complete, also add all known conda environments in\n    # all envs_dirs\n    envs_dirs = (envs_dir for envs_dir in context.envs_dirs if isdir(envs_dir))\n    all_env_paths.update(path for path in (\n        join(envs_dir, name) for envs_dir in envs_dirs for name in listdir(envs_dir)\n    ) if path not in all_env_paths and is_conda_environment(path))\n\n    all_env_paths.add(context.root_prefix)\n    return sorted(all_env_paths)\n\n\ndef query_all_prefixes(spec):\n    for prefix in list_all_known_prefixes():\n        prefix_recs = tuple(PrefixData(prefix).query(spec))\n        if prefix_recs:\n            yield prefix, prefix_recs\n\n\ndef _clean_environments_txt(environments_txt_file, remove_location=None):\n    if not isfile(environments_txt_file):\n        return ()\n\n    if remove_location:\n        remove_location = normpath(remove_location)\n    environments_txt_lines = tuple(yield_lines(environments_txt_file))\n    environments_txt_lines_cleaned = tuple(\n        prefix for prefix in environments_txt_lines\n        if prefix != remove_location and is_conda_environment(prefix)\n    )\n    if environments_txt_lines_cleaned != environments_txt_lines:\n        _rewrite_environments_txt(environments_txt_file, environments_txt_lines_cleaned)\n    return environments_txt_lines_cleaned\n\n\ndef _rewrite_environments_txt(environments_txt_file, prefixes):\n    try:\n        with open(environments_txt_file, 'w') as fh:\n            fh.write('\\n'.join(prefixes))\n            fh.write('\\n')\n    except EnvironmentError as e:\n        log.info(\"File not cleaned: %s\", environments_txt_file)\n        log.debug('%r', e, exc_info=True)\n", "path": "conda/core/envs_manager.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright (C) 2012 Anaconda, Inc\n# SPDX-License-Identifier: BSD-3-Clause\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom errno import EACCES, EROFS, ENOENT\nfrom logging import getLogger\nfrom os import devnull, listdir\nfrom os.path import dirname, isdir, isfile, join, normpath\n\nfrom .prefix_data import PrefixData\nfrom ..base.context import context\nfrom ..common.compat import ensure_text_type, on_win, open\nfrom ..common._os import is_admin\nfrom ..common.path import expand\nfrom ..gateways.disk.read import yield_lines\nfrom ..gateways.disk.test import is_conda_environment\n\nlog = getLogger(__name__)\n\n# The idea is to mock this to return '/dev/null' (or some temp file) instead.\ndef get_user_environments_txt_file(userhome='~'):\n    return expand(join(userhome, '.conda', 'environments.txt'))\n\n\ndef register_env(location):\n    user_environments_txt_file = get_user_environments_txt_file()\n    location = normpath(location)\n\n    if (\"placehold_pl\" in location or \"skeleton_\" in location\n       or user_environments_txt_file == devnull):\n        # Don't record envs created by conda-build.\n        return\n\n    if location in yield_lines(user_environments_txt_file):\n        # Nothing to do. Location is already recorded in a known environments.txt file.\n        return\n\n    try:\n        with open(user_environments_txt_file, 'a') as fh:\n            fh.write(ensure_text_type(location))\n            fh.write('\\n')\n    except EnvironmentError as e:\n        if e.errno in (EACCES, EROFS, ENOENT):\n            log.warn(\"Unable to register environment. Path not writable or missing.\\n\"\n                     \"  environment location: %s\\n\"\n                     \"  registry file: %s\", location, user_environments_txt_file)\n        else:\n            raise\n\n\ndef unregister_env(location):\n    if isdir(location):\n        meta_dir = join(location, 'conda-meta')\n        if isdir(meta_dir):\n            meta_dir_contents = listdir(meta_dir)\n            if len(meta_dir_contents) > 1:\n                # if there are any files left other than 'conda-meta/history'\n                #   then don't unregister\n                return\n\n    _clean_environments_txt(get_user_environments_txt_file(), location)\n\n\ndef list_all_known_prefixes():\n    all_env_paths = set()\n    # If the user is an admin, load environments from all user home directories\n    if is_admin():\n        if on_win:\n            home_dir_dir = dirname(expand('~'))\n            search_dirs = tuple(join(home_dir_dir, d) for d in listdir(home_dir_dir))\n        else:\n            from pwd import getpwall\n            search_dirs = tuple(pwentry.pw_dir for pwentry in getpwall()) or (expand('~'),)\n    else:\n        search_dirs = (expand('~'),)\n    for home_dir in search_dirs:\n        environments_txt_file = get_user_environments_txt_file(home_dir)\n        if isfile(environments_txt_file):\n            all_env_paths.update(_clean_environments_txt(environments_txt_file))\n\n\n    # in case environments.txt files aren't complete, also add all known conda environments in\n    # all envs_dirs\n    envs_dirs = (envs_dir for envs_dir in context.envs_dirs if isdir(envs_dir))\n    all_env_paths.update(path for path in (\n        join(envs_dir, name) for envs_dir in envs_dirs for name in listdir(envs_dir)\n    ) if path not in all_env_paths and is_conda_environment(path))\n\n    all_env_paths.add(context.root_prefix)\n    return sorted(all_env_paths)\n\n\ndef query_all_prefixes(spec):\n    for prefix in list_all_known_prefixes():\n        prefix_recs = tuple(PrefixData(prefix).query(spec))\n        if prefix_recs:\n            yield prefix, prefix_recs\n\n\ndef _clean_environments_txt(environments_txt_file, remove_location=None):\n    if not isfile(environments_txt_file):\n        return ()\n\n    if remove_location:\n        remove_location = normpath(remove_location)\n    environments_txt_lines = tuple(yield_lines(environments_txt_file))\n    environments_txt_lines_cleaned = tuple(\n        prefix for prefix in environments_txt_lines\n        if prefix != remove_location and is_conda_environment(prefix)\n    )\n    if environments_txt_lines_cleaned != environments_txt_lines:\n        _rewrite_environments_txt(environments_txt_file, environments_txt_lines_cleaned)\n    return environments_txt_lines_cleaned\n\n\ndef _rewrite_environments_txt(environments_txt_file, prefixes):\n    try:\n        with open(environments_txt_file, 'w') as fh:\n            fh.write('\\n'.join(prefixes))\n            fh.write('\\n')\n    except EnvironmentError as e:\n        log.info(\"File not cleaned: %s\", environments_txt_file)\n        log.debug('%r', e, exc_info=True)\n", "path": "conda/core/envs_manager.py"}]}