summarylogtreecommitdiffstats
path: root/install.freeipa
blob: 4d2bd0e9788aa0ac29b03690218faa843a0bf394 (plain)
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
post_upgrade() {
  # Has the client been configured?
  restore=0
  test -f '/var/lib/ipa-client/sysrestore/sysrestore.index' && restore=$(wc -l '/var/lib/ipa-client/sysrestore/sysrestore.index' | awk '{print $1}')

  if [ -f '/etc/sssd/sssd.conf' -a $restore -ge 2 ]; then
    if ! grep -Eq '/var/lib/sss/pubconf/krb5.include.d/' /etc/krb5.conf 2>/dev/null; then
      echo "includedir /var/lib/sss/pubconf/krb5.include.d/" > /etc/krb5.conf.ipanew
      cat /etc/krb5.conf >> /etc/krb5.conf.ipanew
      mv /etc/krb5.conf.ipanew /etc/krb5.conf
    fi
  fi

  # Has the client been configured?
  restore=0
  test -f '/var/lib/ipa-client/sysrestore/sysrestore.index' \
    && restore=$(wc -l '/var/lib/ipa-client/sysrestore/sysrestore.index' \
                 | awk '{print $1}')

  if [ -f '/etc/ssh/sshd_config' -a $restore -ge 2 ]; then
    if grep -Eq '^(AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys|PubKeyAgent /usr/bin/sss_ssh_authorizedkeys %u)$' /etc/ssh/sshd_config 2>/dev/null; then
      sed -r '
          /^(AuthorizedKeysCommand(User|RunAs)|PubKeyAgentRunAs)[ \t]/ d
      ' /etc/ssh/sshd_config >/etc/ssh/sshd_config.ipanew

      if /usr/sbin/sshd -t -f /dev/null -o 'AuthorizedKeysCommand=/usr/bin/sss_ssh_authorizedkeys' -o 'AuthorizedKeysCommandUser=nobody'; then
        sed -ri '
            s/^PubKeyAgent (.+) %u$/AuthorizedKeysCommand \1/
            s/^AuthorizedKeysCommand .*$/\0\nAuthorizedKeysCommandUser nobody/
        ' /etc/ssh/sshd_config.ipanew
      elif /usr/sbin/sshd -t -f /dev/null -o 'AuthorizedKeysCommand=/usr/bin/sss_ssh_authorizedkeys' -o 'AuthorizedKeysCommandRunAs=nobody'; then
        sed -ri '
            s/^PubKeyAgent (.+) %u$/AuthorizedKeysCommand \1/
            s/^AuthorizedKeysCommand .*$/\0\nAuthorizedKeysCommandRunAs nobody/
        ' /etc/ssh/sshd_config.ipanew
      elif /usr/sbin/sshd -t -f /dev/null -o 'PubKeyAgent=/usr/bin/sss_ssh_authorizedkeys %u' -o 'PubKeyAgentRunAs=nobody'; then
        sed -ri '
            s/^AuthorizedKeysCommand (.+)$/PubKeyAgent \1 %u/
            s/^PubKeyAgent .*$/\0\nPubKeyAgentRunAs nobody/
        ' /etc/ssh/sshd_config.ipanew
      fi

      mv /etc/ssh/sshd_config.ipanew /etc/ssh/sshd_config
      chmod 600 /etc/ssh/sshd_config
    fi
  fi
}