File: motd.c

package info (click to toggle)
shadow 1%3A4.17.4-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 66,752 kB
  • sloc: sh: 44,927; ansic: 34,406; xml: 12,252; exp: 3,691; makefile: 1,633; python: 722; yacc: 622; perl: 120; sed: 16
file content (61 lines) | stat: -rw-r--r-- 1,150 bytes parent folder | download | duplicates (2)
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
/*
 * SPDX-FileCopyrightText: 1989 - 1991, Julianne Frances Haugh
 * SPDX-FileCopyrightText: 1996 - 1997, Marek Michałkiewicz
 * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko
 * SPDX-FileCopyrightText: 2010       , Nicolas François
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <config.h>

#ident "$Id$"

#include <stdio.h>
#include <string.h>

#include "defines.h"
#include "getdef.h"
#include "prototypes.h"


/*
 * motd -- output the /etc/motd file
 *
 * motd() determines the name of a login announcement file and outputs
 * it to the user's terminal at login time.  The MOTD_FILE configuration
 * option is a colon-delimited list of filenames.
 */
int
motd(void)
{
	FILE *fp;
	char *motdlist;
	const char *motdfile;
	char *mb;
	int c;

	motdfile = getdef_str ("MOTD_FILE");
	if (NULL == motdfile)
		return 0;

	motdlist = strdup(motdfile);
	if (motdlist == NULL)
		return -1;

	mb = motdlist;
	while (NULL != (motdfile = strsep(&mb, ":"))) {
		fp = fopen (motdfile, "r");
		if (fp == NULL)
			continue;

		while ((c = getc(fp)) != EOF) {
			putchar(c);
		}
		fclose(fp);
	}
	fflush (stdout);

	free (motdlist);
	return 0;
}