summaryrefslogtreecommitdiff
path: root/src/shutdown
diff options
context:
space:
mode:
Diffstat (limited to 'src/shutdown')
-rw-r--r--src/shutdown/deps-lib/hpr1
-rw-r--r--src/shutdown/hpr.h1
-rw-r--r--src/shutdown/hpr_confirm_hostname.c45
-rw-r--r--src/shutdown/s6-linux-init-hpr.c8
-rw-r--r--src/shutdown/s6-linux-init-shutdown.c7
5 files changed, 58 insertions, 4 deletions
diff --git a/src/shutdown/deps-lib/hpr b/src/shutdown/deps-lib/hpr
index 9e1493d..95dff6a 100644
--- a/src/shutdown/deps-lib/hpr
+++ b/src/shutdown/deps-lib/hpr
@@ -1,2 +1,3 @@
hpr_shutdown.o
hpr_wall.o
+hpr_confirm_hostname.o
diff --git a/src/shutdown/hpr.h b/src/shutdown/hpr.h
index 993f5ab..3dd0375 100644
--- a/src/shutdown/hpr.h
+++ b/src/shutdown/hpr.h
@@ -16,5 +16,6 @@
#define hpr_cancel() hpr_send("c", 1)
extern int hpr_shutdown (unsigned int, tain_t const *, unsigned int) ;
extern void hpr_wall (char const *) ;
+extern void hpr_confirm_hostname (void) ;
#endif
diff --git a/src/shutdown/hpr_confirm_hostname.c b/src/shutdown/hpr_confirm_hostname.c
new file mode 100644
index 0000000..00b3de7
--- /dev/null
+++ b/src/shutdown/hpr_confirm_hostname.c
@@ -0,0 +1,45 @@
+/* ISC license. */
+
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include <termios.h>
+#include <errno.h>
+#include <limits.h>
+
+#include <skalibs/allreadwrite.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/strerr2.h>
+
+#include "hpr.h"
+
+#define PROMPT "Please enter the machine's hostname: "
+
+void hpr_confirm_hostname (void)
+{
+ char name[HOST_NAME_MAX + 1] ;
+ char buf[HOST_NAME_MAX + 1] ;
+ char *p ;
+ ssize_t r ;
+ if (!isatty(0) || !isatty(1))
+ strerr_diefu1sys(100, "ask hostname confirmation") ;
+ if (gethostname(name, HOST_NAME_MAX) < 0)
+ strerr_diefu1sys(111, "get host name") ;
+ name[HOST_NAME_MAX] = 0 ;
+ p = strchr(name, '.') ;
+ if (p) *p = 0 ;
+ if (allwrite(1, PROMPT, sizeof(PROMPT)-1) < 0)
+ strerr_diefu1sys(111, "write to stdout") ;
+ if (tcdrain(1) < 0)
+ strerr_diefu1sys(111, "tcdrain stdout") ;
+ if (tcflush(0, TCIFLUSH) < 0)
+ strerr_diefu1sys(111, "empty stdin buffer") ;
+ r = fd_read(0, buf, HOST_NAME_MAX) ;
+ if (!r) errno = EPIPE ;
+ if (r <= 0) strerr_diefu1sys(111, "read from stdin") ;
+ buf[byte_chr(buf, r, '\n')] = 0 ;
+ p = strchr(buf, '.') ;
+ if (p) *p = 0 ;
+ if (strcasecmp(name, buf))
+ strerr_dief2x(1, "hostname mismatch: expecting ", name) ;
+}
diff --git a/src/shutdown/s6-linux-init-hpr.c b/src/shutdown/s6-linux-init-hpr.c
index d3cd74b..4ce4135 100644
--- a/src/shutdown/s6-linux-init-hpr.c
+++ b/src/shutdown/s6-linux-init-hpr.c
@@ -29,7 +29,7 @@
#define _PATH_WTMP "/dev/null/wtmp"
#endif
-#define USAGE "s6-linux-init-hpr [ -h | -p | -r ] [ -n ] [ -d | -w ] [ -W ] [ -f ]"
+#define USAGE "s6-linux-init-hpr [ -h | -p | -r ] [ -n ] [ -d | -w ] [ -W ] [ -f ] [ -i ]"
int main (int argc, char const *const *argv)
{
@@ -38,13 +38,14 @@ int main (int argc, char const *const *argv)
int dowtmp = 1 ;
int dowall = 1 ;
int dosync = 1 ;
+ int doconfirm = 0 ;
PROG = "s6-linux-init-hpr" ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "hprfdwWn", &l) ;
+ int opt = subgetopt_r(argc, argv, "hprfdwWni", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -56,6 +57,7 @@ int main (int argc, char const *const *argv)
case 'w' : dowtmp = 2 ; break ;
case 'W' : dowall = 0 ; break ;
case 'n' : dosync = 0 ; break ;
+ case 'i' : doconfirm = 0 ; break ;
default : strerr_dieusage(100, USAGE) ;
}
}
@@ -71,6 +73,8 @@ int main (int argc, char const *const *argv)
strerr_dief1sys(100, "nice try, peon") ;
}
+ if (doconfirm) hpr_confirm_hostname() ;
+
if (force)
{
if (dosync) sync() ;
diff --git a/src/shutdown/s6-linux-init-shutdown.c b/src/shutdown/s6-linux-init-shutdown.c
index 1492505..7966c5d 100644
--- a/src/shutdown/s6-linux-init-shutdown.c
+++ b/src/shutdown/s6-linux-init-shutdown.c
@@ -27,7 +27,7 @@
#define UT_NAMESIZE 32
#endif
-#define USAGE "s6-linux-init-shutdown [ -h [ -H | -P ] | -p | -r | -k ] [ -f | -F ] [ -a ] [ -t sec ] time [ message ] or s6-linux-init-shutdown -c [ message ]"
+#define USAGE "s6-linux-init-shutdown [ -h [ -H | -P ] | -p | -r | -k ] [ -f | -F ] [ -a ] [ -i ] [ -t sec ] time [ message ] or s6-linux-init-shutdown -c [ message ]"
#define dieusage() strerr_dieusage(100, USAGE)
#define AC_FILE "/etc/shutdown.allow"
@@ -198,6 +198,7 @@ int main (int argc, char const *const *argv)
int subwhat = 0 ;
int doactl = 0 ;
int docancel = 0 ;
+ int doconfirm = 0 ;
tain_t when ;
PROG = "s6-linux-init-shutdown" ;
@@ -205,7 +206,7 @@ int main (int argc, char const *const *argv)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "HPhprkafFct:", &l) ;
+ int opt = subgetopt_r(argc, argv, "HPhprkafFcit:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -219,6 +220,7 @@ int main (int argc, char const *const *argv)
case 'f' : /* talk to the hand */ break ;
case 'F' : /* no, the other hand */ break ;
case 'c' : docancel = 1 ; break ;
+ case 'i' : doconfirm = 1 ; break ;
case 't' : if (!uint0_scan(l.arg, &gracetime)) dieusage() ; break ;
default : strerr_dieusage(100, USAGE) ;
}
@@ -237,6 +239,7 @@ int main (int argc, char const *const *argv)
strerr_diefu1sys(111, "shutdown") ;
}
if (doactl) access_control() ;
+ if (doconfirm) hpr_confirm_hostname() ;
if (!tain_now_g()) strerr_warnw1sys("get current time") ;
if (docancel)
{