1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
|
#! /bin/sh /usr/share/dpatch/dpatch-run
## 20xgethostname.dpatch by LaMont Jones <lamont@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Use xgethostname instead of gethostname
@DPATCH@
diff -urNad util-linux/lib/Makefile /tmp/dpep.YGr3Vu/util-linux/lib/Makefile
--- util-linux/lib/Makefile 2002-11-02 06:51:26.000000000 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/lib/Makefile 2004-12-15 08:20:23.534627822 -0700
@@ -1,8 +1,9 @@
include ../make_include
include ../MCONFIG
-all: err.o my_reboot.o setproctitle.o env.o carefulputc.o xstrncpy.o md5.o
-
+all: err.o my_reboot.o setproctitle.o env.o carefulputc.o md5.o \
+ xgethostname.o xstrncpy.o
+
err.o: err.c
my_reboot.o: my_reboot.c linux_reboot.h
@@ -15,6 +16,8 @@
xstrncpy.o: xstrncpy.h
+xgethostname.o: xgethostname.h
+
md5.o: md5.c md5.h
.PHONY: clean
diff -urNad util-linux/lib/README.xgethostname /tmp/dpep.YGr3Vu/util-linux/lib/README.xgethostname
--- util-linux/lib/README.xgethostname 1969-12-31 17:00:00.000000000 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/lib/README.xgethostname 2004-12-15 08:20:23.534627822 -0700
@@ -0,0 +1,76 @@
+A wrapper for gethostname that automatically checks system limitations.
+
+Latest version can always be found at:
+ftp://walfield.org/pub/people/neal/xgethostname/xgethostname-latest.tar.gz
+
+Author:
+Neal H Walfield <neal@cs.uml.edu>
+
+Version:
+April 13, 2002
+
+ChangeLog:
+2002-04-13 Neal H Walfield <neal@walfield.org>
+
+ * VERSION: Update to 20010413.
+ * Release version 20010413.
+
+2002-04-13 Neal H Walfield <neal@walfield.org>
+
+ * xgethostname.c (xgethostname): gethostname returns -1 on error,
+ not the error code. There is no need to use realloc as it copies
+ the unused buffer.
+
+2001-08-03 Neal H Walfield <neal@cs.uml.edu>
+
+ * VERSION: Update to 20010803.
+ * Release version 20010803.
+
+2001-08-03 Neal H Walfield <neal@cs.uml.edu>
+
+ * Makefile: Make no assumptions about the make that the user
+ will be using.
+ * xgethostname.c (xgethostname): Be explicitly sure that the
+ returned buffer is NULL terminated.
+ Always compile in the while (err = ENAMETOOLONG) loop; this
+ may help to catch a very exotic implementation and does not
+ hurt anyone.
+
+2001-08-02 Neal H Walfield <neal@cs.uml.edu>
+
+ * Release version 20010802.
+
+2001-08-01 Neal H Walfield <neal@cs.uml.edu>
+
+ * Makefile: New file.
+ * README: New file.
+ * xgethostname.c (xgethostname) [!_SC_HOST_NAME_MAX]: Should
+ not be subject to this condition.
+ (xgethostname): If the system defines a limit < 256 and > 0,
+ do not artificially inflate it, rather, respect it.
+
+2001-07-30 Neal H Walfield <neal@cs.uml.edu>
+
+ * REAMME: Move from here . . .
+ * xgethostname.2: to here.
+ Format it for man.
+
+2001-07-30 Neal H Walfield <neal@cs.uml.edu>
+
+ * README: Fix grammer error.
+ * xgethostname.c: Likewise.
+ * xgethostname.h: Likewise.
+
+ * Makefile: New file.
+
+2001-07-29 Neal H Walfield <neal@cs.uml.edu>
+
+ * Release version 20010729.
+
+ * AUTHOR: New file.
+ * ChangeLog: New file.
+ * COPYING: New file.
+ * README: New file.
+ * VERSION: New file.
+ * xgethostname.c: New file.
+ * xgethostname.h: New file.
diff -urNad util-linux/lib/xgethostname.2 /tmp/dpep.YGr3Vu/util-linux/lib/xgethostname.2
--- util-linux/lib/xgethostname.2 1969-12-31 17:00:00.000000000 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/lib/xgethostname.2 2004-12-15 08:20:23.534627822 -0700
@@ -0,0 +1,37 @@
+.TH XGETHOSTNAME 2 "30 July 2001" "xgethostname"
+.SH NAME
+xgethostname \- get the host name.
+.SH
+SYNOPSIS
+.BI "char *xgethostname (void);"
+.SH DESCRIPTION
+The xhostname function is intended to replace
+.BR gethostname(2),
+a function used to access the host name. The old interface is
+inflexable given that it assumes the existance of the
+.BR MAXHOSTNAMELEN
+macro, which neither
+.BR POSIX
+nor the proposed
+.BR "Single Unix Specification version 3"
+guarantee to be defined.
+.SH RETURN VALUE
+On success, a malloced, null terminated (possibly truncated)
+string containing the host name is returned. On failure,
+.I NULL
+is returned and errno is set.
+.SH ERRORS
+.TP
+.BR ENOMEM
+Failed to allocate memory.
+.LP
+As
+.BR xgethostname
+is really just a wrapper around your systems
+.BR gethostname (2),
+see that man page for additional details.
+.SH "SEE ALSO"
+.BR gethostname (2)
+.SH AUTHOR
+.BR xgethostname
+was written by Neal H Walfield <neal@cs.uml.edu>.
diff -urNad util-linux/lib/xgethostname.c /tmp/dpep.YGr3Vu/util-linux/lib/xgethostname.c
--- util-linux/lib/xgethostname.c 1969-12-31 17:00:00.000000000 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/lib/xgethostname.c 2004-12-15 08:20:23.535627607 -0700
@@ -0,0 +1,126 @@
+/* Copyright (c) 2001 Neal H Walfield <neal@cs.uml.edu>.
+
+ This file is placed into the public domain. Its distribution
+ is unlimited.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* NAME
+
+ xgethostname - get the host name.
+
+ SYNOPSIS
+
+ char *xgethostname (void);
+
+ DESCRIPTION
+
+ The xhostname function is intended to replace gethostname(2), a
+ function used to access the host name. The old interface is
+ inflexable given that it assumes the existance of the
+ MAXHOSTNAMELEN macro, which neither POSIX nor the proposed
+ Single Unix Specification version 3 guarantee to be defined.
+
+ RETURN VALUE
+
+ On success, a malloced, null terminated (possibly truncated)
+ string containing the host name is returned. On failure,
+ NULL is returned and errno is set.
+ */
+
+#include <sys/param.h> /* For MAXHOSTNAMELEN */
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include "xgethostname.h"
+
+char *
+xgethostname (void)
+{
+ int size = 0;
+ int addnull = 0;
+ char *buf;
+ int err;
+
+#ifdef MAXHOSTNAMELEN
+ size = MAXHOSTNAMELEN;
+ addnull = 1;
+#else /* MAXHOSTNAMELEN */
+#ifdef _SC_HOST_NAME_MAX
+ size = sysconf (_SC_HOST_NAME_MAX);
+ addnull = 1;
+#endif /* _SC_HOST_NAME_MAX */
+ if (size <= 0)
+ size = 256;
+#endif /* MAXHOSTNAMELEN */
+
+ buf = malloc (size + addnull);
+ if (! buf)
+ {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ err = gethostname (buf, size);
+ while (err == -1 && errno == ENAMETOOLONG)
+ {
+ free (buf);
+
+ size *= 2;
+ buf = malloc (size + addnull);
+ if (! buf)
+ {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ err = gethostname (buf, size);
+ }
+
+ if (err)
+ {
+ if (buf)
+ free (buf);
+ errno = err;
+ return NULL;
+ }
+
+ if (addnull)
+ buf[size] = '\0';
+
+ return buf;
+}
+
+#ifdef WANT_TO_TEST_XGETHOSTNAME
+#include <stdio.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+ char *hostname;
+
+ hostname = xgethostname ();
+ if (! hostname)
+ {
+ perror ("xgethostname");
+ return 1;
+ }
+
+ printf ("%s\n", hostname);
+ free (hostname);
+
+ return 0;
+}
+#endif /* WANT_TO_TEST_XGETHOSTNAME */
diff -urNad util-linux/lib/xgethostname.h /tmp/dpep.YGr3Vu/util-linux/lib/xgethostname.h
--- util-linux/lib/xgethostname.h 1969-12-31 17:00:00.000000000 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/lib/xgethostname.h 2004-12-15 08:20:23.535627607 -0700
@@ -0,0 +1,48 @@
+/* Copyright (c) 2001 Neal H Walfield <neal@cs.uml.edu>.
+
+ This file is placed into the public domain. Its distribution
+ is unlimited.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* NAME
+
+ xgethostname - get the host name.
+
+ SYNOPSIS
+
+ char *xgethostname (void);
+
+ DESCRIPTION
+
+ The xhostname function is intended to replace gethostname(2), a
+ function used to access the host name. The old interface is
+ inflexable given that it assumes the existance of the
+ MAXHOSTNAMELEN macro, which neither POSIX nor the proposed
+ Single Unix Specification version 3 guarantee to be defined.
+
+ RETURN VALUE
+
+ On success, a malloced, null terminated (possibly truncated)
+ string containing the host name is returned. On failure,
+ NULL is returned and errno is set.
+ */
+
+#ifndef XGETHOSTNAME
+#define XGETHOSTNAME
+
+char * xgethostname (void);
+
+#endif /* XGETHOSTNAME */
+
diff -urNad util-linux/login-utils/Makefile /tmp/dpep.YGr3Vu/util-linux/login-utils/Makefile
--- util-linux/login-utils/Makefile 2004-11-23 09:06:57.000000000 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/login-utils/Makefile 2004-12-15 08:20:23.530628681 -0700
@@ -100,18 +100,18 @@
shutdown.o simpleinit.o: $(LIB)/linux_reboot.h
wall.o: ttymsg.h $(LIB)/carefulputc.h
-agetty: agetty.o $(LIB)/xstrncpy.o
+agetty: agetty.o $(LIB)/xstrncpy.o $(LIB)/xgethostname.o
chfn: chfn.o islocal.o setpwnam.o $(SELINUXOBJS) $(LIB)/env.o $(LIB)/xstrncpy.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM) $(SELINUXLLIB)
chsh: chsh.o islocal.o setpwnam.o $(SELINUXOBJS) $(LIB)/env.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM) $(SELINUXLLIB)
-last: last.o
+last: last.o $(LIB)/xgethostname.o
ifeq "$(HAVE_PAM)" "yes"
-login: login.o $(LIB)/setproctitle.o $(LIB)/xstrncpy.o
+login: login.o $(LIB)/setproctitle.o $(LIB)/xstrncpy.o $(LIB)/xgethostname.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM) $(SELINUXLLIB)
else
-login: login.o $(LIB)/xstrncpy.o $(LIB)/setproctitle.o checktty.o
+login: login.o $(LIB)/xstrncpy.o $(LIB)/xgethostname.o $(LIB)/setproctitle.o checktty.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(SELINUXLLIB)
endif
@@ -134,7 +134,8 @@
newgrp.o: $(LIB)/pathnames.h
$(CC) -c $(CFLAGS) $(PAMFL) newgrp.c
-wall: wall.o ttymsg.o $(LIB)/carefulputc.o $(LIB)/xstrncpy.o
+wall: wall.o ttymsg.o $(LIB)/carefulputc.o $(LIB)/xstrncpy.o \
+ $(LIB)/xgethostname.o
LOGINFLAGS=
ifeq "$(USE_TTY_GROUP)" "yes"
@@ -147,7 +148,8 @@
LOGINFLAGS += -DDO_STAT_MAIL
endif
-login.o: login.c $(LIB)/pathnames.h $(LIB)/setproctitle.c $(LIB)/setproctitle.h
+login.o: login.c $(LIB)/pathnames.h $(LIB)/setproctitle.c $(LIB)/setproctitle.h \
+ $(LIB)/xgethostname.h
$(CC) -c $(CFLAGS) $(PAMFL) $(LOGINFLAGS) login.c
# LOGINFLAGS here only for -DUSE_TTY_GROUP
diff -urNad util-linux/login-utils/agetty.c /tmp/dpep.YGr3Vu/util-linux/login-utils/agetty.c
--- util-linux/login-utils/agetty.c 2004-12-15 08:20:12.865921144 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/login-utils/agetty.c 2004-12-15 08:20:23.531628466 -0700
@@ -1019,10 +1019,12 @@
#endif
#ifdef __linux__
{
- char hn[MAXHOSTNAMELEN+1];
+ char *hn;
- (void) gethostname(hn, MAXHOSTNAMELEN);
+ if (!(hn = xgethostname()))
+ error(_("can't get hostname"));
write(1, hn, strlen(hn));
+ free(hn);
}
#endif
(void) write(1, LOGIN, sizeof(LOGIN) - 1); /* always show login prompt */
diff -urNad util-linux/login-utils/last.c /tmp/dpep.YGr3Vu/util-linux/login-utils/last.c
--- util-linux/login-utils/last.c 2002-03-08 15:59:41.000000000 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/login-utils/last.c 2004-12-15 08:20:23.532628252 -0700
@@ -49,6 +49,7 @@
#include "pathnames.h"
#include "nls.h"
+#include "xgethostname.h"
#define SECDAY (24*60*60) /* seconds in a day */
#define NO 0 /* false/no */
@@ -430,15 +431,15 @@
hostconv(char *arg) {
static int first = 1;
static char *hostdot,
- name[MAXHOSTNAMELEN];
+ *name;
char *argdot;
if (!(argdot = strchr(arg, '.')))
return;
if (first) {
first = 0;
- if (gethostname(name, sizeof(name))) {
- perror(_("last: gethostname"));
+ if (!(name = xgethostname())) {
+ perror(_("last: can't get hostname"));
exit(1);
}
hostdot = strchr(name, '.');
diff -urNad util-linux/login-utils/login.c /tmp/dpep.lVXZel/util-linux/login-utils/login.c
--- util-linux/login-utils/login.c 2004-12-04 19:37:12.000000000 -0700
+++ /tmp/dpep.lVXZel/util-linux/login-utils/login.c 2004-12-15 08:26:47.887008273 -0700
@@ -116,6 +116,7 @@
#include "my_crypt.h"
#include "login.h"
#include "xstrncpy.h"
+#include "xgethostname.h"
#include "nls.h"
#ifdef __linux__
@@ -356,7 +355,7 @@
int ask, fflag, hflag, pflag, cnt, errsv;
int quietlog, passwd_req;
char *domain, *ttyn;
- char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10];
+ char tname[sizeof(_PATH_TTY) + 10];
char *termenv;
char *childArgv[10];
char *buff;
@@ -398,9 +397,11 @@
* -h is used by other servers to pass the name of the remote
* host to login so that it may be placed in utmp and wtmp
*/
- gethostname(tbuf, sizeof(tbuf));
- xstrncpy(thishost, tbuf, sizeof(thishost));
- domain = index(tbuf, '.');
+ if (!(thishost = xgethostname())) {
+ fprintf(stderr, _("login: can't get hostname\n"));
+ exit(1);
+ }
+ domain = index(thishost, '.');
username = tty_name = hostname = NULL;
fflag = hflag = pflag = 0;
diff -urNad util-linux/login-utils/wall.c /tmp/dpep.YGr3Vu/util-linux/login-utils/wall.c
--- util-linux/login-utils/wall.c 2004-12-15 08:20:13.006890841 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/login-utils/wall.c 2004-12-15 08:20:23.533628037 -0700
@@ -54,6 +54,7 @@
#include <utmp.h>
#include "nls.h"
+#include "xgethostname.h"
#include "xstrncpy.h"
#include "ttymsg.h"
#include "pathnames.h"
@@ -146,8 +147,7 @@
time_t now;
FILE *fp;
int fd;
- char *p, *whom, *where, hostname[MAXHOSTNAMELEN],
- lbuf[MAXHOSTNAMELEN + 320],
+ char *p, *whom, *where, *hostname, lbuf[1024],
tmpname[sizeof(_PATH_TMP) + 20];
(void)sprintf(tmpname, "%s/wall.XXXXXX", _PATH_TMP);
@@ -158,6 +158,9 @@
(void)unlink(tmpname);
if (!nobanner) {
+ char *mesg, *mesg_notice;
+ int mesg_size, size;
+
if (!(whom = getlogin()) || !*whom)
whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???";
if (!whom || strlen(whom) > 100)
@@ -165,7 +168,11 @@
where = ttyname(2);
if (!where || strlen(where) > 100)
where = "somewhere";
- (void)gethostname(hostname, sizeof(hostname));
+ if (!(hostname = xgethostname())) {
+ (void)fprintf(stderr, _("%s: can't get hostname.\n"),
+ progname);
+ exit(1);
+ }
(void)time(&now);
lt = localtime(&now);
@@ -178,13 +185,35 @@
*/
/* snprintf is not always available, but the sprintf's here
will not overflow as long as %d takes at most 100 chars */
+
+ mesg_notice = _("Broadcast Message from %s@%s");
+ mesg_size = strlen(whom) + strlen(hostname) +
+ strlen(mesg_notice);
+ if (!(mesg = malloc(mesg_size))) {
+ (void)fprintf(stderr, _("%s: Out of memory!\n"),
+ progname);
+ exit(1);
+ }
+
(void)fprintf(fp, "\r%79s\r\n", " ");
- (void)sprintf(lbuf, _("Broadcast Message from %s@%s"),
- whom, hostname);
- (void)fprintf(fp, "%-79.79s\007\007\r\n", lbuf);
- (void)sprintf(lbuf, " (%s) at %d:%02d ...",
- where, lt->tm_hour, lt->tm_min);
- (void)fprintf(fp, "%-79.79s\r\n", lbuf);
+ (void)sprintf(mesg, mesg_notice, whom, hostname);
+ (void)fprintf(fp, "%-79.79s\007\007\r\n", mesg);
+
+ mesg_notice = " (%s) at %d:%02d ...";
+ size = strlen(mesg_notice) + strlen(where);
+ if (mesg_size < size) {
+ if (!realloc(mesg, size)) {
+ (void)fprintf(stderr, _("%s: Out of memory!\n"),
+ progname);
+ exit(1);
+ }
+ }
+
+ (void)sprintf(mesg, mesg_notice, where,
+ lt->tm_hour, lt->tm_min);
+ (void)fprintf(fp, "%-79.79s\r\n", mesg);
+
+ free(mesg);
}
(void)fprintf(fp, "%79s\r\n", " ");
diff -urNad util-linux/misc-utils/Makefile /tmp/dpep.YGr3Vu/util-linux/misc-utils/Makefile
--- util-linux/misc-utils/Makefile 2004-12-05 12:09:12.000000000 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/misc-utils/Makefile 2004-12-15 08:20:23.533628037 -0700
@@ -96,8 +96,8 @@
mcookie.o: mcookie.c $(LIB)/md5.h
reset: reset.sh
script: script.o
-write.o: $(LIB)/carefulputc.h
-write: write.o $(LIB)/carefulputc.o
+write.o: $(LIB)/carefulputc.h $(LIB)/xgethostname.h
+write: write.o $(LIB)/carefulputc.o $(LIB)/xgethostname.o
ifeq "$(HAVE_NCURSES)" "yes"
setterm: setterm.o
diff -urNad util-linux/misc-utils/write.c /tmp/dpep.YGr3Vu/util-linux/misc-utils/write.c
--- util-linux/misc-utils/write.c 2001-03-15 03:09:58.000000000 -0700
+++ /tmp/dpep.YGr3Vu/util-linux/misc-utils/write.c 2004-12-15 08:20:23.533628037 -0700
@@ -64,9 +64,10 @@
#include <paths.h>
#include "pathnames.h"
#include "carefulputc.h"
+#include "xgethostname.h"
#include "nls.h"
-void search_utmp(char *, char *, char *, uid_t);
+void search_utmp(char *, char **, char *, uid_t);
void do_write(char *, char *, uid_t);
void wr_fputs(char *);
static void done(int);
@@ -78,7 +79,7 @@
time_t atime;
uid_t myuid;
int msgsok, myttyfd;
- char tty[MAXPATHLEN], *mytty;
+ char *tty, *mytty;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -120,7 +121,7 @@
/* check args */
switch (argc) {
case 2:
- search_utmp(argv[1], tty, mytty, myuid);
+ search_utmp(argv[1], &tty, mytty, myuid);
do_write(tty, mytty, myuid);
break;
case 3:
@@ -189,8 +190,10 @@
*
* Special case for writing to yourself - ignore the terminal you're
* writing from, unless that's the only terminal with messages enabled.
+ *
+ * Returns tty as an allocated string.
*/
-void search_utmp(char *user, char *tty, char *mytty, uid_t myuid)
+void search_utmp(char *user, char **tty, char *mytty, uid_t myuid)
{
struct utmp u;
@@ -224,7 +227,11 @@
++nttys;
if (atime > bestatime) {
bestatime = atime;
- (void)strcpy(tty, atty);
+ if ((*tty = strdup(atty)) == NULL) {
+ (void)fprintf(stderr,
+ _("write: out of memory\n"));
+ exit(1);
+ }
}
}
}
@@ -236,7 +243,12 @@
}
if (nttys == 0) {
if (user_is_me) { /* ok, so write to yourself! */
- (void)strcpy(tty, mytty);
+ if ((*tty = strdup(mytty)) == NULL) {
+ (void)fprintf(stderr,
+ _("write: out of memory\n"));
+ exit(1);
+ }
+
return;
}
(void)fprintf(stderr,
@@ -245,7 +257,7 @@
} else if (nttys > 1) {
(void)fprintf(stderr,
_("write: %s is logged in more than once; writing to %s\n"),
- user, tty);
+ user, *tty);
}
}
@@ -257,19 +269,23 @@
{
struct stat s;
- char path[MAXPATHLEN];
+ char *path;
- if (strlen(tty) + 6 > sizeof(path))
- return(1);
+ if ((path = malloc(strlen(tty) + sizeof("/dev/") + 1)) == NULL){
+ (void)fprintf(stderr,_("write: out of memory\n"));
+ exit(1);
+ }
(void)sprintf(path, "/dev/%s", tty);
if (stat(path, &s) < 0) {
if (showerror)
(void)fprintf(stderr,
"write: %s: %s\n", path, strerror(errno));
+ free(path);
return(1);
}
*msgsokP = (s.st_mode & (S_IWRITE >> 3)) != 0; /* group write bit */
*atimeP = s.st_atime;
+ free(path);
return(0);
}
@@ -280,7 +296,7 @@
char *login, *pwuid, *nows;
struct passwd *pwd;
time_t now;
- char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512];
+ char *path, *host, *host_tmp, line[512];
/* Determine our login name(s) before the we reopen() stdout */
if ((pwd = getpwuid(myuid)) != NULL)
@@ -290,8 +306,10 @@
if ((login = getlogin()) == NULL)
login = pwuid;
- if (strlen(tty) + 6 > sizeof(path))
+ if ((path = malloc(strlen(tty) + sizeof("/dev/") + 1)) == NULL) {
+ (void)fprintf(stderr, _("write: out of memory\n"));
exit(1);
+ }
(void)sprintf(path, "/dev/%s", tty);
if ((freopen(path, "w", stdout)) == NULL) {
(void)fprintf(stderr, "write: %s: %s\n",
@@ -299,12 +317,16 @@
exit(1);
}
+ free(path);
+
(void)signal(SIGINT, done);
(void)signal(SIGHUP, done);
/* print greeting */
- if (gethostname(host, sizeof(host)) < 0)
- (void)strcpy(host, "???");
+ if ((host_tmp = xgethostname()) != NULL)
+ host = host_tmp;
+ else
+ host = "???";
now = time((time_t *)NULL);
nows = ctime(&now);
nows[16] = '\0';
@@ -317,6 +339,8 @@
login, host, mytty, nows + 11);
printf("\r\n");
+ free(host_tmp);
+
while (fgets(line, sizeof(line), stdin) != NULL)
wr_fputs(line);
}
|