|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1983 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)get_names.c 5.8 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include "talk.h" ! 25: #include <sys/param.h> ! 26: #include <protocols/talkd.h> ! 27: #include <pwd.h> ! 28: ! 29: char *getlogin(); ! 30: char *ttyname(); ! 31: char *rindex(); ! 32: extern CTL_MSG msg; ! 33: ! 34: /* ! 35: * Determine the local and remote user, tty, and machines ! 36: */ ! 37: get_names(argc, argv) ! 38: int argc; ! 39: char *argv[]; ! 40: { ! 41: char hostname[MAXHOSTNAMELEN]; ! 42: char *his_name, *my_name; ! 43: char *my_machine_name, *his_machine_name; ! 44: char *my_tty, *his_tty; ! 45: register char *cp; ! 46: ! 47: if (argc < 2 ) { ! 48: printf("Usage: talk user [ttyname]\n"); ! 49: exit(-1); ! 50: } ! 51: if (!isatty(0)) { ! 52: printf("Standard input must be a tty, not a pipe or a file\n"); ! 53: exit(-1); ! 54: } ! 55: if ((my_name = getlogin()) == NULL) { ! 56: struct passwd *pw; ! 57: ! 58: if ((pw = getpwuid(getuid())) == NULL) { ! 59: printf("You don't exist. Go away.\n"); ! 60: exit(-1); ! 61: } ! 62: my_name = pw->pw_name; ! 63: } ! 64: gethostname(hostname, sizeof (hostname)); ! 65: my_machine_name = hostname; ! 66: /* check for, and strip out, the machine name of the target */ ! 67: for (cp = argv[1]; *cp && !any(*cp, "@:!."); cp++) ! 68: ; ! 69: if (*cp == '\0') { ! 70: /* this is a local to local talk */ ! 71: his_name = argv[1]; ! 72: his_machine_name = my_machine_name; ! 73: } else { ! 74: if (*cp++ == '@') { ! 75: /* user@host */ ! 76: his_name = argv[1]; ! 77: his_machine_name = cp; ! 78: } else { ! 79: /* host.user or host!user or host:user */ ! 80: his_name = cp; ! 81: his_machine_name = argv[1]; ! 82: } ! 83: *--cp = '\0'; ! 84: } ! 85: if (argc > 2) ! 86: his_tty = argv[2]; /* tty name is arg 2 */ ! 87: else ! 88: his_tty = ""; ! 89: get_addrs(my_machine_name, his_machine_name); ! 90: /* ! 91: * Initialize the message template. ! 92: */ ! 93: msg.vers = TALK_VERSION; ! 94: msg.addr.sa_family = htons(AF_INET); ! 95: msg.ctl_addr.sa_family = htons(AF_INET); ! 96: msg.id_num = htonl(0); ! 97: strncpy(msg.l_name, my_name, NAME_SIZE); ! 98: msg.l_name[NAME_SIZE - 1] = '\0'; ! 99: strncpy(msg.r_name, his_name, NAME_SIZE); ! 100: msg.r_name[NAME_SIZE - 1] = '\0'; ! 101: strncpy(msg.r_tty, his_tty, TTY_SIZE); ! 102: msg.r_tty[TTY_SIZE - 1] = '\0'; ! 103: } ! 104: ! 105: static ! 106: any(c, cp) ! 107: register char c, *cp; ! 108: { ! 109: ! 110: while (*cp) ! 111: if (c == *cp++) ! 112: return (1); ! 113: return (0); ! 114: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.