亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? su.c

?? linux開發(fā)技術詳解一書的源碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* su for GNU.  Run a shell with substitute user and group IDs.
   Copyright (C) 1992-2002 Free Software Foundation, 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

/* Run a shell with the real and effective UID and GID and groups
   of USER, default `root'.

   The shell run is taken from USER's password entry, /bin/sh if
   none is specified there.  If the account has a password, su
   prompts for a password unless run by a user with real UID 0.

   Does not change the current directory.
   Sets `HOME' and `SHELL' from the password entry for USER, and if
   USER is not root, sets `USER' and `LOGNAME' to USER.
   The subshell is not a login shell.

   If one or more ARGs are given, they are passed as additional
   arguments to the subshell.

   Does not handle /bin/sh or other shells specially
   (setting argv[0] to "-su", passing -c only to certain shells, etc.).
   I don't see the point in doing that, and it's ugly.

   This program intentionally does not support a "wheel group" that
   restricts who can su to UID 0 accounts.  RMS considers that to
   be fascist.

#ifdef USE_PAM

   Actually, with PAM, su has nothing to do with whether or not a
   wheel group is enforced by su.  RMS tries to restrict your access
   to a su which implements the wheel group, but PAM considers that
   to be fascist, and gives the user/sysadmin the opportunity to
   enforce a wheel group by proper editing of /etc/pam.conf

#endif

   Options:
   -, -l, --login	Make the subshell a login shell.
			Unset all environment variables except
			TERM, HOME and SHELL (set as above), and USER
			and LOGNAME (set unconditionally as above), and
			set PATH to a default value.
			Change to USER's home directory.
			Prepend "-" to the shell's name.
   -c, --commmand=COMMAND
			Pass COMMAND to the subshell with a -c option
			instead of starting an interactive shell.
   -f, --fast		Pass the -f option to the subshell.
   -m, -p, --preserve-environment
			Do not change HOME, USER, LOGNAME, SHELL.
			Run $SHELL instead of USER's shell from /etc/passwd
			unless not the superuser and USER's shell is
			restricted.
			Overridden by --login and --shell.
   -s, --shell=shell	Run SHELL instead of USER's shell from /etc/passwd
			unless not the superuser and USER's shell is
			restricted.

   Compile-time options:
   -DSYSLOG_SUCCESS	Log successful su's (by default, to root) with syslog.
   -DSYSLOG_FAILURE	Log failed su's (by default, to root) with syslog.

   -DSYSLOG_NON_ROOT	Log all su's, not just those to root (UID 0).
   Never logs attempted su's to nonexistent accounts.

   Written by David MacKenzie <djm@gnu.ai.mit.edu>.  */

#include <config.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>

/* Hide any system prototype for getusershell.
   This is necessary because some Cray systems have a conflicting
   prototype (returning `int') in <unistd.h>.  */
#define getusershell _getusershell_sys_proto_

#ifdef USE_PAM
# include <security/pam_appl.h>
# include <security/pam_misc.h>
# include <signal.h>
# include <sys/wait.h>
# include <sys/fsuid.h>
#endif /* USE_PAM */

#include "system.h"
#include "closeout.h"
#include "dirname.h"

#undef getusershell

#if HAVE_SYSLOG_H && HAVE_SYSLOG
# include <syslog.h>
#else
# undef SYSLOG_SUCCESS
# undef SYSLOG_FAILURE
# undef SYSLOG_NON_ROOT
#endif

#if HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif

#ifndef HAVE_ENDGRENT
# define endgrent() ((void) 0)
#endif

#ifndef HAVE_ENDPWENT
# define endpwent() ((void) 0)
#endif

#if HAVE_SHADOW_H
# include <shadow.h>
#endif

#include "error.h"

/* The official name of this program (e.g., no `g' prefix).  */
#define PROGRAM_NAME "su"

#define AUTHORS "David MacKenzie"

#if HAVE_PATHS_H
# include <paths.h>
#endif

/* The default PATH for simulated logins to non-superuser accounts.  */
#ifdef _PATH_DEFPATH
# define DEFAULT_LOGIN_PATH _PATH_DEFPATH
#else
# define DEFAULT_LOGIN_PATH ":/usr/ucb:/bin:/usr/bin"
#endif

/* The default PATH for simulated logins to superuser accounts.  */
#ifdef _PATH_DEFPATH_ROOT
# define DEFAULT_ROOT_LOGIN_PATH _PATH_DEFPATH_ROOT
#else
# define DEFAULT_ROOT_LOGIN_PATH "/usr/ucb:/bin:/usr/bin:/etc"
#endif

/* The default paths which get set are both bogus and oddly influenced
   by <paths.h> and -D on the commands line. Just to be clear, we'll set
   these explicitly. -ewt */
#undef DEFAULT_LOGIN_PATH
#undef DEFAULT_ROOT_LOGIN_PATH
#define DEFAULT_LOGIN_PATH "/bin:/usr/bin:/usr/local/bin:/usr/bin/X11"
#define DEFAULT_ROOT_LOGIN_PATH \
    "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin/X11"

/* The shell to run if none is given in the user's passwd entry.  */
#define DEFAULT_SHELL "/bin/sh"

/* The user to become if none is specified.  */
#define DEFAULT_USER "root"

#ifndef USE_PAM
char *crypt ();
#endif
char *getpass ();
char *getusershell ();
void endusershell ();
void setusershell ();

extern char **environ;

static void run_shell (const char *, const char *, char **, const struct passwd *)
#ifdef USE_PAM
     ;
#else
     ATTRIBUTE_NORETURN;
#endif

/* The name this program was run with.  */
char *program_name;

/* If nonzero, pass the `-f' option to the subshell.  */
static int fast_startup;

/* If nonzero, simulate a login instead of just starting a shell.  */
static int simulate_login;

/* If nonzero, change some environment vars to indicate the user su'd to.  */
static int change_environment;

static struct option const longopts[] =
{
  {"command", required_argument, 0, 'c'},
  {"fast", no_argument, NULL, 'f'},
  {"login", no_argument, NULL, 'l'},
  {"preserve-environment", no_argument, &change_environment, 0},
  {"shell", required_argument, 0, 's'},
  {GETOPT_HELP_OPTION_DECL},
  {GETOPT_VERSION_OPTION_DECL},
  {0, 0, 0, 0}
};

/* Add VAL to the environment, checking for out of memory errors.  */

static void
xputenv (char *val)
{
  if (putenv (val))
    xalloc_die ();
}

/* Return a newly-allocated string whose contents concatenate
   those of S1, S2, S3.  */

static char *
concat (const char *s1, const char *s2, const char *s3)
{
  int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
  char *result = (char *) xmalloc (len1 + len2 + len3 + 1);

  strcpy (result, s1);
  strcpy (result + len1, s2);
  strcpy (result + len1 + len2, s3);
  result[len1 + len2 + len3] = 0;

  return result;
}

/* Return the number of elements in ARR, a null-terminated array.  */

static int
elements (char **arr)
{
  int n = 0;

  for (n = 0; *arr; ++arr)
    ++n;
  return n;
}

#if defined (SYSLOG_SUCCESS) || defined (SYSLOG_FAILURE)
/* Log the fact that someone has run su to the user given by PW;
   if SUCCESSFUL is nonzero, they gave the correct password, etc.  */

static void
log_su (const struct passwd *pw, int successful)
{
  const char *new_user, *old_user, *tty;

# ifndef SYSLOG_NON_ROOT
  if (pw->pw_uid)
    return;
# endif
  new_user = pw->pw_name;
  /* The utmp entry (via getlogin) is probably the best way to identify
     the user, especially if someone su's from a su-shell.  */
  old_user = getlogin ();
  if (old_user == NULL)
    {
      /* getlogin can fail -- usually due to lack of utmp entry.
	 Resort to getpwuid.  */
      struct passwd *pwd = getpwuid (getuid ());
      old_user = (pwd ? pwd->pw_name : "");
    }
  tty = ttyname (2);
  if (tty == NULL)
    tty = "none";
  /* 4.2BSD openlog doesn't have the third parameter.  */
  openlog (base_name (program_name), 0
# ifdef LOG_AUTH
	   , LOG_AUTH
# endif
	   );
  syslog (LOG_NOTICE,
# ifdef SYSLOG_NON_ROOT
	  "%s(to %s) %s on %s",
# else
	  "%s%s on %s",
# endif
	  successful ? "" : "FAILED SU ",
# ifdef SYSLOG_NON_ROOT
	  new_user,
# endif
	  old_user, tty);
  closelog ();
}
#endif

#ifdef USE_PAM
static pam_handle_t *pamh = NULL;
static int retval;
static struct pam_conv conv = {
  misc_conv,
  NULL
};

#define PAM_BAIL_P if (retval) { \
  pam_end(pamh, PAM_SUCCESS); \
  return 0; \
}
#endif

/* Ask the user for a password.
   If PAM is in use, let PAM ask for the password if necessary.
   Return 1 if the user gives the correct password for entry PW,
   0 if not.  Return 1 without asking for a password if run by UID 0
   or if PW has an empty password.  */

static int
correct_password (const struct passwd *pw)
{
#ifdef USE_PAM
  struct passwd *caller;
  retval = pam_start(PROGRAM_NAME, pw->pw_name, &conv, &pamh);
  PAM_BAIL_P;

  if (getuid() != 0 && !isatty(0)) {
	fprintf(stderr, "standard in must be a tty\n");
	exit(1);
  }

  caller = getpwuid(getuid());
  if(caller != NULL && caller->pw_name != NULL) {
	  retval = pam_set_item(pamh, PAM_RUSER, caller->pw_name);
	  PAM_BAIL_P;
  }

  retval = pam_authenticate(pamh, 0);
  PAM_BAIL_P;
  retval = pam_acct_mgmt(pamh, 0);
  if (retval == PAM_NEW_AUTHTOK_REQD) {
    /* password has expired.  Offer option to change it. */
    retval = pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK);
    PAM_BAIL_P;
  }
  PAM_BAIL_P;
  /* must be authenticated if this point was reached */
  return 1;
#else /* !USE_PAM */
  char *unencrypted, *encrypted, *correct;
#if HAVE_GETSPNAM && HAVE_STRUCT_SPWD_SP_PWDP
  /* Shadow passwd stuff for SVR3 and maybe other systems.  */
  struct spwd *sp = getspnam (pw->pw_name);

  endspent ();
  if (sp)
    correct = sp->sp_pwdp;
  else
#endif
    correct = pw->pw_passwd;

  if (getuid () == 0 || correct == 0 || correct[0] == '\0')
    return 1;

  unencrypted = getpass (_("Password:"));
  if (unencrypted == NULL)
    {
      error (0, 0, _("getpass: cannot open /dev/tty"));
      return 0;
    }
  encrypted = crypt (unencrypted, correct);
  memset (unencrypted, 0, strlen (unencrypted));
  return strcmp (encrypted, correct) == 0;
#endif /* !USE_PAM */
}

/* Update `environ' for the new shell based on PW, with SHELL being
   the value for the SHELL environment variable.  */

static void
modify_environment (const struct passwd *pw, const char *shell)
{
  char *term;
  char *display;
  char *xauthority;

  if (simulate_login)
    {
      /* Leave TERM, DISPLAY, XAUTHORITY unchanged.  Set HOME, SHELL, USER, LOGNAME, PATH.
         Unset all other environment variables.  */
      term = getenv ("TERM");
      display = getenv ("DISPLAY");
      xauthority = getenv ("XAUTHORITY");

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区免费在线观看| 国产精品青草久久| 色成年激情久久综合| 日韩电影免费在线看| 亚洲精品福利视频网站| 国产精品色噜噜| 久久久久久99久久久精品网站| 欧美性生活一区| 91在线观看美女| 99久久精品国产一区二区三区| 成人免费看黄yyy456| 国产在线麻豆精品观看| 视频一区视频二区在线观看| 亚洲午夜免费电影| 午夜久久福利影院| 日本伊人色综合网| 麻豆精品一区二区三区| 老色鬼精品视频在线观看播放| 理论电影国产精品| 国产91富婆露脸刺激对白| 粉嫩一区二区三区在线看| www.亚洲精品| 色婷婷av一区二区三区软件 | 午夜精品视频在线观看| 亚洲va国产天堂va久久en| 三级久久三级久久| 激情图区综合网| 欧美人与z0zoxxxx视频| 欧美体内she精视频| 欧美一区二区人人喊爽| 国产欧美一区二区在线观看| 日韩伦理免费电影| 日韩福利视频网| 不卡一区在线观看| 欧美日本在线观看| 国产亚洲美州欧州综合国| 一区二区三区不卡视频| 精品中文av资源站在线观看| 成人午夜电影网站| 777午夜精品免费视频| 国产精品三级av| 免费一级片91| 欧美日韩精品综合在线| 中文字幕欧美三区| 免费成人在线观看| 色婷婷久久久综合中文字幕| 欧美精品一区二区不卡| 性做久久久久久| 91蜜桃传媒精品久久久一区二区 | 777奇米四色成人影色区| 国产精品久99| 成人免费视频app| 精品欧美一区二区三区精品久久 | 裸体健美xxxx欧美裸体表演| 色综合天天视频在线观看| 久久婷婷色综合| 精品综合免费视频观看| 欧美一区二区视频观看视频| 亚洲一区二区三区小说| 色综合久久九月婷婷色综合| 国产精品女主播在线观看| 麻豆精品在线播放| 精品免费一区二区三区| 日韩国产高清在线| 欧美日韩国产综合一区二区三区 | 亚洲人成精品久久久久| 成人免费福利片| 中文字幕日本不卡| 在线观看日韩av先锋影音电影院| 亚洲欧洲色图综合| 欧美午夜在线观看| 日本免费新一区视频| 日韩欧美一区二区视频| 欧美日韩日本视频| 久久99久久99小草精品免视看| 精品日韩一区二区三区 | 风间由美一区二区av101| 亚洲国产精品v| 在线观看国产日韩| 韩国欧美国产1区| 国产精品美女一区二区| 欧美性色综合网| 精品综合免费视频观看| 自拍视频在线观看一区二区| 欧美三级视频在线| 国产剧情一区二区三区| 亚洲色图视频网站| 欧美一级免费观看| 99在线精品视频| 久久99精品久久久久久久久久久久| 中文字幕av不卡| 日韩三级中文字幕| 91碰在线视频| 国产精品综合在线视频| 一区二区三区视频在线观看| 欧美mv和日韩mv的网站| 在线观看91精品国产入口| 国模冰冰炮一区二区| 午夜激情一区二区三区| 中文字幕一区三区| 精品国产伦一区二区三区观看方式| 色爱区综合激月婷婷| 成人国产精品免费观看| 激情av综合网| 男人的j进女人的j一区| 亚洲成人午夜电影| 亚洲午夜av在线| 亚洲女人的天堂| 中文字幕中文在线不卡住| 久久蜜桃一区二区| 精品久久久久久无| 日韩一区二区三区精品视频 | 1000部国产精品成人观看| 精品成人私密视频| 久久久久国产精品麻豆| 精品对白一区国产伦| 日韩一级片在线观看| 日韩精品中文字幕在线一区| 欧美大片一区二区| 亚洲精品一线二线三线| 久久亚洲影视婷婷| 国产女人水真多18毛片18精品视频| 久久精品人人做人人爽人人| 日本大胆欧美人术艺术动态 | 精品一区二区三区免费| 国内一区二区视频| 成人av在线网站| 色一情一乱一乱一91av| 欧美日本韩国一区二区三区视频| 欧美日韩黄色一区二区| 欧美精品一区二区三区高清aⅴ| 精品国产一区二区在线观看| 久久这里只有精品6| 亚洲人精品一区| 欧美aa在线视频| 不卡一区二区在线| 欧美精品在线观看播放| 久久久久高清精品| 亚洲精品视频在线| 天天影视网天天综合色在线播放| 久久国产综合精品| 一本色道久久综合狠狠躁的推荐| 欧美精品乱码久久久久久| 久久久精品tv| 婷婷综合五月天| 91视频在线观看免费| 欧美一区二区观看视频| 中文字幕亚洲精品在线观看 | 久久久久综合网| 午夜私人影院久久久久| 国产成人一区在线| 欧美变态口味重另类| 亚洲午夜激情av| 99精品欧美一区二区蜜桃免费| 精品久久人人做人人爽| 99re视频这里只有精品| 久久久精品天堂| 九九久久精品视频| 91精品国产欧美一区二区18| 亚洲女与黑人做爰| 一本色道a无线码一区v| 国产精品国产成人国产三级| 国产精品一品二品| 国产日韩欧美麻豆| 国产精品一区专区| 久久久久久电影| 国产精品77777| 国产欧美一区视频| 成人午夜免费视频| 亚洲欧洲国产专区| 久久这里只精品最新地址| 国产毛片精品国产一区二区三区| 欧美成人猛片aaaaaaa| 国产伦精品一区二区三区免费| 欧美精品一区二区三区蜜桃视频| 国产一区二区三区香蕉| 国产精品午夜春色av| bt欧美亚洲午夜电影天堂| 亚洲私人黄色宅男| 制服丝袜一区二区三区| 国产精品综合久久| 欧美日本在线视频| 久久免费美女视频| 成人午夜视频网站| 亚洲香肠在线观看| 欧美一区日韩一区| 国产一区二区三区最好精华液| 国产三级一区二区| 欧洲色大大久久| 国产精品99久久久久久久女警| 国产精品情趣视频| 欧美日韩日日夜夜| zzijzzij亚洲日本少妇熟睡| 亚洲在线一区二区三区| 精品国产免费一区二区三区四区| 色综合久久88色综合天天| 另类人妖一区二区av| 亚洲综合免费观看高清完整版 | 欧美老女人在线| 99vv1com这只有精品|