1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
24
25 /*
26 * Copyright (c) 2000 by Sun Microsystems, Inc.
27 * All rights reserved.
28 */
29
30 #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:mailst.c 2.7 */
31
32 #include "uucp.h"
33
34 extern int xfappend();
35
36 /*
37 * fork and execute a mail command sending
38 * string (str) to user (user).
39 * If file is non-null, the file is also sent.
40 * (this is used for mail returned to sender.)
41 * user -> user to send mail to
42 * subj -> subject for the mail
43 * str -> string mailed to user
44 * infile -> optional stdin mailed to user
45 * errfile -> optional stderr mailed to user
46 */
47 void
mailst(user,subj,str,infile,errfile)48 mailst(user, subj, str, infile, errfile)
49 char *user, *subj, *str, *infile, *errfile;
50 {
51 register FILE *fp, *fi;
52 char cmd[BUFSIZ];
53 char subject[BUFSIZ];
54 char *c;
55
56 /* get rid of some stuff that could be dangerous */
57 if ( (c = strpbrk(user, Shchar)) != NULL) {
58 *c = NULLCHAR;
59 }
60
61 /* limit subject to one line */
62 if ((c = strchr(subj, '\n')) != NULL) {
63 strncpy(subject, subj, c-subj);
64 subject[c-subj] = NULLCHAR;
65 subj = subject;
66 }
67
68 (void) snprintf(cmd, sizeof (cmd), "%s %s '%s'", PATH, MAIL, user);
69 if ((fp = popen(cmd, "w")) == NULL)
70 return;
71 (void) fprintf(fp, "To: %s\nSubject: %s\n\n%s\n", user, subj, str);
72
73 /* copy back stderr */
74 if (*errfile != '\0' && NOTEMPTY(errfile) && (fi = fopen(errfile, "r")) != NULL) {
75 fputs(gettext("\n\t===== stderr was =====\n"), fp);
76 if (xfappend(fi, fp) != SUCCESS)
77 fputs(gettext("\n\t===== well, i tried =====\n"), fp);
78 (void) fclose(fi);
79 fputc('\n', fp);
80 }
81
82 /* copy back stdin */
83 if (*infile) {
84 if (!NOTEMPTY(infile))
85 fputs(gettext("\n\t===== stdin was empty =====\n"), fp);
86 else if (chkpth(infile, CK_READ) == FAIL) {
87 fputs(gettext( "\n\t===== stdin was"
88 " denied read permission =====\n"), fp);
89 snprintf(cmd, sizeof (cmd),
90 "user %s, stdin %s", user, infile);
91 logent(cmd, "DENIED");
92 }
93 else if ((fi = fopen(infile, "r")) == NULL) {
94 fputs(gettext(
95 "\n\t===== stdin was unreadable =====\n"), fp);
96 snprintf(cmd, sizeof (cmd),
97 "user %s, stdin %s", user, infile);
98 logent(cmd, "UNREADABLE");
99 }
100 else {
101 fputs(gettext("\n\t===== stdin was =====\n"), fp);
102 if (xfappend(fi, fp) != SUCCESS)
103 fputs(gettext(
104 "\n\t===== well, i tried =====\n"), fp);
105 (void) fclose(fi);
106 }
107 fputc('\n', fp);
108 }
109
110 (void) pclose(fp);
111 return;
112 }
113 #ifndef V7
114 static char un[2*NAMESIZE];
115 void
setuucp(p)116 setuucp(p)
117 char *p;
118 {
119 char **envp;
120
121 envp = Env;
122 for ( ; *envp; envp++) {
123 if(PREFIX("LOGNAME", *envp)) {
124 (void) snprintf(un, sizeof (un), "LOGNAME=%s",p);
125 envp[0] = &un[0];
126 }
127 }
128 return;
129 }
130 #else
131 /*ARGSUSED*/
132 void
setuucp(p)133 setuucp(p) char *p; {}
134 #endif
135