17c478bd9Sstevel@tonic-gate /* 2*740638c8Sbw * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 57c478bd9Sstevel@tonic-gate 67c478bd9Sstevel@tonic-gate /* 77c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 87c478bd9Sstevel@tonic-gate * All rights reserved. 97c478bd9Sstevel@tonic-gate * 107c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted 117c478bd9Sstevel@tonic-gate * provided that the above copyright notice and this paragraph are 127c478bd9Sstevel@tonic-gate * duplicated in all such forms and that any documentation, 137c478bd9Sstevel@tonic-gate * advertising materials, and other materials related to such 147c478bd9Sstevel@tonic-gate * distribution and use acknowledge that the software was developed 157c478bd9Sstevel@tonic-gate * by the University of California, Berkeley. The name of the 167c478bd9Sstevel@tonic-gate * University may not be used to endorse or promote products derived 177c478bd9Sstevel@tonic-gate * from this software without specific prior written permission. 187c478bd9Sstevel@tonic-gate */ 197c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 207c478bd9Sstevel@tonic-gate 217c478bd9Sstevel@tonic-gate #include "defs.h" 227c478bd9Sstevel@tonic-gate #include <string.h> 237c478bd9Sstevel@tonic-gate #include <syslog.h> 247c478bd9Sstevel@tonic-gate #include <krb5defs.h> 257c478bd9Sstevel@tonic-gate #include <k5-int.h> 267c478bd9Sstevel@tonic-gate #include <priv_utils.h> 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #define NHOSTS 100 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * Remote distribution program. 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate char *distfile = NULL; 357c478bd9Sstevel@tonic-gate char Tmpfile[] = "/tmp/rdistXXXXXX"; 367c478bd9Sstevel@tonic-gate char *tmpname = &Tmpfile[5]; 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate int debug; /* debugging flag */ 397c478bd9Sstevel@tonic-gate int nflag; /* NOP flag, just print commands without executing */ 407c478bd9Sstevel@tonic-gate int qflag; /* Quiet. Don't print messages */ 417c478bd9Sstevel@tonic-gate int options; /* global options */ 427c478bd9Sstevel@tonic-gate int iamremote; /* act as remote server for transfering files */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate FILE *fin = NULL; /* input file pointer */ 457c478bd9Sstevel@tonic-gate int rem = -1; /* file descriptor to remote source/sink process */ 467c478bd9Sstevel@tonic-gate char host[32]; /* host name */ 477c478bd9Sstevel@tonic-gate int nerrs; /* number of errors while sending/receiving */ 487c478bd9Sstevel@tonic-gate char user[10]; /* user's name */ 497c478bd9Sstevel@tonic-gate char homedir[128]; /* user's home directory */ 507c478bd9Sstevel@tonic-gate char buf[RDIST_BUFSIZ]; /* general purpose buffer */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate struct passwd *pw; /* pointer to static area used by getpwent */ 537c478bd9Sstevel@tonic-gate struct group *gr; /* pointer to static area used by getgrent */ 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate char des_inbuf[2 * RDIST_BUFSIZ]; /* needs to be > largest read size */ 567c478bd9Sstevel@tonic-gate char des_outbuf[2 * RDIST_BUFSIZ]; /* needs to be > largest write size */ 577c478bd9Sstevel@tonic-gate krb5_data desinbuf, desoutbuf; 587c478bd9Sstevel@tonic-gate krb5_encrypt_block eblock; /* eblock for encrypt/decrypt */ 597c478bd9Sstevel@tonic-gate krb5_context bsd_context; 607c478bd9Sstevel@tonic-gate krb5_auth_context auth_context; 617c478bd9Sstevel@tonic-gate krb5_creds *cred; 627c478bd9Sstevel@tonic-gate char *krb_cache = NULL; 637c478bd9Sstevel@tonic-gate krb5_flags authopts; 647c478bd9Sstevel@tonic-gate krb5_error_code status; 657c478bd9Sstevel@tonic-gate enum kcmd_proto kcmd_proto = KCMD_NEW_PROTOCOL; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate int encrypt_flag = 0; /* Flag set when encryption is used */ 687c478bd9Sstevel@tonic-gate int krb5auth_flag = 0; /* Flag set, when KERBEROS is enabled */ 697c478bd9Sstevel@tonic-gate int debug_port = 0; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate int retval = 0; 727c478bd9Sstevel@tonic-gate char *krb_realm = NULL; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* Flag set, if -PN / -PO is specified */ 757c478bd9Sstevel@tonic-gate static boolean_t rcmdoption_done = B_FALSE; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate static int encrypt_done = 0; /* Flag set, if -x is specified */ 787c478bd9Sstevel@tonic-gate profile_options_boolean option[] = { 797c478bd9Sstevel@tonic-gate { "encrypt", &encrypt_flag, 0 }, 807c478bd9Sstevel@tonic-gate { NULL, NULL, 0 } 817c478bd9Sstevel@tonic-gate }; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate static char *rcmdproto = NULL; 847c478bd9Sstevel@tonic-gate profile_option_strings rcmdversion[] = { 857c478bd9Sstevel@tonic-gate { "rcmd_protocol", &rcmdproto, 0 }, 867c478bd9Sstevel@tonic-gate { NULL, NULL, 0 } 877c478bd9Sstevel@tonic-gate }; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate char *realmdef[] = { "realms", NULL, "rdist", NULL }; 907c478bd9Sstevel@tonic-gate char *appdef[] = { "appdefaults", "rdist", NULL }; 917c478bd9Sstevel@tonic-gate 92*740638c8Sbw static void usage(void); 93*740638c8Sbw static char *prtype(int t); 94*740638c8Sbw static void prsubcmd(struct subcmd *s); 95*740638c8Sbw static void docmdargs(int nargs, char *args[]); 96*740638c8Sbw void prnames(); 97*740638c8Sbw void prcmd(); 98*740638c8Sbw 997c478bd9Sstevel@tonic-gate int 1007c478bd9Sstevel@tonic-gate main(argc, argv) 1017c478bd9Sstevel@tonic-gate int argc; 1027c478bd9Sstevel@tonic-gate char *argv[]; 1037c478bd9Sstevel@tonic-gate { 1047c478bd9Sstevel@tonic-gate register char *arg; 1057c478bd9Sstevel@tonic-gate int cmdargs = 0; 1067c478bd9Sstevel@tonic-gate char *dhosts[NHOSTS], **hp = dhosts; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate pw = getpwuid(getuid()); 1117c478bd9Sstevel@tonic-gate if (pw == NULL) { 1127c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: Who are you?\n"), argv[0]); 1137c478bd9Sstevel@tonic-gate exit(1); 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate strncpy(user, pw->pw_name, sizeof (user)); 1167c478bd9Sstevel@tonic-gate user[sizeof (user) - 1] = '\0'; 1177c478bd9Sstevel@tonic-gate strncpy(homedir, pw->pw_dir, sizeof (homedir)); 1187c478bd9Sstevel@tonic-gate homedir[sizeof (homedir) - 1] = '\0'; 1197c478bd9Sstevel@tonic-gate gethostname(host, sizeof (host)); 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate while (--argc > 0) { 1227c478bd9Sstevel@tonic-gate if ((arg = *++argv)[0] != '-') 1237c478bd9Sstevel@tonic-gate break; 1247c478bd9Sstevel@tonic-gate if ((strcmp(arg, "-Server") == 0)) 1257c478bd9Sstevel@tonic-gate iamremote++; 1267c478bd9Sstevel@tonic-gate else while (*++arg) { 1277c478bd9Sstevel@tonic-gate if (strncmp(*argv, "-PO", 3) == 0) { 1287c478bd9Sstevel@tonic-gate if (rcmdoption_done == B_TRUE) { 1297c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("rdist: " 1307c478bd9Sstevel@tonic-gate "Only one of -PN " 1317c478bd9Sstevel@tonic-gate "and -PO allowed.\n")); 1327c478bd9Sstevel@tonic-gate usage(); 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate kcmd_proto = KCMD_OLD_PROTOCOL; 1357c478bd9Sstevel@tonic-gate krb5auth_flag++; 1367c478bd9Sstevel@tonic-gate rcmdoption_done = B_TRUE; 1377c478bd9Sstevel@tonic-gate break; 1387c478bd9Sstevel@tonic-gate } 1397c478bd9Sstevel@tonic-gate if (strncmp(*argv, "-PN", 3) == 0) { 1407c478bd9Sstevel@tonic-gate if (rcmdoption_done == B_TRUE) { 1417c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("rdist: " 1427c478bd9Sstevel@tonic-gate "Only one of -PN " 1437c478bd9Sstevel@tonic-gate "and -PO allowed.\n")); 1447c478bd9Sstevel@tonic-gate usage(); 1457c478bd9Sstevel@tonic-gate } 1467c478bd9Sstevel@tonic-gate kcmd_proto = KCMD_NEW_PROTOCOL; 1477c478bd9Sstevel@tonic-gate krb5auth_flag++; 1487c478bd9Sstevel@tonic-gate rcmdoption_done = B_TRUE; 1497c478bd9Sstevel@tonic-gate break; 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate switch (*arg) { 1537c478bd9Sstevel@tonic-gate #ifdef DEBUG 1547c478bd9Sstevel@tonic-gate case 'p': 1557c478bd9Sstevel@tonic-gate if (--argc <= 0) 1567c478bd9Sstevel@tonic-gate usage(); 1577c478bd9Sstevel@tonic-gate debug_port = htons(atoi(*++argv)); 1587c478bd9Sstevel@tonic-gate break; 1597c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 1607c478bd9Sstevel@tonic-gate case 'k': 1617c478bd9Sstevel@tonic-gate if (--argc <= 0) { 1627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("rdist: " 1637c478bd9Sstevel@tonic-gate "-k flag must be followed with " 1647c478bd9Sstevel@tonic-gate " a realm name.\n")); 1657c478bd9Sstevel@tonic-gate exit(1); 1667c478bd9Sstevel@tonic-gate } 1677c478bd9Sstevel@tonic-gate if ((krb_realm = strdup(*++argv)) == NULL) { 1687c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("rdist: " 1697c478bd9Sstevel@tonic-gate "Cannot malloc.\n")); 1707c478bd9Sstevel@tonic-gate exit(1); 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate krb5auth_flag++; 1737c478bd9Sstevel@tonic-gate break; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate case 'a': 1767c478bd9Sstevel@tonic-gate krb5auth_flag++; 1777c478bd9Sstevel@tonic-gate break; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate case 'x': 1807c478bd9Sstevel@tonic-gate encrypt_flag++; 1817c478bd9Sstevel@tonic-gate encrypt_done++; 1827c478bd9Sstevel@tonic-gate krb5auth_flag++; 1837c478bd9Sstevel@tonic-gate break; 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate case 'f': 1867c478bd9Sstevel@tonic-gate if (--argc <= 0) 1877c478bd9Sstevel@tonic-gate usage(); 1887c478bd9Sstevel@tonic-gate distfile = *++argv; 1897c478bd9Sstevel@tonic-gate if (distfile[0] == '-' && distfile[1] == '\0') 1907c478bd9Sstevel@tonic-gate fin = stdin; 1917c478bd9Sstevel@tonic-gate break; 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate case 'm': 1947c478bd9Sstevel@tonic-gate if (--argc <= 0) 1957c478bd9Sstevel@tonic-gate usage(); 1967c478bd9Sstevel@tonic-gate if (hp >= &dhosts[NHOSTS-2]) { 1977c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("rdist:" 1987c478bd9Sstevel@tonic-gate " too many destination" 1997c478bd9Sstevel@tonic-gate " hosts\n")); 2007c478bd9Sstevel@tonic-gate exit(1); 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate *hp++ = *++argv; 2037c478bd9Sstevel@tonic-gate break; 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate case 'd': 2067c478bd9Sstevel@tonic-gate if (--argc <= 0) 2077c478bd9Sstevel@tonic-gate usage(); 2087c478bd9Sstevel@tonic-gate define(*++argv); 2097c478bd9Sstevel@tonic-gate break; 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate case 'D': 2127c478bd9Sstevel@tonic-gate debug++; 2137c478bd9Sstevel@tonic-gate break; 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate case 'c': 2167c478bd9Sstevel@tonic-gate cmdargs++; 2177c478bd9Sstevel@tonic-gate break; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate case 'n': 2207c478bd9Sstevel@tonic-gate if (options & VERIFY) { 2217c478bd9Sstevel@tonic-gate printf("rdist: -n overrides -v\n"); 2227c478bd9Sstevel@tonic-gate options &= ~VERIFY; 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate nflag++; 2257c478bd9Sstevel@tonic-gate break; 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate case 'q': 2287c478bd9Sstevel@tonic-gate qflag++; 2297c478bd9Sstevel@tonic-gate break; 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate case 'b': 2327c478bd9Sstevel@tonic-gate options |= COMPARE; 2337c478bd9Sstevel@tonic-gate break; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate case 'R': 2367c478bd9Sstevel@tonic-gate options |= REMOVE; 2377c478bd9Sstevel@tonic-gate break; 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate case 'v': 2407c478bd9Sstevel@tonic-gate if (nflag) { 2417c478bd9Sstevel@tonic-gate printf("rdist: -n overrides -v\n"); 2427c478bd9Sstevel@tonic-gate break; 2437c478bd9Sstevel@tonic-gate } 2447c478bd9Sstevel@tonic-gate options |= VERIFY; 2457c478bd9Sstevel@tonic-gate break; 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate case 'w': 2487c478bd9Sstevel@tonic-gate options |= WHOLE; 2497c478bd9Sstevel@tonic-gate break; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate case 'y': 2527c478bd9Sstevel@tonic-gate options |= YOUNGER; 2537c478bd9Sstevel@tonic-gate break; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate case 'h': 2567c478bd9Sstevel@tonic-gate options |= FOLLOW; 2577c478bd9Sstevel@tonic-gate break; 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate case 'i': 2607c478bd9Sstevel@tonic-gate options |= IGNLNKS; 2617c478bd9Sstevel@tonic-gate break; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate default: 2647c478bd9Sstevel@tonic-gate usage(); 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate *hp = NULL; 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate mktemp(Tmpfile); 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate if (krb5auth_flag > 0) { 2737c478bd9Sstevel@tonic-gate status = krb5_init_context(&bsd_context); 2747c478bd9Sstevel@tonic-gate if (status) { 2757c478bd9Sstevel@tonic-gate com_err("rdist", status, 2767c478bd9Sstevel@tonic-gate gettext("while initializing krb5")); 2777c478bd9Sstevel@tonic-gate exit(1); 2787c478bd9Sstevel@tonic-gate } 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate /* Set up des buffers */ 2817c478bd9Sstevel@tonic-gate desinbuf.data = des_inbuf; 2827c478bd9Sstevel@tonic-gate desoutbuf.data = des_outbuf; 2837c478bd9Sstevel@tonic-gate desinbuf.length = sizeof (des_inbuf); 2847c478bd9Sstevel@tonic-gate desoutbuf.length = sizeof (des_outbuf); 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate /* 2877c478bd9Sstevel@tonic-gate * Get our local realm to look up local realm options. 2887c478bd9Sstevel@tonic-gate */ 2897c478bd9Sstevel@tonic-gate status = krb5_get_default_realm(bsd_context, &realmdef[1]); 2907c478bd9Sstevel@tonic-gate if (status) { 2917c478bd9Sstevel@tonic-gate com_err("rdist", status, 2927c478bd9Sstevel@tonic-gate gettext("while getting default realm")); 2937c478bd9Sstevel@tonic-gate exit(1); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate /* 2967c478bd9Sstevel@tonic-gate * See if encryption should be done for this realm 2977c478bd9Sstevel@tonic-gate */ 2987c478bd9Sstevel@tonic-gate profile_get_options_boolean(bsd_context->profile, realmdef, 2997c478bd9Sstevel@tonic-gate option); 3007c478bd9Sstevel@tonic-gate /* 3017c478bd9Sstevel@tonic-gate * Check the appdefaults section 3027c478bd9Sstevel@tonic-gate */ 3037c478bd9Sstevel@tonic-gate profile_get_options_boolean(bsd_context->profile, appdef, 3047c478bd9Sstevel@tonic-gate option); 3057c478bd9Sstevel@tonic-gate profile_get_options_string(bsd_context->profile, appdef, 3067c478bd9Sstevel@tonic-gate rcmdversion); 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate if ((encrypt_done > 0) || (encrypt_flag > 0)) { 3097c478bd9Sstevel@tonic-gate if (krb5_privacy_allowed() == TRUE) { 3107c478bd9Sstevel@tonic-gate encrypt_flag++; 3117c478bd9Sstevel@tonic-gate } else { 3127c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("rdist: " 3137c478bd9Sstevel@tonic-gate "Encryption not supported.\n")); 3147c478bd9Sstevel@tonic-gate exit(1); 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate if ((rcmdoption_done == B_FALSE) && (rcmdproto != NULL)) { 3197c478bd9Sstevel@tonic-gate if (strncmp(rcmdproto, "rcmdv2", 6) == 0) { 3207c478bd9Sstevel@tonic-gate kcmd_proto = KCMD_NEW_PROTOCOL; 3217c478bd9Sstevel@tonic-gate } else if (strncmp(rcmdproto, "rcmdv1", 6) == 0) { 3227c478bd9Sstevel@tonic-gate kcmd_proto = KCMD_OLD_PROTOCOL; 3237c478bd9Sstevel@tonic-gate } else { 3247c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Unrecognized " 3257c478bd9Sstevel@tonic-gate "KCMD protocol (%s)"), rcmdproto); 3267c478bd9Sstevel@tonic-gate exit(1); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate } 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate if (iamremote) { 3327c478bd9Sstevel@tonic-gate setreuid(getuid(), getuid()); 3337c478bd9Sstevel@tonic-gate server(); 3347c478bd9Sstevel@tonic-gate exit(nerrs != 0); 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate if (__init_suid_priv(0, PRIV_NET_PRIVADDR, NULL) == -1) { 3377c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 3387c478bd9Sstevel@tonic-gate "rdist needs to run with sufficient privilege\n"); 3397c478bd9Sstevel@tonic-gate exit(1); 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate if (cmdargs) 3437c478bd9Sstevel@tonic-gate docmdargs(argc, argv); 3447c478bd9Sstevel@tonic-gate else { 3457c478bd9Sstevel@tonic-gate if (fin == NULL) { 3467c478bd9Sstevel@tonic-gate if (distfile == NULL) { 3477c478bd9Sstevel@tonic-gate if ((fin = fopen("distfile", "r")) == NULL) 3487c478bd9Sstevel@tonic-gate fin = fopen("Distfile", "r"); 3497c478bd9Sstevel@tonic-gate } else 3507c478bd9Sstevel@tonic-gate fin = fopen(distfile, "r"); 3517c478bd9Sstevel@tonic-gate if (fin == NULL) { 3527c478bd9Sstevel@tonic-gate perror(distfile ? distfile : "distfile"); 3537c478bd9Sstevel@tonic-gate exit(1); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate } 3567c478bd9Sstevel@tonic-gate yyparse(); 3577c478bd9Sstevel@tonic-gate if (nerrs == 0) 3587c478bd9Sstevel@tonic-gate docmds(dhosts, argc, argv); 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate 361*740638c8Sbw return (nerrs != 0); 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate 364*740638c8Sbw static void 3657c478bd9Sstevel@tonic-gate usage() 3667c478bd9Sstevel@tonic-gate { 3677c478bd9Sstevel@tonic-gate printf(gettext("Usage: rdist [-nqbhirvwyDax] [-PN / -PO] " 3687c478bd9Sstevel@tonic-gate #ifdef DEBUG 3697c478bd9Sstevel@tonic-gate "[-p port] " 3707c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 3717c478bd9Sstevel@tonic-gate "[-k realm] [-f distfile] [-d var=value] [-m host] [file ...]\n")); 3727c478bd9Sstevel@tonic-gate printf(gettext("or: rdist [-nqbhirvwyDax] [-PN / -PO] [-p port] " 3737c478bd9Sstevel@tonic-gate "[-k realm] -c source [...] machine[:dest]\n")); 3747c478bd9Sstevel@tonic-gate exit(1); 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate /* 3787c478bd9Sstevel@tonic-gate * rcp like interface for distributing files. 3797c478bd9Sstevel@tonic-gate */ 380*740638c8Sbw static void 3817c478bd9Sstevel@tonic-gate docmdargs(nargs, args) 3827c478bd9Sstevel@tonic-gate int nargs; 3837c478bd9Sstevel@tonic-gate char *args[]; 3847c478bd9Sstevel@tonic-gate { 3857c478bd9Sstevel@tonic-gate register struct namelist *nl, *prev; 3867c478bd9Sstevel@tonic-gate register char *cp; 3877c478bd9Sstevel@tonic-gate struct namelist *files, *hosts; 3887c478bd9Sstevel@tonic-gate struct subcmd *cmds; 3897c478bd9Sstevel@tonic-gate char *dest; 3907c478bd9Sstevel@tonic-gate static struct namelist tnl = { NULL, NULL }; 3917c478bd9Sstevel@tonic-gate int i; 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate if (nargs < 2) 3947c478bd9Sstevel@tonic-gate usage(); 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate prev = NULL; 3977c478bd9Sstevel@tonic-gate for (i = 0; i < nargs - 1; i++) { 3987c478bd9Sstevel@tonic-gate nl = makenl(args[i]); 3997c478bd9Sstevel@tonic-gate if (prev == NULL) 4007c478bd9Sstevel@tonic-gate files = prev = nl; 4017c478bd9Sstevel@tonic-gate else { 4027c478bd9Sstevel@tonic-gate prev->n_next = nl; 4037c478bd9Sstevel@tonic-gate prev = nl; 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate cp = args[i]; 4087c478bd9Sstevel@tonic-gate if ((dest = index(cp, ':')) != NULL) 4097c478bd9Sstevel@tonic-gate *dest++ = '\0'; 4107c478bd9Sstevel@tonic-gate tnl.n_name = cp; 4117c478bd9Sstevel@tonic-gate hosts = expand(&tnl, E_ALL); 4127c478bd9Sstevel@tonic-gate if (nerrs) 4137c478bd9Sstevel@tonic-gate exit(1); 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate if (dest == NULL || *dest == '\0') 4167c478bd9Sstevel@tonic-gate cmds = NULL; 4177c478bd9Sstevel@tonic-gate else { 4187c478bd9Sstevel@tonic-gate cmds = makesubcmd(INSTALL); 4197c478bd9Sstevel@tonic-gate cmds->sc_options = options; 4207c478bd9Sstevel@tonic-gate cmds->sc_name = dest; 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate if (debug) { 4247c478bd9Sstevel@tonic-gate printf("docmdargs()\nfiles = "); 4257c478bd9Sstevel@tonic-gate prnames(files); 4267c478bd9Sstevel@tonic-gate printf("hosts = "); 4277c478bd9Sstevel@tonic-gate prnames(hosts); 4287c478bd9Sstevel@tonic-gate } 4297c478bd9Sstevel@tonic-gate insert(NULL, files, hosts, cmds); 4307c478bd9Sstevel@tonic-gate docmds(NULL, 0, NULL); 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate /* 4347c478bd9Sstevel@tonic-gate * Print a list of NAME blocks (mostly for debugging). 4357c478bd9Sstevel@tonic-gate */ 436*740638c8Sbw void 4377c478bd9Sstevel@tonic-gate prnames(nl) 4387c478bd9Sstevel@tonic-gate register struct namelist *nl; 4397c478bd9Sstevel@tonic-gate { 4407c478bd9Sstevel@tonic-gate printf("( "); 4417c478bd9Sstevel@tonic-gate while (nl != NULL) { 4427c478bd9Sstevel@tonic-gate printf("%s ", nl->n_name); 4437c478bd9Sstevel@tonic-gate nl = nl->n_next; 4447c478bd9Sstevel@tonic-gate } 4457c478bd9Sstevel@tonic-gate printf(")\n"); 4467c478bd9Sstevel@tonic-gate } 4477c478bd9Sstevel@tonic-gate 448*740638c8Sbw void 4497c478bd9Sstevel@tonic-gate prcmd(c) 4507c478bd9Sstevel@tonic-gate struct cmd *c; 4517c478bd9Sstevel@tonic-gate { 4527c478bd9Sstevel@tonic-gate extern char *prtype(); 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate while (c) { 4557c478bd9Sstevel@tonic-gate printf("c_type %s, c_name %s, c_label %s, c_files ", 4567c478bd9Sstevel@tonic-gate prtype(c->c_type), c->c_name, 4577c478bd9Sstevel@tonic-gate c->c_label? c->c_label : "NULL"); 4587c478bd9Sstevel@tonic-gate prnames(c->c_files); 4597c478bd9Sstevel@tonic-gate prsubcmd(c->c_cmds); 4607c478bd9Sstevel@tonic-gate c = c->c_next; 4617c478bd9Sstevel@tonic-gate } 4627c478bd9Sstevel@tonic-gate } 4637c478bd9Sstevel@tonic-gate 464*740638c8Sbw static void 4657c478bd9Sstevel@tonic-gate prsubcmd(s) 4667c478bd9Sstevel@tonic-gate struct subcmd *s; 4677c478bd9Sstevel@tonic-gate { 4687c478bd9Sstevel@tonic-gate extern char *prtype(); 4697c478bd9Sstevel@tonic-gate extern char *proptions(); 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate while (s) { 4727c478bd9Sstevel@tonic-gate printf("sc_type %s, sc_options %d%s, sc_name %s, sc_args ", 4737c478bd9Sstevel@tonic-gate prtype(s->sc_type), 4747c478bd9Sstevel@tonic-gate s->sc_options, proptions(s->sc_options), 4757c478bd9Sstevel@tonic-gate s->sc_name ? s->sc_name : "NULL"); 4767c478bd9Sstevel@tonic-gate prnames(s->sc_args); 4777c478bd9Sstevel@tonic-gate s = s->sc_next; 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate } 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate char * 4827c478bd9Sstevel@tonic-gate prtype(t) 4837c478bd9Sstevel@tonic-gate int t; 4847c478bd9Sstevel@tonic-gate { 4857c478bd9Sstevel@tonic-gate switch (t) { 4867c478bd9Sstevel@tonic-gate case EQUAL: 4877c478bd9Sstevel@tonic-gate return ("EQUAL"); 4887c478bd9Sstevel@tonic-gate case LP: 4897c478bd9Sstevel@tonic-gate return ("LP"); 4907c478bd9Sstevel@tonic-gate case RP: 4917c478bd9Sstevel@tonic-gate return ("RP"); 4927c478bd9Sstevel@tonic-gate case SM: 4937c478bd9Sstevel@tonic-gate return ("SM"); 4947c478bd9Sstevel@tonic-gate case ARROW: 4957c478bd9Sstevel@tonic-gate return ("ARROW"); 4967c478bd9Sstevel@tonic-gate case COLON: 4977c478bd9Sstevel@tonic-gate return ("COLON"); 4987c478bd9Sstevel@tonic-gate case DCOLON: 4997c478bd9Sstevel@tonic-gate return ("DCOLON"); 5007c478bd9Sstevel@tonic-gate case NAME: 5017c478bd9Sstevel@tonic-gate return ("NAME"); 5027c478bd9Sstevel@tonic-gate case STRING: 5037c478bd9Sstevel@tonic-gate return ("STRING"); 5047c478bd9Sstevel@tonic-gate case INSTALL: 5057c478bd9Sstevel@tonic-gate return ("INSTALL"); 5067c478bd9Sstevel@tonic-gate case NOTIFY: 5077c478bd9Sstevel@tonic-gate return ("NOTIFY"); 5087c478bd9Sstevel@tonic-gate case EXCEPT: 5097c478bd9Sstevel@tonic-gate return ("EXCEPT"); 5107c478bd9Sstevel@tonic-gate case PATTERN: 5117c478bd9Sstevel@tonic-gate return ("PATTERN"); 5127c478bd9Sstevel@tonic-gate case SPECIAL: 5137c478bd9Sstevel@tonic-gate return ("SPECIAL"); 5147c478bd9Sstevel@tonic-gate case OPTION: 5157c478bd9Sstevel@tonic-gate return ("OPTION"); 5167c478bd9Sstevel@tonic-gate } 517*740638c8Sbw return (NULL); 5187c478bd9Sstevel@tonic-gate } 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate char * 5217c478bd9Sstevel@tonic-gate proptions(o) 5227c478bd9Sstevel@tonic-gate int o; 5237c478bd9Sstevel@tonic-gate { 5247c478bd9Sstevel@tonic-gate return (printb((unsigned short) o, OBITS)); 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate char * 5287c478bd9Sstevel@tonic-gate printb(v, bits) 5297c478bd9Sstevel@tonic-gate register char *bits; 5307c478bd9Sstevel@tonic-gate register unsigned short v; 5317c478bd9Sstevel@tonic-gate { 5327c478bd9Sstevel@tonic-gate register int i, any = 0; 5337c478bd9Sstevel@tonic-gate register char c; 5347c478bd9Sstevel@tonic-gate char *p = buf; 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate bits++; 5377c478bd9Sstevel@tonic-gate if (bits) { 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate *p++ = '<'; 5407c478bd9Sstevel@tonic-gate while ((i = *bits++) != 0) { 5417c478bd9Sstevel@tonic-gate if (v & (1 << (i-1))) { 5427c478bd9Sstevel@tonic-gate if (any) 5437c478bd9Sstevel@tonic-gate *p++ = ','; 5447c478bd9Sstevel@tonic-gate any = 1; 5457c478bd9Sstevel@tonic-gate for (; (c = *bits) > 32; bits++) 5467c478bd9Sstevel@tonic-gate *p++ = c; 5477c478bd9Sstevel@tonic-gate } else 5487c478bd9Sstevel@tonic-gate for (; *bits > 32; bits++) 5497c478bd9Sstevel@tonic-gate ; 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate *p++ = '>'; 5527c478bd9Sstevel@tonic-gate } 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate *p = '\0'; 5557c478bd9Sstevel@tonic-gate return (buf); 5567c478bd9Sstevel@tonic-gate } 557