/usr/sbin/edubuntu-server-auth is in edubuntu-server-client 14.02.2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | #!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (C) 2012-2014 Stéphane Graber
# Author: Stéphane Graber <stgraber@ubuntu.com>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can find the license on Debian systems in the file
# /usr/share/common-licenses/GPL-2
import argparse
import configparser
import gettext
import os
import socket
import subprocess
import sys
_ = gettext.gettext
gettext.textdomain("edubuntu-server-auth")
# Constants
PKG_LIST = ("libpam-sss", "libnss-sss", "libsss-sudo",
"libsasl2-modules-gssapi-heimdal", "samba-common-bin")
# Common functions
def backup_config(path):
if os.path.exists(path) and not os.path.exists("%s.pre-edubuntu" % path):
os.rename(path, "%s.pre-edubuntu" % path)
def get_username(args):
username = ""
password = ""
if hasattr(args, "username"):
username = args.username
else:
username = os.environ['USER']
if hasattr(args, "password"):
if args.password == "-":
password = sys.stdin.read().strip()
else:
password = args.password
if password:
return "%s%%%s" % (username, password)
else:
return username
def restore_config(path):
if os.path.exists(path):
os.remove(path)
if os.path.exists("%s.pre-edubuntu" % path):
os.rename("%s.pre-edubuntu" % path, path)
# The various actions
def join_domain(args):
krb5_domain = args.domain.upper()
ldap_dn = "DC=%s" % ",DC=".join(args.domain.split("."))
smb_workgroup = args.domain.split(".")[0].upper()
smb_hostname = socket.gethostname().upper()
domain_sid = None
enctypes = "rc4-hmac aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96"
# Mark the packages for installation
cache = apt.Cache()
for pkg in PKG_LIST:
if pkg in cache:
cache[pkg].mark_install()
else:
print("Unable to find package: %s" % pkg)
sys.exit(1)
if cache.get_changes():
print("Installing %s needed packages." % len(cache.get_changes()))
cache.update()
cache.commit()
# Configure kerberos
backup_config("/etc/krb5.conf")
backup_config("/etc/krb5.keytab")
with open("/etc/krb5.conf", "w+") as fd:
fd.write("""[libdefaults]
default_realm = %s
dns_lookup_realm = false
dns_lookup_kdc = true
ticket_lifetime = 24h
allow_weak_crypto = true
default_tgs_enctypes = %s
default_tkt_enctypes = %s
permitted_enctypes = %s
[domain_realm]
.%s = %s
%s = %s
""" % (
krb5_domain, enctypes, enctypes, enctypes,
args.domain, krb5_domain, args.domain, krb5_domain))
os.fchmod(fd.fileno(), 0o644)
os.fchown(fd.fileno(), 0, 0)
# Configure samba
backup_config("/etc/samba/smb.conf")
with open("/etc/samba/smb.conf", "w+") as fd:
fd.write("""[global]
workgroup = %s
realm = %s
server string = %s
netbios name = %s
security = ads
kerberos method = system keytab
passdb backend = tdbsam
""" % (smb_workgroup, args.domain, smb_hostname, smb_hostname))
os.fchmod(fd.fileno(), 0o644)
os.fchown(fd.fileno(), 0, 0)
command = ["net", "ads", "join", "-U", get_username(args)]
while 1:
# Join
subprocess.call(command)
# Get the SID
net = subprocess.Popen(['net', 'getdomainsid'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, universal_newlines=True)
net.wait()
for line in net.stdout:
line = line.strip()
if line.startswith("SID for domain"):
domain_sid = line.split()[-1]
break
if not domain_sid:
print("Failed to join domain. Try again.")
continue
break
# Configure lightdm
if os.path.exists("/etc/lightdm/lightdm.conf"):
write_lightdm = False
lightdm = configparser.ConfigParser()
lightdm.read("/etc/lightdm/lightdm.conf")
if not lightdm.has_section("SeatDefaults"):
lightdm.add_section("SeatDefaults")
if not lightdm.has_option("SeatDefaults", "greeter-show-manual-login"):
lightdm.set("SeatDefaults", "greeter-show-manual-login", "true")
write_lightdm = True
elif lightdm.get("SeatDefaults",
"greeter-show-manual-login") != "true":
lightdm.set("SeatDefaults", "greeter-show-manual-login", "true")
write_lightdm = True
if write_lightdm:
with open("/etc/lightdm/lightdm.conf", "w+") as fd:
lightdm.write(fd)
# Configure PAM
with open("/usr/share/pam-configs/edubuntu-domain", "w+") as fd:
fd.write("""Name: edubuntu-server settings
Default: yes
Priority: 128
Session-Type: Additional
Session-Interactive-Only: yes
Session:
optional pam_mkhomedir.so
""")
os.fchmod(fd.fileno(), 0o644)
os.fchown(fd.fileno(), 0, 0)
with open(os.devnull, "w") as fd:
subprocess.call(["pam-auth-update", "--package"],
stdout=fd, stderr=fd)
# Configure sssd
with open(os.devnull, "w") as fd:
subprocess.call(["stop", "sssd"],
stdout=fd, stderr=fd)
backup_config("/etc/sssd/sssd.conf")
with open("/etc/sssd/sssd.conf", "w+") as fd:
fd.write("""[sssd]
domains = Edubuntu
services = nss, pam, sudo
config_file_version = 2
sbus_timeout = 30
debug_level = 0
[nss]
default_shell = /bin/bash
[domain/Edubuntu]
enumerate = false
cache_credentials = true
fallback_homedir = /home/%%u
id_provider = ldap
auth_provider = krb5
chpass_provider = krb5
sudo_provider = ldap
dns_discovery_domain = %s
krb5_realm = %s
ldap_idmap_default_domain_sid = %s
ldap_schema = ad
ldap_id_mapping = true
ldap_user_gecos = displayName
ldap_force_upper_case_realm = true
ldap_sudo_search_base = OU=sudoers,%s
ldap_sasl_mech = GSSAPI
""" % (args.domain, krb5_domain, domain_sid, ldap_dn))
os.fchmod(fd.fileno(), 0o600)
os.fchown(fd.fileno(), 0, 0)
with open(os.devnull, "w") as fd:
subprocess.call(["start", "sssd"],
stdout=fd, stderr=fd)
def leave_domain(args):
# Unconfigure samba
if os.path.exists("/etc/samba/smb.conf"):
command = ["net", "ads", "leave", "-U", get_username(args)]
if subprocess.call(command) != 0:
print("Failed to leave the domain.")
sys.exit(1)
restore_config("/etc/samba/smb.conf")
# Unconfigure sssd
restore_config("/etc/sssd/sssd.conf")
with open(os.devnull, "w") as fd:
if os.path.exists("/etc/sssd/sssd.conf"):
subprocess.call(["initctl", "restart", "sssd"],
stdout=fd, stderr=fd)
else:
subprocess.call(["initctl", "stop", "sssd"],
stdout=fd, stderr=fd)
# Remove the Kerberos configuration
restore_config("/etc/krb5.conf")
restore_config("/etc/krb5.keytab")
# Remove the PAM configuration
restore_config("/usr/share/pam-configs/edubuntu-domain")
with open(os.devnull, "w") as fd:
subprocess.call(["pam-auth-update", "--package", "--remove",
"edubuntu-domain"],
stdout=fd, stderr=fd)
# Unconfigure lightdm
if os.path.exists("/etc/lightdm/lightdm.conf"):
lightdm = configparser.ConfigParser()
lightdm.read("/etc/lightdm/lightdm.conf")
if lightdm.has_section("SeatDefaults") and \
lightdm.has_option("SeatDefaults",
"greeter-show-manual-login"):
lightdm.remove_option("SeatDefaults", "greeter-show-manual-login")
with open("/etc/lightdm/lightdm.conf", "w+") as fd:
lightdm.write(fd)
# Begin parsing the command line
parser = argparse.ArgumentParser(
description=_("Edubuntu server authentication"),
formatter_class=argparse.RawTextHelpFormatter)
# Commands
subparsers = parser.add_subparsers()
subparser_join = subparsers.add_parser('join', help=_('Join the domain'))
subparser_join.set_defaults(action=join_domain)
subparser_join.add_argument(dest="domain", metavar="DOMAIN-FQDN",
help=_("Fully-Qualified-Domain-Name for the domain"
"(e.g. edubuntu.org)"))
subparser_join.add_argument("-U", "--username", dest="username",
metavar="USERNAME",
help=_("Username of a Domain Administrator"))
subparser_join.add_argument("-P", "--password", dest="password",
metavar="PASSWORD",
help=_("Password of a Domain Administrator "
"('-' for stdin)"))
subparser_leave = subparsers.add_parser('leave', help=_('Leave the domain'))
subparser_leave.add_argument("-U", "--username", dest="username",
metavar="USERNAME",
help=_("Username of a Domain Administrator"))
subparser_leave.add_argument("-P", "--password", dest="password",
metavar="PASSWORD",
help=_("Password of a Domain Administrator "
"('-' for stdin)"))
subparser_leave.set_defaults(action=leave_domain)
args = parser.parse_args()
# Basic requirements check
## Check that we have an action
if not hasattr(args, "action"):
parser.error(_("You must specifiy an action."))
sys.exit(1)
## The user needs to be uid 0
if not os.geteuid() == 0:
parser.error(_("You must be root to run this script. "
"Try running: sudo %s" % (sys.argv[0])))
sys.exit(1)
# Import apt now so we don't have to build-depend on it
import apt
args.action(args)
|