components/proftpd/mod_solaris_priv.c
author David Hollister <david.hollister@oracle.com>
Wed, 12 Oct 2016 14:01:13 -0600
changeset 7094 61352b4e5af5
parent 4634 a4940ac4947c
permissions -rw-r--r--
24797203 OpenStack RBAC profiles allow reading too many files 24797238 keystone RBAC and SMF should point at Apache log files 24797256 cinder RBAC and SMF should point at Apache log files 24830959 horizon RBAC and SMF should point at Apache log files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
     1
/*
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
     2
 * ProFTPD - FTP server daemon
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
     3
 * Copyright (c) 1997, 1998 Public Flood Software
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
     4
 * Copyright (c) 2003-2010 The ProFTPD Project team
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
     5
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
     6
 *
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
     7
 * This program is free software; you can redistribute it and/or modify
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
     8
 * it under the terms of the GNU General Public License as published by
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
     9
 * the Free Software Foundation; either version 2 of the License, or
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    10
 * (at your option) any later version.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    11
 *
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    12
 * This program is distributed in the hope that it will be useful,
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    15
 * GNU General Public License for more details.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    16
 *
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    18
 * along with this program; if not, write to the Free Software
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    20
 *
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    21
 * As a special exemption, the copyright holders give permission to link
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    22
 * this program with OpenSSL and distribute the resulting executable without
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    23
 * including the source code for OpenSSL in the source distribution.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    24
 */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    25
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    26
/* Use Solaris privileges to severely limit root's access. After user
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    27
 * authentication, this module _completely_ gives up most privileges,
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    28
 * except for the * bare minimum functionality that is required. 
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    29
 * VERY highly recommended for security-consious admins.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    30
 *
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    31
 * The concept of this was copied from the Linux mod_cap.  Solaris
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    32
 * also has the concept of basic privileges that we can take away to further
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    33
 * restrict a process lower than what a normal user process can do, this
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    34
 * module removes some of those as well.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    35
 */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    36
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    37
#include <stdio.h>
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    38
#include <stdlib.h>
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    39
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    40
#include <priv.h>
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    41
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    42
#include "conf.h"
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    43
#include "privs.h"
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    44
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    45
#define MOD_SOLARIS_PRIV_VERSION	"mod_solaris_priv/1.0"
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    46
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    47
/* Configuration handlers
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    48
 */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    49
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    50
#define	PRIV_USE_FILE_CHOWN		0x0001
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    51
#define	PRIV_USE_FILE_CHOWN_SELF	0x0002
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    52
#define	PRIV_USE_DAC_READ		0x0004
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    53
#define	PRIV_USE_DAC_WRITE		0x0008
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    54
#define	PRIV_USE_DAC_SEARCH		0x0010
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    55
#define	PRIV_USE_SETID			0x0020
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    56
#define	PRIV_USE_FILE_OWNER		0x0040
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    57
#define	PRIV_DROP_FILE_WRITE		0x0080
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    58
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
    59
#define	PRIV_SOL_ROOT_PRIVS	\
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
    60
	(PRIV_USE_FILE_CHOWN | PRIV_USE_FILE_CHOWN_SELF | \
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
    61
	PRIV_USE_DAC_READ | PRIV_USE_DAC_WRITE | PRIV_USE_DAC_SEARCH | \
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
    62
	PRIV_USE_FILE_OWNER)
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
    63
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    64
static unsigned int solaris_priv_flags = 0;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    65
static unsigned char use_privs = TRUE;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    66
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    67
MODRET set_solaris_priv(cmd_rec *cmd) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    68
  unsigned int flags = 0;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    69
  config_rec *c = NULL;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    70
  register unsigned int i = 0;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    71
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    72
  if (cmd->argc - 1 < 1)
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    73
    CONF_ERROR(cmd, "need at least one parameter");
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    74
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    75
  CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    76
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    77
  /* PRIV_CHOWN is enabled by default. */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    78
  flags |= PRIV_USE_FILE_CHOWN;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    79
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    80
  for (i = 1; i < cmd->argc; i++) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    81
    char *cp = cmd->argv[i];
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    82
    cp++;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    83
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    84
    if (*cmd->argv[i] != '+' && *cmd->argv[i] != '-')
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    85
      CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, ": bad option: '",
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    86
        cmd->argv[i], "'", NULL));
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    87
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    88
    if (strcasecmp(cp, "PRIV_USE_FILE_CHOWN") == 0) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    89
      if (*cmd->argv[i] == '-')
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    90
        flags &= ~PRIV_USE_FILE_CHOWN;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    91
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    92
    } else if (strcasecmp(cp, "PRIV_FILE_CHOWN_SELF") == 0) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    93
      if (*cmd->argv[i] == '-')
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    94
        flags &= ~PRIV_USE_FILE_CHOWN_SELF;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    95
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    96
    } else if (strcasecmp(cp, "PRIV_DAC_READ") == 0) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    97
      if (*cmd->argv[i] == '+')
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    98
        flags |= PRIV_USE_DAC_READ;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
    99
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   100
    } else if (strcasecmp(cp, "PRIV_DAC_WRITE") == 0) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   101
      if (*cmd->argv[i] == '+')
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   102
        flags |= PRIV_USE_DAC_WRITE;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   103
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   104
    } else if (strcasecmp(cp, "PRIV_DAC_SEARCH") == 0) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   105
      if (*cmd->argv[i] == '+')
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   106
        flags |= PRIV_USE_DAC_SEARCH;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   107
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   108
    } else if (strcasecmp(cp, "PRIV_FILE_OWNER") == 0) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   109
      if (*cmd->argv[i] == '+')
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   110
        flags |= PRIV_USE_FILE_OWNER;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   111
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   112
    } else {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   113
      CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unknown privilege: '",
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   114
        cp, "'", NULL));
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   115
    }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   116
  }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   117
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   118
  c = add_config_param(cmd->argv[0], 1, NULL);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   119
  c->argv[0] = pcalloc(c->pool, sizeof(unsigned int));
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   120
  *((unsigned int *) c->argv[0]) = flags;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   121
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   122
  return PR_HANDLED(cmd);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   123
}
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   124
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   125
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   126
MODRET set_solaris_priv_engine(cmd_rec *cmd) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   127
  int bool = -1;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   128
  config_rec *c = NULL;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   129
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   130
  CHECK_ARGS(cmd, 1);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   131
  CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   132
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   133
  bool = get_boolean(cmd, 1);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   134
  if (bool == -1)
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   135
    CONF_ERROR(cmd, "expecting Boolean parameter");
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   136
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   137
  c = add_config_param(cmd->argv[0], 1, NULL);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   138
  c->argv[0] = pcalloc(c->pool, sizeof(unsigned char));
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   139
  *((unsigned char *) c->argv[0]) = bool;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   140
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   141
  return PR_HANDLED(cmd);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   142
}
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   143
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   144
/* Command handlers
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   145
 */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   146
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   147
/* The POST_CMD handler for "PASS" is only called after PASS has
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   148
 * successfully completed, which means authentication is successful,
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   149
 * so we can "tweak" our root access down to almost nothing.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   150
 */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   151
MODRET solaris_priv_post_pass(cmd_rec *cmd) {
1339
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   152
  int res = -1;
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   153
  int priv_flags = solaris_priv_flags;
1339
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   154
  priv_set_t *p = NULL;
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   155
  priv_set_t *i = NULL;
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   156
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   157
  if (!use_privs)
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   158
    return PR_DECLINED(cmd);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   159
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   160
  /* If we authenticated as root, we get all appropriate privs */
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   161
  if (session.uid == 0) {
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   162
    priv_flags = PRIV_SOL_ROOT_PRIVS;
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   163
  }
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   164
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   165
  pr_signals_block();
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   166
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   167
  /* The only privilege we need is PRIV_NET_PRIVADDR (bind
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   168
   * ports < 1024).  Everything else can be discarded.  We set this
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   169
   * in the permitted set only, as when we switch away from root
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   170
   * we lose effective anyhow, and must reset it.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   171
   *
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   172
   * We also remove the basic Solaris privileges we know we will
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   173
   * never need.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   174
   */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   175
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   176
  i = priv_allocset();
1339
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   177
  if (i == NULL)
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   178
    goto out;
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   179
  priv_basicset(i);
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   180
  priv_delset(i, PRIV_PROC_EXEC);
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   181
  priv_delset(i, PRIV_PROC_FORK);
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   182
  priv_delset(i, PRIV_PROC_INFO);
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   183
  priv_delset(i, PRIV_PROC_SESSION);
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   184
  setppriv(PRIV_SET, PRIV_INHERITABLE, i);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   185
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   186
  p = priv_allocset();
1339
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   187
  if (p == NULL)
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   188
    goto out;
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   189
  priv_basicset(p);
707
5953149bd743 7130322 proftpd in the default configuration does not have required privileges
tomas klacko - Sun Microsystems - Prague Czech Republic <tomas.klacko@oracle.com>
parents: 619
diff changeset
   190
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   191
  priv_addset(p, PRIV_NET_PRIVADDR);
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   192
  priv_addset(p, PRIV_PROC_AUDIT);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   193
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   194
  priv_delset(p, PRIV_PROC_EXEC);
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   195
  priv_delset(p, PRIV_PROC_FORK);
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   196
  priv_delset(p, PRIV_PROC_INFO);
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   197
  priv_delset(p, PRIV_PROC_SESSION);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   198
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   199
  if (priv_flags & PRIV_USE_SETID)
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   200
    priv_addset(p, PRIV_PROC_SETID);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   201
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   202
  /* Add any of the configurable privileges. */
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   203
  if (priv_flags & PRIV_USE_FILE_CHOWN)
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   204
    priv_addset(p, PRIV_FILE_CHOWN);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   205
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   206
  if (priv_flags & PRIV_USE_FILE_CHOWN_SELF)
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   207
    priv_addset(p, PRIV_FILE_CHOWN_SELF);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   208
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   209
  if (priv_flags & PRIV_USE_DAC_READ)
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   210
    priv_addset(p, PRIV_FILE_DAC_READ);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   211
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   212
  if (priv_flags & PRIV_USE_DAC_WRITE)
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   213
    priv_addset(p, PRIV_FILE_DAC_WRITE);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   214
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   215
  if (priv_flags & PRIV_USE_DAC_SEARCH)
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   216
    priv_addset(p, PRIV_FILE_DAC_SEARCH);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   217
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   218
  if (priv_flags & PRIV_USE_FILE_OWNER)
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   219
    priv_addset(p, PRIV_FILE_OWNER);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   220
4634
a4940ac4947c 20886490 proftpd can't open wtmpx after one login failure, doesn't register the ftp login
William.D.Johnston <William.D.Johnston@oracle.com>
parents: 2205
diff changeset
   221
  if (priv_flags & PRIV_DROP_FILE_WRITE)
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   222
    priv_delset(p, PRIV_FILE_WRITE);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   223
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   224
  res = setppriv(PRIV_SET, PRIV_PERMITTED, p);
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   225
  res = setppriv(PRIV_SET, PRIV_EFFECTIVE, p);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   226
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   227
  if (setreuid(session.uid, session.uid) == -1) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   228
    pr_log_pri(PR_LOG_ERR, MOD_SOLARIS_PRIV_VERSION ": setreuid: %s",
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   229
	strerror(errno));
1339
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   230
    priv_freeset(i);
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   231
    priv_freeset(p);
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   232
    pr_signals_unblock();
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   233
    end_login(1);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   234
  }
1339
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   235
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   236
out:
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   237
  if (i != NULL)
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   238
    priv_freeset(i);
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   239
  if (p != NULL)
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   240
    priv_freeset(p);
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   241
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   242
  pr_signals_unblock();
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   243
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   244
  if (res != -1) {
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   245
    /* That's it!  Disable all further id switching */
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   246
    session.disable_id_switching = TRUE;
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   247
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   248
  } else {
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   249
    pr_log_pri(PR_LOG_NOTICE, MOD_SOLARIS_PRIV_VERSION ": attempt to configure "
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   250
      "privileges failed, reverting to normal operation");
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   251
  }
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   252
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   253
  return PR_DECLINED(cmd);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   254
}
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   255
1339
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   256
static void log_err_effective(const char* fn) {
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   257
  pr_log_pri(PR_LOG_ERR, MOD_SOLARIS_PRIV_VERSION ": %s(%s): %s",
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   258
    fn, "effective", strerror(errno));
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   259
}
141f97d83ea8 16286302 proftpd throws out audit session create fail when user enters a wrong password
Tomas Klacko <tomas.klacko@oracle.com>
parents: 881
diff changeset
   260
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   261
/* Initialization routines
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   262
 */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   263
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   264
static int solaris_priv_sess_init(void) {
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   265
  /* Check to see if the lowering of privileges has been disabled in the
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   266
   * configuration file.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   267
   */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   268
  if (use_privs) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   269
    unsigned char *solaris_priv_engine;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   270
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   271
    solaris_priv_engine = get_param_ptr(main_server->conf, "PrivilegeEngine", FALSE);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   272
    if (solaris_priv_engine &&
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   273
        *solaris_priv_engine == FALSE) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   274
      pr_log_debug(DEBUG3, MOD_SOLARIS_PRIV_VERSION
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   275
        ": lowering of privileges disabled");
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   276
      use_privs = FALSE;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   277
    }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   278
  }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   279
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   280
  /* Check for which specific privileges to include/exclude. */
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   281
  if (use_privs) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   282
    int use_setuid = FALSE;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   283
    config_rec *c;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   284
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   285
    c = find_config(main_server->conf, CONF_PARAM, "PrivilegeSet", FALSE);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   286
    if (c != NULL) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   287
      solaris_priv_flags = *((unsigned int *) c->argv[0]);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   288
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   289
      if (!(solaris_priv_flags & PRIV_USE_FILE_CHOWN)) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   290
        pr_log_debug(DEBUG3, MOD_SOLARIS_PRIV_VERSION
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   291
          ": removing PRIV_CHOWN privilege");
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   292
      }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   293
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   294
      if (solaris_priv_flags & PRIV_USE_DAC_READ) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   295
        pr_log_debug(DEBUG3, MOD_SOLARIS_PRIV_VERSION
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   296
          ": adding PRIV_FILE_DAC_READ privilege"); 
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   297
      }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   298
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   299
      if (solaris_priv_flags & PRIV_USE_DAC_WRITE) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   300
        pr_log_debug(DEBUG3, MOD_SOLARIS_PRIV_VERSION
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   301
          ": adding PRIV_FILE_DAC_WRITE privilege"); 
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   302
      }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   303
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   304
      if (solaris_priv_flags & PRIV_USE_DAC_SEARCH) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   305
        pr_log_debug(DEBUG3, MOD_SOLARIS_PRIV_VERSION
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   306
          ": adding PRIV_DAC_SEARCH privilege");
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   307
      }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   308
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   309
      if (solaris_priv_flags & PRIV_USE_FILE_OWNER) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   310
        pr_log_debug(DEBUG3, MOD_SOLARIS_PRIV_VERSION
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   311
          ": adding PRIV_FILE_OWNER privilege");
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   312
      }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   313
    }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   314
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   315
    c = find_config(main_server->conf, CONF_PARAM, "AllowOverwrite", FALSE);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   316
    if (c && *((int *) c->argv[0]) == FALSE) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   317
        pr_log_debug(DEBUG3, MOD_SOLARIS_PRIV_VERSION
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   318
          ": removing PRIV_FILE_WRITE basic privilege");
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   319
        solaris_priv_flags |= PRIV_DROP_FILE_WRITE;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   320
    }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   321
	    
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   322
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   323
    /* We also need to check for things which want to revoke root privs
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   324
     * altogether: mod_exec, mod_sftp, and the RootRevoke directive.
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   325
     * Revoking root privs completely requires the SETUID/SETGID
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   326
     * privileges.
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   327
     */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   328
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   329
    if (use_setuid == FALSE &&
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   330
        pr_module_exists("mod_sftp.c")) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   331
      c = find_config(main_server->conf, CONF_PARAM, "SFTPEngine", FALSE);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   332
      if (c &&
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   333
          *((int *) c->argv[0]) == TRUE) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   334
        use_setuid = TRUE;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   335
      }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   336
    }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   337
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   338
    if (use_setuid == FALSE &&
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   339
        pr_module_exists("mod_exec.c")) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   340
      c = find_config(main_server->conf, CONF_PARAM, "ExecEngine", FALSE);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   341
      if (c &&
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   342
          *((unsigned char *) c->argv[0]) == TRUE) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   343
        use_setuid = TRUE;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   344
      }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   345
    }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   346
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   347
    if (use_setuid == FALSE) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   348
      c = find_config(main_server->conf, CONF_PARAM, "RootRevoke", FALSE);
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   349
      if (c &&
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   350
          *((unsigned char *) c->argv[0]) == TRUE) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   351
        use_setuid = TRUE;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   352
      }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   353
    }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   354
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   355
    if (use_setuid) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   356
      solaris_priv_flags |= PRIV_USE_SETID;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   357
      pr_log_debug(DEBUG3, MOD_SOLARIS_PRIV_VERSION
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   358
        ": adding PRIV_SETID ");
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   359
    }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   360
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   361
  }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   362
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   363
  return 0;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   364
}
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   365
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   366
static int solaris_priv_module_init(void) {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   367
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   368
  return 0;
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   369
}
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   370
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   371
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   372
/* Module API tables
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   373
 */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   374
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   375
static conftable solaris_priv_conftab[] = {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   376
  { "PrivilegeEngine", set_solaris_priv_engine, NULL },
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   377
  { "PrivilegeSet",    set_solaris_priv,        NULL },
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   378
  { NULL, NULL, NULL }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   379
};
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   380
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   381
static cmdtable solaris_priv_cmdtab[] = {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   382
  { POST_CMD, C_PASS, G_NONE, solaris_priv_post_pass, FALSE, FALSE },
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   383
  { 0, NULL }
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   384
};
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   385
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   386
module solaris_priv_module = {
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   387
  NULL, NULL,
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   388
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   389
  /* Module API version */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   390
  0x20,
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   391
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   392
  /* Module name */
881
b3186e256788 7162794 proftpd drops privilege too early breaking PAM assumptions
Tomas Klacko <tomas.klacko@oracle.com>
parents: 765
diff changeset
   393
  "privileges",
305
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   394
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   395
  /* Module configuration handler table */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   396
  solaris_priv_conftab,
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   397
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   398
  /* Module command handler table */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   399
  solaris_priv_cmdtab,
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   400
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   401
  /* Module authentication handler table */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   402
  NULL,
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   403
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   404
  /* Module initialization */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   405
  solaris_priv_module_init,
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   406
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   407
  /* Session initialization */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   408
  solaris_priv_sess_init,
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   409
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   410
  /* Module version */
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   411
  MOD_SOLARIS_PRIV_VERSION
e95b65443448 PSARC 2011/088 Replace WU-ftpd with modern FTP server proftpd
Milan Jurik <Milan.Jurik@oracle.com>
parents:
diff changeset
   412
};