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
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[] =
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];
62 if (gethostname(hostname, MAXHOSTNAMELEN) < 0) {
63 com_err(argv[0], errno, "while finding hostname");
67 if ((hp = gethostbyname(hostname)) != NULL)
68 (void) strcpy(hostname, hp->h_name);
72 sprintf(scratch, warning, hostname);
76 (void) sprintf(tkt_filename, "/tmp/tkt_zshut_%d", getpid());
77 krb_set_tkt_string(tkt_filename);
79 cp = krb_get_phost(hostname);
81 (void) strcpy(hn2, cp);
83 fprintf(stderr, "%s: can't figure out canonical hostname\n",argv[0]);
86 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 retval = krb_get_svc_in_tkt(SVC_NAME, hn2, rlm,
93 SERVER_SERVICE, SERVER_INSTANCE, 1,
96 fprintf(stderr, "%s: can't get tickets: %s\n",
97 argv[0], krb_get_err_text(retval));
102 if ((retval = ZInitialize()) != ZERR_NONE) {
103 com_err(argv[0], retval, "while initializing");
110 if (!fgets(msgbuff, sizeof(msgbuff), stdin))
112 if ((strlen(msgbuff) + (ptr - message)) > Z_MAXPKTLEN){
115 (void) strcpy(ptr, msgbuff);
119 (void) memset((char *)¬ice, 0, sizeof(notice));
121 notice.z_kind = N_KIND;
123 notice.z_class = N_CLASS;
124 notice.z_class_inst = hostname;
125 notice.z_opcode = N_OPCODE;
127 notice.z_message_len = 0;
128 notice.z_recipient = "";
129 notice.z_default_format = N_DEF_FORMAT;
131 retval = ZSendList(¬ice, msg, N_FIELD_CNT, ZAUTH);
136 if (retval != ZERR_NONE) {
137 com_err(argv[0], retval, "while sending notice");