announce.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T
* All Rights Reserved.
*/
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California.
* All Rights Reserved.
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <time.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include "talkd_impl.h"
static int nofork = 0; /* to be set from the debugger */
/*
* Because the tty driver insists on attaching a terminal-less
* process to any terminal that it writes on, we must fork a child
* to protect ourselves.
*/
int
{
int status;
if (nofork) {
}
/* we are the parent, so wait for the child */
/* the fork failed */
return (FAILED);
}
do {
continue;
} else {
/* shouldn't happen */
print_error("wait");
return (FAILED);
}
}
if ((status & 0377) > 0) {
/* we were killed by some signal */
return (FAILED);
}
} else {
/* we are the child, go and do it */
}
/* NOTREACHED */
}
/*
* See if the user is accepting messages. If so, announce that
* a talk is requested.
*/
static int
{
#define TTY_BUFSZ 32
int fd;
struct passwd *p;
return (FAILED);
}
/* fopen uses O_CREAT|O_TRUNC, we don't want that */
return (PERMISSION_DENIED);
}
/* must be tty */
return (PERMISSION_DENIED);
}
/*
* open gratuitously attaches the talkd to any tty it opens, so
* disconnect us from the tty before we catch a signal
*/
(void) setsid();
return (PERMISSION_DENIED);
}
return (PERMISSION_DENIED);
}
return (PERMISSION_DENIED);
}
return (SUCCESS);
}
#define max(a, b) ((a) > (b) ? (a) : (b))
#define N_LINES 5
#define N_CHARS 300
/*
* Build a block of characters containing the message.
* It is sent blank filled and in a single block to
* try to keep the message in one piece if the recipient
* is in vi at the time.
*/
static void
{
struct tm *localclock;
int i, j, max_size;
/*
* (lines * strlen("\r\n")) + 1(NUL)].
*/
/*
* ( (length of (request->l_name) - 1(NUL)) *
* (strlen("M-") + 1('^') + 1(printable char)) ) + 1(NUL).
*/
int len, k;
i = 0;
max_size = 0;
i++;
"Message from Talk_Daemon@%s at %d:%02d ...", hostname,
i++;
for (j = 0, k = 0; j < len; j++) {
char c;
l_username[k++] = 'M';
l_username[k++] = '-';
}
l_username[k++] = '^';
/* add decimal 64 to the control character */
}
l_username[k++] = c;
} else {
}
}
l_username[k] = '\0';
i++;
i++;
i++;
*(bptr++) = '\n';
for (i = 0; i < N_LINES; i++) {
/* copy the line into the big buffer */
while (*lptr != '\0') {
}
/* pad out the rest of the lines with blanks */
*(bptr++) = ' ';
}
*(bptr++) = '\n';
}
*bptr = '\0';
(void) setsid();
}