CRANIX session: Unterschied zwischen den Versionen

Aus CEPHALIX/CRANIX
K (Admin verschob die Seite Oss session nach CRANIX session, ohne dabei eine Weiterleitung anzulegen)
Zeile 40: Zeile 40:
 
  fi
 
  fi
  
==== oss_session@.service ====
+
==== cranix_session@.service ====
Die Datei /usr/lib/systemd/system/oss_session@.service mit dem Inhalt:
+
Die Datei /usr/lib/systemd/system/cranix_session@.service mit dem Inhalt:
  
 
  #  This file is part of systemd.
 
  #  This file is part of systemd.
Zeile 50: Zeile 50:
 
  #  (at your option) any later version.
 
  #  (at your option) any later version.
 
  [Unit]
 
  [Unit]
  Description=Notify OSS server of user login / logout
+
  Description=Notify CRANIX server of user login / logout
 
  Before=user@%i.service
 
  Before=user@%i.service
 
  [Service]
 
  [Service]
Zeile 59: Zeile 59:
 
  StandardOutput=journal
 
  StandardOutput=journal
 
  StandardError=syslog
 
  StandardError=syslog
  SyslogIdentifier=oss-client
+
  SyslogIdentifier=cranix_session
  ExecStart=/usr/bin/env PAM_USER=%i PAM_SERVICE=oss_session PAM_TYPE=open_session /home/profiles/linux/pam_session
+
  ExecStart=/usr/bin/env PAM_USER=%i PAM_SERVICE=cranix_session PAM_TYPE=open_session /home/profiles/linux/pam_session
  ExecStop=/usr/bin/env PAM_USER=%i PAM_SERVICE=oss_session PAM_TYPE=close_session /home/profiles/linux/pam_session
+
  ExecStop=/usr/bin/env PAM_USER=%i PAM_SERVICE=cranix_session PAM_TYPE=close_session /home/profiles/linux/pam_session
 
  [Install]
 
  [Install]
 
  WantedBy=user@%i.service
 
  WantedBy=user@%i.service
 
  
 
=== Anmeldung am Rechner ===
 
=== Anmeldung am Rechner ===

Version vom 7. April 2022, 11:03 Uhr

1 CRANIX Session

Auf dem Server wird eine Session für jede Anmeldung an einem Client-Rechner erstellt. Diese Session dient dazu, in der OSS-Admin-Oberfläche den angemeldeten Benutzer anzuzeigen bzw. zu entscheiden, in welches Verzeichnis eine ausgeteilte Datei gelangt.

1.1 Programme

Folgende Programme sind notwendig:

1.1.1 pam_session

Die Datei /home/profiles/linux/pam_session mit dem Inhalt:

#!/bin/bash
# Copyright (c) 2016 Peter Varkoly <peter@varkoly.de> Nürnberg, Germany.  All rights reserved.
# edited and supplied with additional systemd script oss_session@.service by Frank Schütte <fschuett@gymhim.de>
if [ "$PAM_USER" = "root" -o "$PAM_USER" = "gast" -o "$PAM_USER" = "sddm" ]
then
       exit 0;
fi
read p
TOKENFILE=TOKEN-$(id -u $PAM_USER)
rm -f /tmp/pw
#date >> /tmp/pw
#set >> /tmp/pw
#echo "PAM_USER: $PAM_USER, PAM_TYPE: $PAM_TYPE, PAM_SERVICE: $PAM_SERVICE TOKEN: $TOKENFILE" >> /tmp/pw
if [ "$PAM_TYPE" = "auth" ]; then
#    echo  curl --insecure -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: text/plain' -d "username=$PAM_USER&password=$p" 'https://admin/api/sessions/login' >>/tmp/pw
   TOKEN=$( curl --insecure -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: text/plain' --data-urlencode "username=$PAM_USER" --data-urlencode "password=$p" 'https://admin/api/sessions/login' )
   if [ "$TOKEN"  -a "${TOKEN:0:7}" != '{"code"' ]
   then
       echo $TOKEN > /tmp/$TOKENFILE
       exit 0
   else
       exit 1
   fi
fi
if [ "$PAM_TYPE" = "close_session" -a -s /tmp/$TOKENFILE ]; then
   if [ $PAM_SERVICE = "gdm" -o $PAM_SERVICE = "kdm" -o $PAM_SERVICE = "login" -o $PAM_SERVICE = "xdm" -o $PAM_SERVICE = "sddm" -o $PAM_SERVICE = "oss_session" ]; then
       TOKEN=$( cat /tmp/$TOKENFILE )
       curl --insecure -X DELETE --header 'Content-Type: application/x-www-form-urlencoded' --header "Authorization: Bearer $TOKEN" "https://admin/api/sessions/$TOKEN"
       rm -r /tmp/$TOKENFILE
   fi
   exit 0
fi

1.1.2 cranix_session@.service

Die Datei /usr/lib/systemd/system/cranix_session@.service mit dem Inhalt:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
[Unit]
Description=Notify CRANIX server of user login / logout
Before=user@%i.service
[Service]
Type=oneshot
RemainAfterExit=yes
Slice=user-%i.slice
RemainAfterExit=yes
StandardOutput=journal
StandardError=syslog
SyslogIdentifier=cranix_session
ExecStart=/usr/bin/env PAM_USER=%i PAM_SERVICE=cranix_session PAM_TYPE=open_session /home/profiles/linux/pam_session
ExecStop=/usr/bin/env PAM_USER=%i PAM_SERVICE=cranix_session PAM_TYPE=close_session /home/profiles/linux/pam_session
[Install]
WantedBy=user@%i.service

1.2 Anmeldung am Rechner

Bei der Anmeldung wird der Dienst PAM aktiviert, daher muss an entsprechenden Stellen die Datei pam_session ausgeführt werden. Dazu wird an geeigneter Stelle unter /etc/pam.d hinzugefügt:

session optional        pam_exec.so     /home/profiles/linux/pam_session

und

auth    required        pam_exec.so expose_authtok /home/profiles/linux/pam_session

Außerdem muss der oss_service@ aktiviert werden mit:

systemctl enable oss_session@

(Vorher muss eventuell ein

systemctl daemon-reload

ausgeführt werden.)