3 ### Generate .ssh/authorized_keys files for SSH services
5 ### (c) 2015 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This program is free software; you can redistribute it and/or modify
11 ### it under the terms of the GNU General Public License as published by
12 ### the Free Software Foundation; either version 2 of the License, or
13 ### (at your option) any later version.
15 ### This program is distributed in the hope that it will be useful,
16 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ### GNU General Public License for more details.
20 ### You should have received a copy of the GNU General Public License
21 ### along with this program; if not, write to the Free Software
22 ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
27 allow_agent_forwarding
=no
28 allow_x11_forwarding
=no
29 allow_port_forwarding
=no
31 env
="SSHSVC_USER=@user"
41 *@user
*) e
=${e%%@user*}$user${e#*@user} ;;
44 case $progressp in nil
) break ;; esac
46 line
="environment=\"$e\""
50 make_full_key_line
() {
52 line
=$
(make_key_line
"$user")
53 case "${cmd+t},$line" in
55 t
,*) line
="command=\"$cmd\",$line" ;;
57 case "$allow_port_forwarding" in
58 yes) ;; *) line
="no-port-forwarding,$line" ;;
60 case "$allow_x11_forwarding" in
61 yes) ;; *) line
="no-X11-forwarding,$line" ;;
63 case "$allow_agent_forwarding" in
64 yes) ;; *) line
="no-agent-forwarding,$line" ;;
67 yes) ;; *) line
="no-pty,$line" ;;
72 ## Scan the command line.
73 prog
=${0##*/} bogusp
=nil
74 conf
=sshsvc.conf out
=authorized_keys keysdir
=keys
75 head=sshsvc-authkeys.
head tail=sshsvc-authkeys.
tail
77 echo "usage: $prog [-c CONF] [-k DIR] [-o OUTPUT] [-H HEAD] [-T TAIL]"
79 while getopts hc
:k
:o
:H
:T
: opt
; do
90 shift $
(( $OPTIND - 1 ))
91 case $# in 0) ;; *) bogusp
=t
;; esac
92 case $bogusp in t
) usage
>&2; exit 1 ;; esac
94 ## Read the configuration.
95 case $conf in /*) ;; *) conf
=.
/$conf ;; esac
101 *) exec 3>"$out.new" ;;
104 echo >&3 "### GENERATED by $prog"
106 if [ -r
"$head" ]; then cat "$head" >&3; fi
108 for i
in "$keysdir"/*.pub
; do
109 u
=${i#*/}; u
=${u%.*}; u
=${u%%!*}
110 l
=$
(make_full_key_line
"$u")
115 if [ -r
"$tail" ]; then cat "$tail" >&3; fi
117 echo >&3 "### GENERATED by $prog"
122 *) mv "$out.new" "$out" ;;