s3-spoolss/registry: use marshall_sec_desc in fill_in_printer_values().
[Samba.git] / packaging / Debian / debian-unstable / samba.postinst
blob0fb03f8768e017074a6c15a1e413b0da01a4fef3
1 #!/bin/sh -e
3 # Post-installation script for the Samba package for Debian GNU/Linux
7 case "$1" in
8 configure)
9 # continue below
12 abort-upgrade|abort-remove|abort-deconfigure)
13 exit 0
17 echo "postinst called with unknown argument \`$1'" >&2
18 exit 0
20 esac
22 # Handle debconf
23 . /usr/share/debconf/confmodule
25 INITCONFFILE=/etc/default/samba
27 # We generate several files during the postinst, and we don't want
28 # them to be readable only by root.
29 umask 022
32 # Generate configuration file if it does not exist, using default values.
33 [ -r "${INITCONFFILE}" ] || {
34 echo Generating ${INITCONFFILE}... >&2
35 cat >${INITCONFFILE} <<'EOFMAGICNUMBER1234'
36 # Defaults for samba initscript
37 # sourced by /etc/init.d/samba
38 # installed at /etc/default/samba by the maintainer scripts
42 # This is a POSIX shell fragment
45 # How should Samba (smbd) run? Possible values are "daemons"
46 # or "inetd".
47 RUN_MODE=""
48 EOFMAGICNUMBER1234
51 # --- Begin of FHS migration code ---
53 # Starting with Samba 2.2.3-4 the WINS database, the browse
54 # database and other important run-time files are stored in
55 # FHS-compliant directories. The following code takes care of
56 # moving the files in the old directories (/var/samba/ and
57 # /var/state/samba) to the new FHS-compliant directories.
59 if [ -d /var/samba/ ] && [ -n "$2" ] && dpkg --compare-versions "$2" lt 2.0.7-4
60 then
61 mv /var/samba/* /var/lib/samba/ 2>/dev/null || true
62 rmdir /var/samba/
65 # Default for anything we don't know about (see next two 'for' loops)
66 # is /var/lib/samba -- guaranteed not to accidentally tromp on any
67 # files the admin thought were safe.
68 if [ -d /var/state/samba ] && [ -n "$2" ] && dpkg --compare-versions "$2" lt 2.2.3-4
69 then
70 mv /var/state/samba/* /var/lib/samba/ 2>/dev/null || true
71 rmdir /var/state/samba/
73 # It's not FHS, and it's probably our fault this is here,
74 # so delete it if we can.
75 rmdir /var/state/ 2> /dev/null || true
78 # All these files are now placed in their respective FHS-compliant
79 # directories. Separate out the individual files accordingly.
80 for F in browse.dat printing.tdb winbindd_cache.tdb
82 if [ -e /var/lib/samba/"$F" ]; then
83 mv /var/lib/samba/"$F" /var/cache/samba/
85 done
87 for F in brlock.tdb connections.tdb locking.tdb messages.tdb nmbd.pid \
88 sessionid.tdb smbd.pid unexpected.tdb
90 if [ -e /var/lib/samba/"$F" ]; then
91 mv /var/lib/samba/"$F" /var/run/samba/
93 done
95 # Beginning with Samba 2.2.5-1, we also move the domain secrets file
96 # to a more suitable location, since no one really edits this by hand.
97 if [ -e /etc/samba/secrets.tdb -a ! -e /var/lib/samba/secrets.tdb ]
98 then
99 mv /etc/samba/secrets.tdb /var/lib/samba/
102 # If upgrading from a previous 2.999 snapshot, move the passdb.tdb
103 # database into /var/lib.
105 if [ -n "$2" ] && dpkg --compare-versions "$2" lt 2.999+3.0.alpha23-5 \
106 && [ -e /etc/samba/passdb.tdb -a ! -e /var/lib/samba/passdb.tdb ]
107 then
108 mv /etc/samba/passdb.tdb /var/lib/samba/
111 # --- End of FHS migration code ---
113 # If upgrading from a previous 2.999 snapshot, clear the broken
114 # registry.tdb file.
115 if [ -n "$2" ] && dpkg --compare-versions "$2" gt 2.99.cvs.20020713-1 \
116 && dpkg --compare-versions "$2" lt 2.999+3.0cvs20020805-1
117 then
118 rm -f /var/lib/samba/registry.tdb
121 # ------------------------- Debconf questions start ---------------------
123 # Run Samba as daemons or from inetd?
124 db_get samba/run_mode || true
125 RUN_MODE="${RET}"
127 TMPFILE=/etc/default/samba.dpkg-tmp
128 sed -e "s/^[[:space:]]*RUN_MODE[[:space:]]*=.*/RUN_MODE=\"${RUN_MODE}\"/" \
129 < ${INITCONFFILE} >${TMPFILE}
130 chmod a+r ${TMPFILE}
131 mv -f ${TMPFILE} ${INITCONFFILE}
133 # Generate a smbpasswd file?
134 db_get samba/generate_smbpasswd || true
135 GENERATE_SMBPASSWD="${RET}"
137 db_get samba/tdbsam || true
138 PDB_MIGRATE="${RET}"
140 # Done with debconf now.
141 db_stop
143 umask 066
145 # FIXME: disable if ldapsam support is enabled?
146 # FIXME: we don't want to pass these through the smbpasswd backend,
147 # some of the faking can cause us problems!
148 if [ "${GENERATE_SMBPASSWD}" = "true" -a ! -e /var/lib/samba/passdb.tdb -a ! -e /etc/samba/smbpasswd ]; then
149 getent passwd | /usr/sbin/mksmbpasswd > /etc/samba/smbpasswd
150 pdbedit -i smbpasswd -e tdbsam
151 rm /etc/samba/smbpasswd
154 umask 022
156 if [ -n "$2" -a -e /etc/samba/smbpasswd \
157 -a ! -e /var/lib/samba/passdb.tdb -a "$PDB_MIGRATE" = "true" ] \
158 && dpkg --compare-versions "$2" lt 2.99.cvs.20020713-2
159 then
160 umask 066
161 pdbedit -i smbpasswd -e tdbsam
162 rm /etc/samba/smbpasswd
163 umask 022
165 # The database has been moved, now make sure we can still find it.
166 PASSDB=`sed -n -e"s/^[[:space:]]*\[global\]/\[global\]/i
167 /^\[global\]/,/^[[:space:]]*\[/ \
168 s/^[[:space:]]*passdb backend[[:space:]]*=[[:space:]]*//pi" \
169 < /etc/samba/smb.conf \
170 | tail -n 1`
171 if echo "$PASSDB" | egrep -q "(^|[[:space:]])smbpasswd"; then
172 if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
173 PASSDB=`echo $PASSDB | sed -e's/\(^\|[[:space:]]\)smbpasswd/\1tdbsam/'`
176 if ! echo "$PASSDB" | egrep -q "(^|[[:space:]])tdbsam"; then
177 PASSDB="tdbsam $PASSDB"
179 TMPFILE=/etc/samba/smb.conf.dpkg-tmp
180 sed -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
181 /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
182 s/^\([[:space:]]*\)passdb backend[[:space:]]*=.*/\1passdb backend = ${PASSDB}/i" \
183 < /etc/samba/smb.conf >${TMPFILE}
184 chmod a+r ${TMPFILE}
185 mv -f ${TMPFILE} /etc/samba/smb.conf
188 # ------------------------- Debconf questions end ---------------------
190 # Handle removal of nmbd from inetd.conf, which is no longer a supported
191 # configuration.
192 if dpkg --compare-versions "$2" lt 2.999+3.0.alpha20-4; then
193 update-inetd --remove netbios-ns
196 # We want to add these entries to inetd.conf commented out. Otherwise
197 # UDP traffic could make inetd to start nmbd or smbd right during
198 # the configuration stage.
199 if [ -z "$2" ]; then
200 update-inetd --add "#<off># netbios-ssn stream tcp nowait root /usr/sbin/tcpd /usr/sbin/smbd"
203 if [ "$RUN_MODE" = "daemons" ]; then
204 update-inetd --disable netbios-ssn
205 else
206 update-inetd --enable netbios-ssn
209 # This check is a safety net: the /etc/samba/smbpasswd file must have
210 # permissions 600.
211 if [ -f /etc/samba/smbpasswd ]; then
212 chmod 600 /etc/samba/smbpasswd
215 # Do the same check for /var/backup/smbpasswd.bak, just in case.
216 if [ -f /var/backups/smbpasswd.bak ]; then
217 chmod 600 /var/backups/smbpasswd.bak
220 # Delete old /etc/samba/debian_config file, which is not used anymore
221 # now that we are using debconf.
222 rm -f /etc/samba/debian_config
224 # Move old log files to the new location of Samba's log files
225 mv -f /var/log/nmb* /var/log/samba/ 2> /dev/null || true
226 mv -f /var/log/smb* /var/log/samba/ 2> /dev/null || true
228 #DEBHELPER#
230 exit 0