This file is indexed.

/usr/lib/python2.7/dist-packages/nss_cache/nss.py is in nsscache 0.32-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# Copyright 2007 Google Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

"""NSS utility library."""

__author__ = 'vasilios@google.com (Vasilios Hoffman)'

import grp
import logging
import pwd
import subprocess

from nss_cache import config
from nss_cache import error
from nss_cache.maps import group
from nss_cache.maps import passwd
from nss_cache.maps import shadow

# TODO(v): this should be a config option someday, but it's as standard
# as libc so at the moment we'll leave it be for simplicity.
GETENT = '/usr/bin/getent'


def GetMap(map_name):
  """Retrieves a Map of type map_name via nss calls."""

  if map_name == config.MAP_PASSWORD:
    return GetPasswdMap()
  elif map_name == config.MAP_GROUP:
    return GetGroupMap()
  elif map_name == config.MAP_SHADOW:
    return GetShadowMap()

  raise error.UnsupportedMap


def GetPasswdMap():
  """Returns a PasswdMap built from nss calls."""
  passwd_map = passwd.PasswdMap()

  for nss_entry in pwd.getpwall():
    map_entry = passwd.PasswdMapEntry()
    map_entry.name = nss_entry[0]
    map_entry.passwd = nss_entry[1]
    map_entry.uid = nss_entry[2]
    map_entry.gid = nss_entry[3]
    map_entry.gecos = nss_entry[4]
    map_entry.dir = nss_entry[5]
    map_entry.shell = nss_entry[6]
    passwd_map.Add(map_entry)

  return passwd_map


def GetGroupMap():
  """Returns a GroupMap built from nss calls."""
  group_map = group.GroupMap()

  for nss_entry in grp.getgrall():
    map_entry = group.GroupMapEntry()
    map_entry.name = nss_entry[0]
    map_entry.passwd = nss_entry[1]
    map_entry.gid = nss_entry[2]
    map_entry.members = nss_entry[3]
    if not map_entry.members:
      map_entry.members = ['']
    group_map.Add(map_entry)

  return group_map


def GetShadowMap():
  """Returns a ShadowMap built from nss calls."""
  getent = _SpawnGetent(config.MAP_SHADOW)
  (getent_stdout, getent_stderr) = getent.communicate()

  # The following is going to be map-specific each time, so no point in
  # making more methods.
  shadow_map = shadow.ShadowMap()

  for line in getent_stdout.split():
    nss_entry = line.strip().split(':')
    map_entry = shadow.ShadowMapEntry()
    map_entry.name = nss_entry[0]
    map_entry.passwd = nss_entry[1]
    if nss_entry[2] != '':
      map_entry.lstchg = int(nss_entry[2])
    if nss_entry[3] != '':
      map_entry.min = int(nss_entry[3])
    if nss_entry[4] != '':
      map_entry.max = int(nss_entry[4])
    if nss_entry[5] != '':
      map_entry.warn = int(nss_entry[5])
    if nss_entry[6] != '':
      map_entry.inact = int(nss_entry[6])
    if nss_entry[7] != '':
      map_entry.expire = int(nss_entry[7])
    if nss_entry[8] != '':
      map_entry.flag = int(nss_entry[8])
    shadow_map.Add(map_entry)

  if getent_stderr:
    logging.debug('captured error %s', getent_stderr)

  retval = getent.returncode

  if retval != 0:
    logging.warning('%s returned error code: %d', GETENT, retval)

  return shadow_map


def _SpawnGetent(map_name):
  """Run 'getent map' in a subprocess for reading NSS data."""
  getent = subprocess.Popen([GETENT, map_name],
                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)

  return getent