1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains code for "zshutdown_notify", a utility called by
3 * shutdown(8) to do Zephyr notification on shutdown.
5 * Created by: C. Anthony Della Fera
7 * $Id: zshutdown_notify.c,v 1.14 1997/10/25 21:47:15 ghudson Exp $
9 * Copyright (c) 1987, 1993 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
15 #include <zephyr/mit-copyright.h>
16 #include <zephyr/zephyr.h>
18 #include <sys/socket.h>
22 static const char *rcsid_zshutdown_notify_c =
23 "$Id: zshutdown_notify.c,v 1.14 1997/10/25 21:47:15 ghudson Exp $";
27 #define N_CLASS "FILSRV"
28 #define N_OPCODE "SHUTDOWN"
29 #define N_DEF_FORMAT "From $sender:\n@bold(Shutdown message from $1 at $time)\n@center(System going down, message is:)\n\n$2\n\n@center(@bold($3))"
33 #define SVC_NAME "rcmd"
37 * Standard warning strings appended as extra fields to
41 static char warning[] = "Please detach any filesystems you may have\nattached from this host by typing detach -host %s";
51 char hostname[MAXHOSTNAMELEN];
52 char msgbuff[BUFSIZ], message[Z_MAXPKTLEN], *ptr;
54 char *msg[N_FIELD_CNT];
56 char tkt_filename[MAXPATHLEN];
58 char hn2[MAXHOSTNAMELEN];
60 extern char *krb_get_phost();
63 if (gethostname(hostname, MAXHOSTNAMELEN) < 0) {
64 com_err(argv[0], errno, "while finding hostname");
68 if ((hp = gethostbyname(hostname)) != NULL)
69 (void) strcpy(hostname, hp->h_name);
73 sprintf(scratch, warning, hostname);
77 (void) sprintf(tkt_filename, "/tmp/tkt_zshut_%d", getpid());
78 krb_set_tkt_string(tkt_filename);
80 cp = krb_get_phost(hostname);
82 (void) strcpy(hn2, cp);
84 fprintf(stderr, "%s: can't figure out canonical hostname\n",argv[0]);
87 if (retval = krb_get_lrealm(rlm, 1)) {
88 fprintf(stderr, "%s: can't get local realm: %s\n",
89 argv[0], krb_get_err_text(retval));
92 if (retval = krb_get_svc_in_tkt(SVC_NAME, hn2, rlm,
93 SERVER_SERVICE, SERVER_INSTANCE, 1,
95 fprintf(stderr, "%s: can't get tickets: %s\n",
96 argv[0], krb_get_err_text(retval));
101 if ((retval = ZInitialize()) != ZERR_NONE) {
102 com_err(argv[0], retval, "while initializing");
109 if (!fgets(msgbuff, sizeof(msgbuff), stdin))
111 if ((strlen(msgbuff) + (ptr - message)) > Z_MAXPKTLEN){
114 (void) strcpy(ptr, msgbuff);
118 (void) memset((char *)¬ice, 0, sizeof(notice));
120 notice.z_kind = N_KIND;
122 notice.z_class = N_CLASS;
123 notice.z_class_inst = hostname;
124 notice.z_opcode = N_OPCODE;
126 notice.z_message_len = 0;
127 notice.z_recipient = "";
128 notice.z_default_format = N_DEF_FORMAT;
130 retval = ZSendList(¬ice, msg, N_FIELD_CNT, ZAUTH);
135 if (retval != ZERR_NONE) {
136 com_err(argv[0], retval, "while sending notice");