#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
"""
Generic implementation of OS support for most unix-derived OSs.
In general, if os.type is "posix", most if not all of these methods
can be used. For any that are unusable (or where a better
implementation exists), a module can be provided which overrides
these.
"""
import pwd
import grp
import errno
import os
import platform
import shutil
import stat
import sys
import tempfile
# used to cache contents of passwd and group files
users = {}
uids = {}
users_lastupdate = {}
groups = {}
gids = {}
groups_lastupdate = {}
# storage to repeat first call to group routines
__been_here = {}
def already_called():
if callers_name in __been_here:
return True
else:
return False
def get_isainfo():
def get_release():
return os_util.get_os_release()
def get_platform():
def get_userid():
"""To be used for display purposes only!"""
# If the software is being executed with pfexec, the uid or euid will
# likely be 0 which is of no use. Since the os.getlogin() interface
# provided by Python breaks in a number of interesting ways, their
# recommendation is to pull the username from the environment instead.
if user:
try:
except KeyError:
# The environment username wasn't valid.
pass
def get_username():
"""To be used for display purposes only!"""
if not already_called():
def is_admin():
if not already_called():
if not use_file:
try:
except OSError as e:
raise
# If the password file doesn't exist, bootstrap
# ourselves from the current environment.
except KeyError:
if not already_called():
if not use_file:
try:
except OSError as e:
raise
# If the password file doesn't exist, bootstrap
# ourselves from the current environment.
except KeyError:
if not already_called():
if not use_file:
try:
except OSError as e:
raise
# If the password file doesn't exist, bootstrap
# ourselves from the current environment.
except KeyError:
if not already_called():
if not use_file:
try:
except OSError as e:
raise
# If the password file doesn't exist, bootstrap
# ourselves from the current environment.
except KeyError:
if not already_called():
try:
return [unam
]
except OSError as e:
raise
# If the password file doesn't exist, bootstrap
# ourselves from the current environment.
# The following call could be expensive.
if not allpwdentries:
allpwdentries = []
return [
for pwdentry in allpwdentries
]
# check if we need to reload cache
return
f = open(passwd_file)
for line in f:
# Skip any line we can't make sense of.
continue
try:
except ValueError:
# Skip any line we can't make sense of.
continue
# Traditional systems allow multiple users to have the same
# user id, so only the first one should be mapped to the
# current pw_entry.
f.close()
# check if we need to reload cache
return
f = open(group_file)
for line in f:
# Skip any line we can't make sense of.
continue
try:
except ValueError:
# Skip any line we can't make sense of.
continue
# Traditional systems allow multiple groups to have the same
# group id, so only the first one should be mapped to the
# current pw_entry.
f.close()
try:
except OSError as e:
# Handle the case where we tried to rename a file across a
# filesystem boundary.
raise
# Copy the data and metadata into a temporary file in the same
# filesystem as the destination, rename into place, and unlink
# the original.
try:
except OSError as e:
# If we don't have sufficient permissions to put the
# file where we want it, then higher levels can deal
# with that effectively, but people will want to know
# the original destination filename.
raise
return '/'
raise ae