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 /*
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 #pragma ident "%Z%%M% %I% %E% SMI"
41
42 #include "talk.h"
43 #include "ctl.h"
44 #include <locale.h>
45 #include <pwd.h>
46 #include <sys/systeminfo.h>
47
48 char *getlogin(), *ttyname(int);
49
50 extern CTL_MSG msg;
51
52 /*
53 * Determine the local and remote user, tty, and machines
54 */
55
56 struct hostent *gethostbyname();
57
58 void
59 get_names(argc, argv)
60 int argc;
61 char *argv[];
62 {
63 char hostname[HOST_NAME_LENGTH + 1];
64 char *rem_name;
65 char *my_name;
66 char *my_machine_name;
67 char *rem_machine_name;
68 char *my_tty;
69 char *rem_tty;
70 char *ptr;
71 int name_length;
72
73 if (argc < 2) {
74 fprintf(stderr,
75 "Usage: talk %s\n", gettext("address [terminal]"));
76 exit(1);
77 }
78 if (!isatty(0)) {
79 fprintf(stderr,
80 gettext("Standard input must be a tty, not a pipe or a file\n"));
81 exit(1);
82 }
83
84 if (!isatty(1)) {
85 fprintf(stderr,
86 gettext("Standard output must be a tty, not a pipe or a file\n"));
87 exit(1);
88 }
89
90 if ((my_name = getlogin()) == NULL) {
91 struct passwd *pass = getpwuid(getuid());
92 if (pass != NULL)
93 my_name = pass->pw_name;
94 }
95 if (my_name == NULL) {
96 fprintf(stderr,
97 gettext("Who are you? You have no entry in /etc/utmp! Aborting..\n"));
98 exit(1);
99 }
100
101 name_length = HOST_NAME_LENGTH;
102 (void) sysinfo(SI_HOSTNAME, hostname, name_length);
103 my_machine_name = hostname;
104
105 my_tty = strrchr(ttyname(0), '/') + 1;
106
107 /*
108 * check for, and strip out, the machine name of the target
109 */
110
111 for (ptr = argv[1]; *ptr != '\0' &&
112 *ptr != '@' &&
113 *ptr != ':' &&
114 *ptr != '!' &&
115 *ptr != '.'; ptr++) {
116 }
117
118 if (*ptr == '\0') {
119
120 /* this is a local to local talk */
121
122 rem_name = argv[1];
123 rem_machine_name = my_machine_name;
124
125 } else {
126
|
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 /*
23 * Copyright 2017 Gary Mills
24 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31 /*
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
34 * All Rights Reserved
35 *
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
38 * contributors.
39 */
40
41 #include "talk.h"
42 #include "ctl.h"
43 #include <locale.h>
44 #include <pwd.h>
45 #include <sys/systeminfo.h>
46
47 char *getlogin(), *ttyname(int);
48
49 extern CTL_MSG msg;
50
51 /*
52 * Determine the local and remote user, tty, and machines
53 */
54
55 struct hostent *gethostbyname();
56
57 void
58 get_names(argc, argv)
59 int argc;
60 char *argv[];
61 {
62 char hostname[HOST_NAME_LENGTH + 1];
63 char *rem_name;
64 char *my_name;
65 char *my_machine_name;
66 char *rem_machine_name;
67 char *rem_tty;
68 char *ptr;
69 int name_length;
70
71 if (argc < 2) {
72 fprintf(stderr,
73 "Usage: talk %s\n", gettext("address [terminal]"));
74 exit(1);
75 }
76 if (!isatty(0)) {
77 fprintf(stderr,
78 gettext("Standard input must be a tty, not a pipe or a file\n"));
79 exit(1);
80 }
81
82 if (!isatty(1)) {
83 fprintf(stderr,
84 gettext("Standard output must be a tty, not a pipe or a file\n"));
85 exit(1);
86 }
87
88 if ((my_name = getlogin()) == NULL) {
89 struct passwd *pass = getpwuid(getuid());
90 if (pass != NULL)
91 my_name = pass->pw_name;
92 }
93 if (my_name == NULL) {
94 fprintf(stderr,
95 gettext("Who are you? You have no entry in /etc/utmp! Aborting..\n"));
96 exit(1);
97 }
98
99 name_length = HOST_NAME_LENGTH;
100 (void) sysinfo(SI_HOSTNAME, hostname, name_length);
101 my_machine_name = hostname;
102
103 /*
104 * check for, and strip out, the machine name of the target
105 */
106
107 for (ptr = argv[1]; *ptr != '\0' &&
108 *ptr != '@' &&
109 *ptr != ':' &&
110 *ptr != '!' &&
111 *ptr != '.'; ptr++) {
112 }
113
114 if (*ptr == '\0') {
115
116 /* this is a local to local talk */
117
118 rem_name = argv[1];
119 rem_machine_name = my_machine_name;
120
121 } else {
122
|