From: Paul Park Date: Tue, 15 Aug 1995 18:25:04 +0000 (+0000) Subject: Add support for -s scriptfile and fix gcc -Wall complaints X-Git-Tag: krb5-1.0-beta6~1318 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0856d376d5ea663aef7df59ef0d560e452566eb0;p=krb5.git Add support for -s scriptfile and fix gcc -Wall complaints git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6521 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/admin/edit/ChangeLog b/src/admin/edit/ChangeLog index 0e5756fd5..a6e127df0 100644 --- a/src/admin/edit/ChangeLog +++ b/src/admin/edit/ChangeLog @@ -1,4 +1,9 @@ +Tue Aug 15 14:22:50 EDT 1995 Paul Park (pjpark@mit.edu) + * kdb5_edit.c, ss_wrapper.c, cpw.c, kdb5_edit.h - Add support for + -s scriptfile and fix up assorted gcc -Wall complaints. + + Mon Aug 7 17:32:31 EDT 1995 Paul Park (pjpark@mit.edu) * cpw.c - Use krb5_string_to_keysalts() to generate a list of unique key/salt pairs supplied in argv. diff --git a/src/admin/edit/cpw.c b/src/admin/edit/cpw.c index 9c121f89f..f706b89c1 100644 --- a/src/admin/edit/cpw.c +++ b/src/admin/edit/cpw.c @@ -49,8 +49,9 @@ extern krb5_encrypt_block master_encblock; extern int valid_master_key; extern char *krb5_default_pwd_prompt1, *krb5_default_pwd_prompt2; extern krb5_boolean dbactive; +extern FILE *scriptfile; -static krb5_key_salt_tuple ks_tuple_rnd_def[] = { KEYTYPE_DES, 0 }; +static krb5_key_salt_tuple ks_tuple_rnd_def[] = {{ KEYTYPE_DES, 0 }}; static int ks_tuple_rnd_def_count = 1; static void @@ -62,15 +63,16 @@ enter_rnd_key(argc, argv, entry) krb5_error_code retval; int nprincs = 1; - if (retval = krb5_dbe_crk(edit_context, &master_encblock, ks_tuple_rnd_def, - ks_tuple_rnd_def_count, entry)) { + if ((retval = krb5_dbe_crk(edit_context, &master_encblock, + ks_tuple_rnd_def, + ks_tuple_rnd_def_count, entry))) { com_err(argv[0], retval, "while generating random key"); krb5_db_free_principal(edit_context, entry, nprincs); exit_status++; return; } - if (retval = krb5_db_put_principal(edit_context, entry, &nprincs)) { + if ((retval = krb5_db_put_principal(edit_context, entry, &nprincs))) { com_err(argv[0], retval, "while storing entry for '%s'\n", argv[1]); krb5_db_free_principal(edit_context, entry, nprincs); exit_status++; @@ -101,10 +103,12 @@ pre_key(argc, argv, newprinc, entry) com_err(argv[0], 0, Err_no_database); } else if (!valid_master_key) { com_err(argv[0], 0, Err_no_master_msg); - } else if (retval = krb5_parse_name(edit_context, argv[argc-1], newprinc)) { + } else if ((retval = krb5_parse_name(edit_context, + argv[argc-1], + newprinc))) { com_err(argv[0], retval, "while parsing '%s'", argv[argc-1]); - } else if (retval = krb5_db_get_principal(edit_context, *newprinc, entry, - &nprincs, &more)) { + } else if ((retval = krb5_db_get_principal(edit_context, *newprinc, entry, + &nprincs, &more))) { com_err(argv[0],retval,"while trying to get principal's db entry"); } else if ((nprincs > 1) || (more)) { krb5_db_free_principal(edit_context, entry, nprincs); @@ -132,7 +136,7 @@ void add_rnd_key(argc, argv) } switch (pre_key(argc, argv, &newprinc, &entry)) { case 0: - if (retval = create_db_entry(newprinc, &entry)) { + if ((retval = create_db_entry(newprinc, &entry))) { com_err(argv[0], retval, "While creating new db entry."); exit_status++; return; @@ -154,7 +158,6 @@ void change_rnd_key(argc, argv) int argc; char *argv[]; { - krb5_error_code retval; krb5_principal newprinc; krb5_db_entry entry; @@ -177,7 +180,7 @@ void change_rnd_key(argc, argv) } } -static krb5_key_salt_tuple ks_tuple_default[] = { KEYTYPE_DES, 0 }; +static krb5_key_salt_tuple ks_tuple_default[] = {{ KEYTYPE_DES, 0 }}; static int ks_tuple_count_default = 1; void @@ -193,19 +196,37 @@ enter_pwd_key(cmdname, princ, ks_tuple, ks_tuple_count, entry) krb5_error_code retval; int one = 1; - if (retval = krb5_read_password(edit_context, krb5_default_pwd_prompt1, - krb5_default_pwd_prompt2, - password, &pwsize)) { - com_err(cmdname, retval, "while reading password for '%s'", princ); - goto errout; + /* Prompt for password only if interactive */ + if (!scriptfile) { + if ((retval = krb5_read_password(edit_context, + krb5_default_pwd_prompt1, + krb5_default_pwd_prompt2, + password, &pwsize))) { + com_err(cmdname, retval, "while reading password for '%s'", princ); + goto errout; + } + } + else { + if (!fgets(password, pwsize, scriptfile)) { + com_err(cmdname, errno, "while reading password for '%s'", princ); + retval = errno; + goto errout; + } + else { + pwsize = strlen(password); + if (password[pwsize-1] == '\n') { + password[pwsize-1] = '\0'; + pwsize--; + } + } } if (ks_tuple_count == 0) { ks_tuple_count = ks_tuple_count_default; ks_tuple = ks_tuple_default; } - if (retval = krb5_dbe_cpw(edit_context, &master_encblock, ks_tuple, - ks_tuple_count, password, entry)) { + if ((retval = krb5_dbe_cpw(edit_context, &master_encblock, ks_tuple, + ks_tuple_count, password, entry))) { com_err(cmdname, retval, "while storing entry for '%s'\n", princ); memset(password, 0, sizeof(password)); /* erase it */ krb5_dbe_free_contents(edit_context, entry); @@ -214,7 +235,7 @@ enter_pwd_key(cmdname, princ, ks_tuple, ks_tuple_count, entry) memset(password, 0, sizeof(password)); /* erase it */ /* Write the entry back out and we're done */ - if (retval = krb5_db_put_principal(edit_context, entry, &one)) { + if ((retval = krb5_db_put_principal(edit_context, entry, &one))) { com_err(cmdname, retval, "while storing entry for '%s'\n", princ); } @@ -236,12 +257,9 @@ void change_pwd_key(argc, argv) { krb5_key_salt_tuple * ks_tuple = NULL; krb5_int32 n_ks_tuple = 0; - krb5_error_code retval; krb5_principal newprinc; krb5_db_entry entry; - krb5_kvno vno; - int one; int i; if (argc < 2) { @@ -278,7 +296,6 @@ void change_pwd_key(argc, argv) break; } -change_pwd_key_error:; if (ks_tuple) { free(ks_tuple); } @@ -301,7 +318,7 @@ void add_new_key(argc, argv) } switch (pre_key(argc, argv, &newprinc, &entry)) { case 0: - if (retval = create_db_entry(newprinc, &entry)) { + if ((retval = create_db_entry(newprinc, &entry))) { com_err(argv[0], retval, "While creating new db entry."); exit_status++; return; diff --git a/src/admin/edit/kdb5_edit.c b/src/admin/edit/kdb5_edit.c index 3fcdf239f..129c0d366 100644 --- a/src/admin/edit/kdb5_edit.c +++ b/src/admin/edit/kdb5_edit.c @@ -65,6 +65,11 @@ int exit_status = 0; krb5_context edit_context; +/* + * Script input, specified by -s. + */ +FILE *scriptfile = (FILE *) NULL; + static void usage(who, status) char *who; @@ -112,7 +117,7 @@ char *kdb5_edit_Init(argc, argv) retval = krb5_init_context(&edit_context); if (retval) { fprintf(stderr, "krb5_init_context failed with error #%ld\n", - retval); + (long) retval); exit(1); } krb5_init_ets(edit_context); @@ -122,7 +127,7 @@ char *kdb5_edit_Init(argc, argv) progname = argv[0]; - while ((optchar = getopt(argc, argv, "P:d:r:R:k:M:e:m")) != EOF) { + while ((optchar = getopt(argc, argv, "P:d:r:R:k:M:e:ms:")) != EOF) { switch(optchar) { case 'P': /* Only used for testing!!! */ mkey_password = optarg; @@ -162,6 +167,14 @@ char *kdb5_edit_Init(argc, argv) case 'm': manual_mkey = TRUE; break; + case 's': + /* Open the script file */ + if (!(scriptfile = fopen(optarg, "r"))) { + com_err(argv[0], errno, "while opening script file %s", + optarg); + exit(1); + } + break; case '?': default: usage(progname, 1); @@ -224,7 +237,7 @@ char *kdb5_edit_Init(argc, argv) interface will have umask = 77 but that is not a serious problem. */ (void) umask(077); - if (retval = krb5_kt_register(edit_context, &krb5_ktf_writable_ops)) { + if ((retval = krb5_kt_register(edit_context, &krb5_ktf_writable_ops))) { com_err(progname, retval, "while registering writable key table functions"); exit(1); @@ -259,12 +272,12 @@ char *kdb5_edit_Init(argc, argv) krb5_use_cstype(edit_context, &master_encblock, etype); if (cur_realm) { - if (retval = krb5_set_default_realm(edit_context, cur_realm)) { + if ((retval = krb5_set_default_realm(edit_context, cur_realm))) { com_err(progname, retval, "while setting default realm name"); exit(1); } } else { - if (retval = krb5_get_default_realm(edit_context, &defrealm)) { + if ((retval = krb5_get_default_realm(edit_context, &defrealm))) { com_err(progname, retval, "while retrieving default realm name"); exit(1); } @@ -294,8 +307,8 @@ princ_exists(pname, principal) krb5_error_code retval; krb5_kvno vno = 0; - if (retval = krb5_db_get_principal(edit_context, principal, &entry, - &nprincs, &more)) { + if ((retval = krb5_db_get_principal(edit_context, principal, &entry, + &nprincs, &more))) { com_err(pname, retval, "while attempting to verify principal's existence"); exit_status++; @@ -326,14 +339,15 @@ int create_db_entry(principal, newentry) newentry->max_renewable_life = mblock.max_rlife; newentry->expiration = mblock.expiration; - if (retval = krb5_copy_principal(edit_context, principal, &newentry->princ)) + if ((retval = krb5_copy_principal(edit_context, principal, + &newentry->princ))) return retval; - if (retval = krb5_timeofday(edit_context, &mod_princ.mod_date)) + if ((retval = krb5_timeofday(edit_context, &mod_princ.mod_date))) goto create_db_entry_error; - if (retval = krb5_copy_principal(edit_context, master_princ, - &mod_princ.mod_princ)) + if ((retval = krb5_copy_principal(edit_context, master_princ, + &mod_princ.mod_princ))) goto create_db_entry_error; retval = krb5_dbe_encode_mod_princ_data(edit_context, &mod_princ, newentry); @@ -409,13 +423,13 @@ set_dbname_help(pname, dbname) exit(1); } strcpy(current_dbname, dbname); - if (retval = krb5_db_set_name(edit_context, current_dbname)) { + if ((retval = krb5_db_set_name(edit_context, current_dbname))) { com_err(pname, retval, "while setting active database to '%s'", dbname); exit_status++; return(1); } - if (retval = krb5_db_init(edit_context)) { + if ((retval = krb5_db_init(edit_context))) { com_err(pname, retval, "while initializing database"); exit_status++; return(1); @@ -423,15 +437,15 @@ set_dbname_help(pname, dbname) /* assemble & parse the master key name */ - if (retval = krb5_db_setup_mkey_name(edit_context, mkey_name, cur_realm, 0, - &master_princ)) { + if ((retval = krb5_db_setup_mkey_name(edit_context, mkey_name, cur_realm, + 0, &master_princ))) { com_err(pname, retval, "while setting up master key name"); exit_status++; return(1); } nentries = 1; - if (retval = krb5_db_get_principal(edit_context, master_princ, &master_entry, - &nentries, &more)) { + if ((retval = krb5_db_get_principal(edit_context, master_princ, + &master_entry, &nentries, &more))) { com_err(pname, retval, "while retrieving master entry"); exit_status++; (void) krb5_db_fini(edit_context); @@ -477,10 +491,10 @@ set_dbname_help(pname, dbname) } free(scratch.data); mkey_password = 0; - } else if (retval = krb5_db_fetch_mkey(edit_context, master_princ, - &master_encblock, manual_mkey, - FALSE, stash_file, - 0, &master_keyblock)) { + } else if ((retval = krb5_db_fetch_mkey(edit_context, master_princ, + &master_encblock, manual_mkey, + FALSE, stash_file, + 0, &master_keyblock))) { com_err(pname, retval, "while reading master key"); com_err(pname, 0, "Warning: proceeding without master key"); exit_status++; @@ -489,8 +503,9 @@ set_dbname_help(pname, dbname) return(0); } valid_master_key = 1; - if (retval = krb5_db_verify_master_key(edit_context, master_princ, - &master_keyblock,&master_encblock)) { + if ((retval = krb5_db_verify_master_key(edit_context, master_princ, + &master_keyblock,&master_encblock)) + ) { com_err(pname, retval, "while verifying master key"); exit_status++; memset((char *)master_keyblock.contents, 0, master_keyblock.length); @@ -499,8 +514,8 @@ set_dbname_help(pname, dbname) dbactive = TRUE; return(1); } - if (retval = krb5_process_key(edit_context, &master_encblock, - &master_keyblock)) { + if ((retval = krb5_process_key(edit_context, &master_encblock, + &master_keyblock))) { com_err(pname, retval, "while processing master key"); exit_status++; memset((char *)master_keyblock.contents, 0, master_keyblock.length); @@ -509,9 +524,9 @@ set_dbname_help(pname, dbname) dbactive = TRUE; return(1); } - if (retval = krb5_init_random_key(edit_context, &master_encblock, - &master_keyblock, - &master_random)) { + if ((retval = krb5_init_random_key(edit_context, &master_encblock, + &master_keyblock, + &master_random))) { com_err(pname, retval, "while initializing random key generator"); exit_status++; (void) krb5_finish_key(edit_context, &master_encblock); @@ -546,29 +561,30 @@ void enter_master_key(argc, argv) krb5_xfree(master_keyblock.contents); master_keyblock.contents = NULL; } - if (retval = krb5_db_fetch_mkey(edit_context, master_princ, &master_encblock, + if ((retval = krb5_db_fetch_mkey(edit_context, master_princ, + &master_encblock, TRUE, FALSE, (char *) NULL, - 0, &master_keyblock)) { + 0, &master_keyblock))) { com_err(pname, retval, "while reading master key"); exit_status++; return; } - if (retval = krb5_db_verify_master_key(edit_context, master_princ, - &master_keyblock, - &master_encblock)) { + if ((retval = krb5_db_verify_master_key(edit_context, master_princ, + &master_keyblock, + &master_encblock))) { com_err(pname, retval, "while verifying master key"); exit_status++; return; } - if (retval = krb5_process_key(edit_context, &master_encblock, - &master_keyblock)) { + if ((retval = krb5_process_key(edit_context, &master_encblock, + &master_keyblock))) { com_err(pname, retval, "while processing master key"); exit_status++; return; } - if (retval = krb5_init_random_key(edit_context, &master_encblock, - &master_keyblock, - &master_random)) { + if ((retval = krb5_init_random_key(edit_context, &master_encblock, + &master_keyblock, + &master_random))) { com_err(pname, retval, "while initializing random key generator"); exit_status++; (void) krb5_finish_key(edit_context, &master_encblock); @@ -632,7 +648,7 @@ void extract_srvtab(argc, argv) strcat(ktname, argv[1]); strcat(ktname, "-new-srvtab"); - if (retval = krb5_kt_resolve(edit_context, ktname, &ktid)) { + if ((retval = krb5_kt_resolve(edit_context, ktname, &ktid))) { com_err(argv[0], retval, "while resolving keytab name '%s'", ktname); exit_status++; return; @@ -656,15 +672,15 @@ void extract_srvtab(argc, argv) strcat(pname, cur_realm); } - if (retval = krb5_parse_name(edit_context, pname, &princ)) { + if ((retval = krb5_parse_name(edit_context, pname, &princ))) { com_err(argv[0], retval, "while parsing %s", pname); exit_status++; free(pname); continue; } nentries = 1; - if (retval = krb5_db_get_principal(edit_context, princ, &dbentry, &nentries, - &more)) { + if ((retval = krb5_db_get_principal(edit_context, princ, &dbentry, + &nentries, &more))) { com_err(argv[0], retval, "while retrieving %s", pname); exit_status++; goto cleanmost; @@ -680,16 +696,17 @@ void extract_srvtab(argc, argv) exit_status++; goto cleanmost; } - if (retval = krb5_dbekd_decrypt_key_data(edit_context, &master_encblock, - &dbentry.key_data[0], - &newentry.key, NULL)) { + if ((retval = krb5_dbekd_decrypt_key_data(edit_context, + &master_encblock, + &dbentry.key_data[0], + &newentry.key, NULL))) { com_err(argv[0], retval, "while decrypting key for '%s'", pname); exit_status++; goto cleanall; } newentry.principal = princ; newentry.vno = dbentry.key_data[0].key_data_kvno; - if (retval = krb5_kt_add_entry(edit_context, ktid, &newentry)) { + if ((retval = krb5_kt_add_entry(edit_context, ktid, &newentry))) { com_err(argv[0], retval, "while adding key to keytab '%s'", ktname); exit_status++; @@ -704,7 +721,7 @@ void extract_srvtab(argc, argv) free(pname); krb5_free_principal(edit_context, princ); } - if (retval = krb5_kt_close(edit_context, ktid)) { + if ((retval = krb5_kt_close(edit_context, ktid))) { com_err(argv[0], retval, "while closing keytab"); exit_status++; } @@ -776,15 +793,15 @@ void extract_v4_srvtab(argc, argv) strcat(pname, cur_realm); } - if (retval = krb5_parse_name(edit_context, pname, &princ)) { + if ((retval = krb5_parse_name(edit_context, pname, &princ))) { com_err(argv[0], retval, "while parsing %s", pname); exit_status++; free(pname); continue; } nentries = 1; - if (retval = krb5_db_get_principal(edit_context, princ, &dbentry, &nentries, - &more)) { + if ((retval = krb5_db_get_principal(edit_context, princ, &dbentry, + &nentries, &more))) { com_err(argv[0], retval, "while retrieving %s", pname); exit_status++; goto cleanmost; @@ -800,9 +817,10 @@ void extract_v4_srvtab(argc, argv) exit_status++; goto cleanmost; } - if (retval = krb5_dbekd_decrypt_key_data(edit_context, &master_encblock, - &dbentry.key_data[0], - &key, NULL)) { + if ((retval = krb5_dbekd_decrypt_key_data(edit_context, + &master_encblock, + &dbentry.key_data[0], + &key, NULL))) { com_err(argv[0], retval, "while decrypting key for '%s'", pname); exit_status++; goto cleanall; @@ -880,7 +898,7 @@ list_iterator(ptr, entry) struct list_iterator_struct *lis = (struct list_iterator_struct *)ptr; char *name; - if (retval = krb5_unparse_name(edit_context, entry->princ, &name)) { + if ((retval = krb5_unparse_name(edit_context, entry->princ, &name))) { com_err(lis->cmdname, retval, "while unparsing principal"); exit_status++; return retval; @@ -970,7 +988,7 @@ void delete_entry(argc, argv) exit_status++; return; } - if (retval = krb5_parse_name(edit_context, argv[1], &newprinc)) { + if ((retval = krb5_parse_name(edit_context, argv[1], &newprinc))) { com_err(argv[0], retval, "while parsing '%s'", argv[1]); exit_status++; return; @@ -981,16 +999,19 @@ void delete_entry(argc, argv) exit_status++; return; } - printf("Are you sure you want to delete '%s'?\nType 'yes' to confirm:", - argv[1]); - if ((fgets(yesno, sizeof(yesno), stdin) == NULL) || - strcmp(yesno, "yes\n")) { - printf("NOT removing '%s'\n", argv[1]); - krb5_free_principal(edit_context, newprinc); - return; + if (!scriptfile) { + /* Only confirm if we're interactive */ + printf("Are you sure you want to delete '%s'?\nType 'yes' to confirm:", + argv[1]); + if ((fgets(yesno, sizeof(yesno), stdin) == NULL) || + strcmp(yesno, "yes\n")) { + printf("NOT removing '%s'\n", argv[1]); + krb5_free_principal(edit_context, newprinc); + return; + } + printf("OK, deleting '%s'\n", argv[1]); } - printf("OK, deleting '%s'\n", argv[1]); - if (retval = krb5_db_delete_principal(edit_context, newprinc, &one)) { + if ((retval = krb5_db_delete_principal(edit_context, newprinc, &one))) { com_err(argv[0], retval, "while deleting '%s'", argv[1]); exit_status++; } else if (one != 1) { @@ -1030,7 +1051,6 @@ void show_principal(argc, argv) krb5_boolean more; krb5_error_code retval; char *pr_name = 0; - int i; char buffer[256]; if (argc < 2) { @@ -1049,13 +1069,14 @@ void show_principal(argc, argv) exit_status++; return; } - if (retval = krb5_parse_name(edit_context, argv[1], &princ)) { + if ((retval = krb5_parse_name(edit_context, argv[1], &princ))) { com_err(argv[0], retval, "while parsing '%s'", argv[1]); exit_status++; return; } - if (retval = krb5_db_get_principal(edit_context,princ,&entry,&nprincs,&more)) { + if ((retval = krb5_db_get_principal(edit_context,princ,&entry, + &nprincs,&more))) { com_err(argv[0], retval, "while trying to get principal's database entry"); exit_status++; @@ -1068,7 +1089,7 @@ void show_principal(argc, argv) goto errout; } - if (retval = krb5_unparse_name(edit_context, entry.princ, &pr_name)) { + if ((retval = krb5_unparse_name(edit_context, entry.princ, &pr_name))) { com_err(argv[0], retval, "while unparsing principal"); exit_status++; goto errout; @@ -1122,8 +1143,8 @@ int parse_princ_args(argc, argv, entry, pass, randkey, caller) int *randkey; char *caller; { - int i, j, attrib_set; - time_t date; + int i, attrib_set; + krb5_timestamp date; krb5_error_code retval; *pass = NULL; @@ -1258,14 +1279,15 @@ void modent(argc, argv) return; } mod_princ.mod_princ = master_princ; - if (retval = krb5_timeofday(edit_context, &mod_princ.mod_date)) { + if ((retval = krb5_timeofday(edit_context, &mod_princ.mod_date))) { com_err(argv[0], retval, "while fetching date"); krb5_free_principal(edit_context, entry.princ); exit_status++; free(canon); return; } - if (retval=krb5_dbe_encode_mod_princ_data(edit_context,&mod_princ,&entry)) { + if ((retval=krb5_dbe_encode_mod_princ_data(edit_context, + &mod_princ,&entry))) { com_err(argv[0], retval, "while setting mod_prince and mod_date"); krb5_free_principal(edit_context, entry.princ); exit_status++; diff --git a/src/admin/edit/kdb5_edit.h b/src/admin/edit/kdb5_edit.h index 28778404f..cc988011d 100644 --- a/src/admin/edit/kdb5_edit.h +++ b/src/admin/edit/kdb5_edit.h @@ -44,3 +44,14 @@ int set_dbname_help PROTOTYPE((char *, char *)); char *kdb5_edit_Init PROTOTYPE((int, char **)); + +int quit(); + +int check_for_match + PROTOTYPE((char *, int, krb5_db_entry *, int, int)); + +void parse_token + PROTOTYPE((char *, int *, int *, char *)); + +int create_db_entry + PROTOTYPE((krb5_principal, krb5_db_entry *)); diff --git a/src/admin/edit/ss_wrapper.c b/src/admin/edit/ss_wrapper.c index bb12b51aa..73e11b571 100644 --- a/src/admin/edit/ss_wrapper.c +++ b/src/admin/edit/ss_wrapper.c @@ -31,6 +31,7 @@ extern ss_request_table kdb5_edit_cmds; extern int exit_status; +extern FILE *scriptfile; int main(argc, argv) int argc; @@ -47,12 +48,37 @@ int main(argc, argv) ss_perror(sci_idx, retval, "creating invocation"); exit(1); } + if (request) { code = ss_execute_line(sci_idx, request, &code); if (code != 0) { ss_perror(sci_idx, code, request); exit_status++; } + } else if (scriptfile) { + char *command; + int nread; + + /* Get a buffer */ + if ((command = (char *) malloc(BUFSIZ))) { + /* Process commands from the script until end-of-file or error */ + while (!feof(scriptfile) && + !(fgets(command, BUFSIZ, scriptfile))) { + + /* Strip trailing newline */ + if (command[strlen(command)-1] == '\n') + command[strlen(command)-1] = '\0'; + + /* Execute the command */ + code = ss_execute_line(sci_idx, command, &code); + if (code != 0) { + ss_perror(sci_idx, code, command); + exit_status++; + break; + } + } + free(command); + } } else ss_listen(sci_idx, &retval); return quit() ? 1 : exit_status;