##-----------------------------------------------------------------------------
## sshd.ext - fli4l extended configuration check                   3.0.1
##
##        P L E A S E   R E A D   T H E   D O C U M E N T A T I O N ,
##                      S E E   R E A D M E . T X T
##
##        B I T T E  U N B E D I N G T   D I E   D O K U M E N T A T I O N
##              L E S E N ,  S I E H E   R E A D M E . T X T
##
## Creation:     26.06.2001  fm
## Last Update:  $Id: sshd.ext 10552 2005-12-07 10:04:38Z babel $
##
## Copyright (c) 2001 Frank Meyer <frank@fli4l.de>
##
## 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.
##-----------------------------------------------------------------------------

if (opt_sshd)
then
  provides sshd version 3.0.1

  set sshd_filename="dropbearmulti_server"

  if (opt_scp)
  then
    set sshd_filename="${sshd_filename}_scp"
  fi

  if (opt_ssh_client)
  then
    set sshd_filename="${sshd_filename}_client"
  fi

  stat("$config_dir/etc/ssh/known_hosts", known_hosts_file)
  if(known_hosts_file_res == "OK")
  then
    add_to_opt "etc/ssh/known_hosts" "mode=600 flags=utxt"
  fi

  stat("$config_dir/etc/plink/sshhostkeys", known_hosts_file)
  if(known_hosts_file_res == "OK")
  then
    add_to_opt "etc/plink/sshhostkeys" "mode=644 flags=utxt"
  fi

  set convert="no"
  foreach pkf in sshd_public_keyfile_%
  do
    stat("$config_dir/etc/ssh/$pkf", publickeyfile)
    if(publickeyfile_res == "OK")
    then
      add_to_opt "etc/ssh/$pkf" "mode=400 flags=utxt"
    else
      error "sshd: missing public keyfile $config_dir/etc/ssh/$pkf in SSHD_PUBLIC_KEYFILE_$i"
    fi
  done

  foreach pkf in sshd_private_keyfile_%
  do
    stat("$config_dir/etc/ssh/$pkf", privatekeyfile)
    if(privatekeyfile_res == "OK")
    then
      add_to_opt "etc/ssh/$pkf" "mode=644 flags=utxt"
      fgrep("$config_dir/etc/ssh/$pkf", "^-----BEGIN [D|R]SA PRIVATE KEY-----$")
      if (fgrep_match_n != 0)
      then
          set convert="yes"
      fi
    else
      error "sshd: missing private keyfile $config_dir/etc/ssh/$pkf in SSHD_PRIVATE_KEYFILE_$i"
    fi
  done

  if (convert == "yes")
  then
    if (!opt_ssh_client)
    then
       set sshd_filename="${sshd_filename}_client"
    fi
    set sshd_filename="${sshd_filename}_convert"
  fi

  add_to_opt "files/usr/sbin/$sshd_filename" "mode=555"

fi
