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
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.
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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 * Copyright (c) 2000 by Sun Microsystems, Inc.
27 * All rights reserved.
30 #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:mailst.c 2.7 */
34 extern int xfappend();
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
48 mailst(user
, subj
, str
, infile
, errfile
)
49 char *user
, *subj
, *str
, *infile
, *errfile
;
51 register FILE *fp
, *fi
;
56 /* get rid of some stuff that could be dangerous */
57 if ( (c
= strpbrk(user
, Shchar
)) != NULL
) {
61 /* limit subject to one line */
62 if ((c
= strchr(subj
, '\n')) != NULL
) {
63 strncpy(subject
, subj
, c
-subj
);
64 subject
[c
-subj
] = NULLCHAR
;
68 (void) snprintf(cmd
, sizeof (cmd
), "%s %s '%s'", PATH
, MAIL
, user
);
69 if ((fp
= popen(cmd
, "w")) == NULL
)
71 (void) fprintf(fp
, "To: %s\nSubject: %s\n\n%s\n", user
, subj
, str
);
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
);
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");
93 else if ((fi
= fopen(infile
, "r")) == NULL
) {
95 "\n\t===== stdin was unreadable =====\n"), fp
);
96 snprintf(cmd
, sizeof (cmd
),
97 "user %s, stdin %s", user
, infile
);
98 logent(cmd
, "UNREADABLE");
101 fputs(gettext("\n\t===== stdin was =====\n"), fp
);
102 if (xfappend(fi
, fp
) != SUCCESS
)
104 "\n\t===== well, i tried =====\n"), fp
);
114 static char un
[2*NAMESIZE
];
122 for ( ; *envp
; envp
++) {
123 if(PREFIX("LOGNAME", *envp
)) {
124 (void) snprintf(un
, sizeof (un
), "LOGNAME=%s",p
);
133 setuucp(p
) char *p
; {}