3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* ldapmodify.c - generic program to modify or add entries using LDAP */
12 #include <ac/stdlib.h>
14 #include <ac/string.h>
15 #include <ac/unistd.h>
17 #ifdef HAVE_SYS_STAT_H
21 #ifdef HAVE_SYS_FILE_H
31 #include "lutil_ldap.h"
33 #include "ldap_defaults.h"
40 static int ldapadd, force = 0;
41 static char *rejfile = NULL;
42 static LDAP *ld = NULL;
44 #define LDAPMOD_MAXLINE 4096
46 /* strings found in replog/LDIF entries (mostly lifted from slurpd/slurp.h) */
47 #define T_VERSION_STR "version"
48 #define T_REPLICA_STR "replica"
50 #define T_CONTROL_STR "control"
51 #define T_CHANGETYPESTR "changetype"
52 #define T_ADDCTSTR "add"
53 #define T_MODIFYCTSTR "modify"
54 #define T_DELETECTSTR "delete"
55 #define T_MODRDNCTSTR "modrdn"
56 #define T_MODDNCTSTR "moddn"
57 #define T_RENAMECTSTR "rename"
58 #define T_MODOPADDSTR "add"
59 #define T_MODOPREPLACESTR "replace"
60 #define T_MODOPDELETESTR "delete"
61 #define T_MODSEPSTR "-"
62 #define T_NEWRDNSTR "newrdn"
63 #define T_DELETEOLDRDNSTR "deleteoldrdn"
64 #define T_NEWSUPSTR "newsuperior"
67 static int process_ldif_rec LDAP_P(( char *rbuf, int count ));
68 static int parse_ldif_control LDAP_P(( char *line, LDAPControl ***pctrls ));
69 static void addmodifyop LDAP_P((
70 LDAPMod ***pmodsp, int modop,
72 struct berval *value ));
73 static int domodify LDAP_P((
78 static int dodelete LDAP_P((
80 LDAPControl **pctrls ));
81 static int dorename LDAP_P((
86 LDAPControl **pctrls ));
87 static char *read_one_record LDAP_P(( FILE *fp ));
92 fprintf( stderr, _("Add or modify entries from an LDAP server\n\n"));
93 fprintf( stderr, _("usage: %s [options]\n"), prog);
94 fprintf( stderr, _(" The list of desired operations are read from stdin or from the file\n"));
95 fprintf( stderr, _(" specified by \"-f file\".\n"));
96 fprintf( stderr, _("Add or modify options:\n"));
97 fprintf( stderr, _(" -a add values (%s)\n"),
98 (ldapadd ? _("default") : _("default is to replace")));
99 fprintf( stderr, _(" -F force all changes records to be used\n"));
100 fprintf( stderr, _(" -S file write skipped modifications to `file'\n"));
102 exit( EXIT_FAILURE );
106 const char options[] = "aFrS:"
107 "cCd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
110 handle_private_option( int i )
114 char *control, *cvalue;
116 case 'E': /* modify controls */
117 if( protocol == LDAP_VERSION2 ) {
118 fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
120 exit( EXIT_FAILURE );
123 /* should be extended to support comma separated list of
124 * [!]key[=value] parameters, e.g. -E !foo,bar=567
129 if( optarg[0] == '!' ) {
134 control = ber_strdup( optarg );
135 if ( (cvalue = strchr( control, '=' )) != NULL ) {
138 fprintf( stderr, _("Invalid modify control name: %s\n"), control );
146 case 'F': /* force all changes records to be used */
150 case 'r': /* replace (obsolete) */
153 case 'S': /* skipped modifications to file */
154 if( rejfile != NULL ) {
155 fprintf( stderr, _("%s: -S previously specified\n"), prog );
156 exit( EXIT_FAILURE );
158 rejfile = ber_strdup( optarg );
169 main( int argc, char **argv )
171 char *rbuf, *start, *rejbuf = NULL;
173 char *matched_msg, *error_msg;
178 prog = lutil_progname( "ldapmodify", argc, argv );
180 /* strncmp instead of strcmp since NT binaries carry .exe extension */
181 ldapadd = ( strncasecmp( prog, "ldapadd", sizeof("ldapadd")-1 ) == 0 );
183 /* Print usage when no parameters */
184 if( argc < 2 ) usage();
186 tool_args( argc, argv );
188 if ( argc != optind )
191 if ( rejfile != NULL ) {
192 if (( rejfp = fopen( rejfile, "w" )) == NULL ) {
194 return( EXIT_FAILURE );
200 if ( infile != NULL ) {
201 if (( fp = fopen( infile, "r" )) == NULL ) {
203 return( EXIT_FAILURE );
212 ld = tool_conn_setup( not, 0 );
215 if ( pw_file || want_bindpw ) {
217 rc = lutil_get_filed_password( pw_file, &passwd );
218 if( rc ) return EXIT_FAILURE;
220 passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
221 passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
230 if ( authzid || manageDSAit || noop )
231 tool_server_controls( ld, NULL, 0 );
235 while (( rc == 0 || contoper ) &&
236 ( rbuf = read_one_record( fp )) != NULL ) {
242 len = strlen( rbuf );
243 if (( rejbuf = (char *)ber_memalloc( len+1 )) == NULL ) {
245 exit( EXIT_FAILURE );
247 memcpy( rejbuf, rbuf, len+1 );
250 rc = process_ldif_rec( start, count );
255 fprintf(rejfp, _("# Error: %s (%d)"), ldap_err2string(rc), rc);
258 ldap_get_option(ld, LDAP_OPT_MATCHED_DN, &matched_msg);
259 if ( matched_msg != NULL ) {
260 if ( *matched_msg != '\0' )
261 fprintf( rejfp, _(", matched DN: %s"), matched_msg );
262 ldap_memfree( matched_msg );
266 ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error_msg);
267 if ( error_msg != NULL ) {
268 if ( *error_msg != '\0' )
269 fprintf( rejfp, _(", additional info: %s"), error_msg );
270 ldap_memfree( error_msg );
272 fprintf( rejfp, "\n%s\n", rejbuf );
283 if ( rejfp != NULL ) {
292 process_ldif_rec( char *rbuf, int count )
294 char *line, *dn, *type, *newrdn, *newsup, *p;
295 int rc, linenum, modop, replicaport;
296 int expect_modop, expect_sep, expect_ct, expect_newrdn, expect_newsup;
297 int expect_deleteoldrdn, deleteoldrdn;
298 int saw_replica, use_record, new_entry, delete_entry, got_all;
302 LDAPControl **pctrls;
306 rc = got_all = saw_replica = delete_entry = modop = expect_modop = 0;
307 expect_deleteoldrdn = expect_newrdn = expect_newsup = 0;
308 expect_sep = expect_ct = 0;
315 dn = newrdn = newsup = NULL;
317 while ( rc == 0 && ( line = ldif_getline( &rbuf )) != NULL ) {
320 if ( expect_sep && strcasecmp( line, T_MODSEPSTR ) == 0 ) {
326 if ( ldif_parse_line( line, &type, &val.bv_val, &val.bv_len ) < 0 ) {
327 fprintf( stderr, _("%s: invalid format (line %d) entry: \"%s\"\n"),
328 prog, linenum, dn == NULL ? "" : dn );
329 rc = LDAP_PARAM_ERROR;
334 if ( !use_record && strcasecmp( type, T_REPLICA_STR ) == 0 ) {
336 if (( p = strchr( val.bv_val, ':' )) == NULL ) {
340 replicaport = atoi( p );
342 if ( ldaphost != NULL && strcasecmp( val.bv_val, ldaphost ) == 0 &&
343 replicaport == ldapport ) {
346 } else if ( count == 1 && linenum == 1 &&
347 strcasecmp( type, T_VERSION_STR ) == 0 )
349 if( val.bv_len == 0 || atoi(val.bv_val) != 1 ) {
350 fprintf( stderr, _("%s: invalid version %s, line %d (ignored)\n"),
351 prog, val.bv_val, linenum );
355 } else if ( strcasecmp( type, T_DN_STR ) == 0 ) {
356 if (( dn = ber_strdup( val.bv_val )) == NULL ) {
358 exit( EXIT_FAILURE );
362 goto end_line; /* skip all lines until we see "dn:" */
367 /* Check for "control" tag after dn and before changetype. */
368 if (strcasecmp(type, T_CONTROL_STR) == 0) {
369 /* Parse and add it to the list of controls */
370 rc = parse_ldif_control( line, &pctrls );
372 fprintf( stderr, _("%s: Error processing %s line, line %d: %s\n"),
373 prog, T_CONTROL_STR, linenum, ldap_err2string(rc) );
379 if ( !use_record && saw_replica ) {
380 printf(_("%s: skipping change record for entry: %s\n"), prog, dn);
381 printf(_("\t(LDAP host/port does not match replica: lines)\n"));
384 ber_memfree( val.bv_val );
388 if ( strcasecmp( type, T_CHANGETYPESTR ) == 0 ) {
389 #ifdef LIBERAL_CHANGETYPE_MODOP
390 /* trim trailing spaces (and log warning ...) */
393 for ( icnt = val.bv_len; --icnt > 0; ) {
394 if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) {
399 if ( ++icnt != val.bv_len ) {
400 fprintf( stderr, _("%s: illegal trailing space after \"%s: %s\" trimmed (line %d of entry \"%s\")\n"),
401 prog, T_CHANGETYPESTR, val.bv_val, linenum, dn );
402 val.bv_val[icnt] = '\0';
404 #endif /* LIBERAL_CHANGETYPE_MODOP */
406 if ( strcasecmp( val.bv_val, T_MODIFYCTSTR ) == 0 ) {
409 } else if ( strcasecmp( val.bv_val, T_ADDCTSTR ) == 0 ) {
411 } else if ( strcasecmp( val.bv_val, T_MODRDNCTSTR ) == 0
412 || strcasecmp( val.bv_val, T_MODDNCTSTR ) == 0
413 || strcasecmp( val.bv_val, T_RENAMECTSTR ) == 0)
416 } else if ( strcasecmp( val.bv_val, T_DELETECTSTR ) == 0 ) {
417 got_all = delete_entry = 1;
420 _("%s: unknown %s \"%s\" (line %d of entry \"%s\")\n"),
421 prog, T_CHANGETYPESTR, val.bv_val, linenum, dn );
422 rc = LDAP_PARAM_ERROR;
425 } else if ( ldapadd ) { /* missing changetype => add */
427 modop = LDAP_MOD_ADD;
429 expect_modop = 1; /* missing changetype => modify */
433 if ( expect_modop ) {
434 #ifdef LIBERAL_CHANGETYPE_MODOP
435 /* trim trailing spaces (and log warning ...) */
438 for ( icnt = val.bv_len; --icnt > 0; ) {
439 if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) {
444 if ( ++icnt != val.bv_len ) {
445 fprintf( stderr, _("%s: illegal trailing space after \"%s: %s\" trimmed (line %d of entry \"%s\")\n"),
446 prog, type, val.bv_val, linenum, dn );
447 val.bv_val[icnt] = '\0';
449 #endif /* LIBERAL_CHANGETYPE_MODOP */
453 if ( strcasecmp( type, T_MODOPADDSTR ) == 0 ) {
454 modop = LDAP_MOD_ADD;
456 } else if ( strcasecmp( type, T_MODOPREPLACESTR ) == 0 ) {
457 modop = LDAP_MOD_REPLACE;
458 addmodifyop( &pmods, modop, val.bv_val, NULL );
460 } else if ( strcasecmp( type, T_MODOPDELETESTR ) == 0 ) {
461 modop = LDAP_MOD_DELETE;
462 addmodifyop( &pmods, modop, val.bv_val, NULL );
464 } else { /* no modify op: use default */
465 modop = ldapadd ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
469 if ( expect_newrdn ) {
470 if ( strcasecmp( type, T_NEWRDNSTR ) == 0 ) {
471 if (( newrdn = ber_strdup( val.bv_val )) == NULL ) {
473 exit( EXIT_FAILURE );
475 expect_deleteoldrdn = 1;
478 fprintf( stderr, _("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n"),
479 prog, T_NEWRDNSTR, type, linenum, dn );
480 rc = LDAP_PARAM_ERROR;
482 } else if ( expect_deleteoldrdn ) {
483 if ( strcasecmp( type, T_DELETEOLDRDNSTR ) == 0 ) {
484 deleteoldrdn = ( *val.bv_val == '0' ) ? 0 : 1;
485 expect_deleteoldrdn = 0;
489 fprintf( stderr, _("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n"),
490 prog, T_DELETEOLDRDNSTR, type, linenum, dn );
491 rc = LDAP_PARAM_ERROR;
493 } else if ( expect_newsup ) {
494 if ( strcasecmp( type, T_NEWSUPSTR ) == 0 ) {
495 if (( newsup = ber_strdup( val.bv_val )) == NULL ) {
497 exit( EXIT_FAILURE );
501 fprintf( stderr, _("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n"),
502 prog, T_NEWSUPSTR, type, linenum, dn );
503 rc = LDAP_PARAM_ERROR;
505 } else if ( got_all ) {
507 _("%s: extra lines at end (line %d of entry \"%s\")\n"),
509 rc = LDAP_PARAM_ERROR;
511 addmodifyop( &pmods, modop, type, &val );
516 ber_memfree( val.bv_val );
523 if( version && linenum == 1 ) {
527 /* If default controls are set (as with -M option) and controls are
528 specified in the LDIF file, we must add the default controls to
529 the list of controls sent with the ldap operation.
533 LDAPControl **defctrls = NULL; /* Default server controls */
534 LDAPControl **newctrls = NULL;
535 ldap_get_option(ld, LDAP_OPT_SERVER_CONTROLS, &defctrls);
537 int npc=0; /* Number of LDIF controls */
538 int ndefc=0; /* Number of default controls */
539 while (pctrls[npc]) /* Count LDIF controls */
541 while (defctrls[ndefc]) /* Count default controls */
543 newctrls = ber_memrealloc(pctrls, (npc+ndefc+1)*sizeof(LDAPControl*));
544 if (newctrls == NULL)
549 for (i=npc; i<npc+ndefc; i++) {
550 pctrls[i] = ldap_control_dup(defctrls[i-npc]);
551 if (pctrls[i] == NULL) {
556 pctrls[npc+ndefc] = NULL;
558 ldap_controls_free(defctrls); /* Must be freed by library */
565 if ( delete_entry ) {
566 rc = dodelete( dn, pctrls );
567 } else if ( newrdn != NULL ) {
568 rc = dorename( dn, newrdn, newsup, deleteoldrdn, pctrls );
570 rc = domodify( dn, pmods, pctrls, new_entry );
573 if ( rc == LDAP_SUCCESS ) {
581 if ( newrdn != NULL ) {
584 if ( pmods != NULL ) {
585 ldap_mods_free( pmods, 1 );
588 if (pctrls != NULL) {
589 ldap_controls_free( pctrls );
595 /* Parse an LDIF control line of the form
596 control: oid [true/false] [: value] or
597 control: oid [true/false] [:: base64-value] or
598 control: oid [true/false] [:< url]
599 The control is added to the list of controls in *ppctrls.
602 parse_ldif_control( char *line,
603 LDAPControl ***ppctrls )
606 int criticality = 0; /* Default is false if not present */
609 ber_len_t value_len = 0;
611 char *s, *oidStart, *pcolon;
612 LDAPControl *newctrl = NULL;
613 LDAPControl **pctrls = NULL;
618 s = line + strlen(T_CONTROL_STR); /* Skip over "control" */
619 pcolon = s; /* Save this position for later */
620 if (*s++ != ':') /* Make sure colon follows */
621 return ( LDAP_PARAM_ERROR );
622 while (*s && isspace((unsigned char)*s))
623 s++; /* Skip white space before OID */
625 /* OID should come next. Validate and extract it. */
627 return ( LDAP_PARAM_ERROR );
629 while (isdigit((unsigned char)*s) || *s == '.')
630 s++; /* OID should be digits or . */
632 return ( LDAP_PARAM_ERROR ); /* OID was not present */
633 if (*s) { /* End of OID should be space or NULL */
634 if (!isspace((unsigned char)*s))
635 return ( LDAP_PARAM_ERROR ); /* else OID contained invalid chars */
636 *s++ = 0; /* Replace space with null to terminate */
640 oid = ber_strdup(oidStart);
642 return ( LDAP_NO_MEMORY );
644 /* Optional Criticality field is next. */
645 while (*s && isspace((unsigned char)*s))
646 s++; /* Skip white space before criticality */
647 if (strncasecmp(s, "true", 4) == 0) {
651 else if (strncasecmp(s, "false", 5) == 0) {
656 /* Optional value field is next */
657 while (*s && isspace((unsigned char)*s))
658 s++; /* Skip white space before value */
660 if (*s != ':') { /* If value is present, must start with : */
661 rc = LDAP_PARAM_ERROR;
665 /* Shift value down over OID and criticality so it's in the form
667 control:: base64-value
669 Then we can use ldif_parse_line to extract and decode the value
671 while ( (*pcolon++ = *s++) != 0) /* Shift value */
673 rc = ldif_parse_line(line, &type, &val, &value_len);
674 if (type) ber_memfree(type); /* Don't need this field*/
676 rc = LDAP_PARAM_ERROR;
681 /* Create a new LDAPControl structure. */
682 newctrl = (LDAPControl *)ber_memalloc(sizeof(LDAPControl));
683 if ( newctrl == NULL ) {
687 newctrl->ldctl_oid = oid;
689 newctrl->ldctl_iscritical = criticality;
690 newctrl->ldctl_value.bv_len = value_len;
691 newctrl->ldctl_value.bv_val = val;
694 /* Add the new control to the passed-in list of controls. */
697 while ( pctrls[i] ) /* Count the # of controls passed in */
700 /* Allocate 1 more slot for the new control and 1 for the NULL. */
701 pctrls = (LDAPControl **)ber_memrealloc(pctrls, (i+2)*(sizeof(LDAPControl *)));
702 if (pctrls == NULL) {
713 if (newctrl->ldctl_oid)
714 ber_memfree(newctrl->ldctl_oid);
715 if (newctrl->ldctl_value.bv_val)
716 ber_memfree(newctrl->ldctl_value.bv_val);
717 ber_memfree(newctrl);
739 modop |= LDAP_MOD_BVALUES;
742 if ( pmods != NULL ) {
743 for ( ; pmods[ i ] != NULL; ++i ) {
744 if ( strcasecmp( pmods[ i ]->mod_type, attr ) == 0 &&
745 pmods[ i ]->mod_op == modop )
752 if ( pmods == NULL || pmods[ i ] == NULL ) {
753 if (( pmods = (LDAPMod **)ber_memrealloc( pmods, (i + 2) *
754 sizeof( LDAPMod * ))) == NULL )
757 exit( EXIT_FAILURE );
761 pmods[ i + 1 ] = NULL;
763 pmods[ i ] = (LDAPMod *)ber_memcalloc( 1, sizeof( LDAPMod ));
764 if ( pmods[ i ] == NULL ) {
766 exit( EXIT_FAILURE );
769 pmods[ i ]->mod_op = modop;
770 pmods[ i ]->mod_type = ber_strdup( attr );
771 if ( pmods[ i ]->mod_type == NULL ) {
773 exit( EXIT_FAILURE );
779 if ( pmods[ i ]->mod_bvalues != NULL ) {
780 for ( ; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) {
785 pmods[ i ]->mod_bvalues = (struct berval **) ber_memrealloc(
786 pmods[ i ]->mod_bvalues, (j + 2) * sizeof( struct berval * ));
787 if ( pmods[ i ]->mod_bvalues == NULL ) {
788 perror( "ber_realloc" );
789 exit( EXIT_FAILURE );
792 pmods[ i ]->mod_bvalues[ j + 1 ] = NULL;
793 pmods[ i ]->mod_bvalues[ j ] = ber_bvdup( val );
794 if ( pmods[ i ]->mod_bvalues[ j ] == NULL ) {
795 perror( "ber_bvdup" );
796 exit( EXIT_FAILURE );
806 LDAPControl **pctrls,
809 int i, j, k, notascii, op;
812 if ( pmods == NULL ) {
813 fprintf( stderr, _("%s: no attributes to change or add (entry=\"%s\")\n"),
815 return( LDAP_PARAM_ERROR );
818 for ( i = 0; pmods[ i ] != NULL; ++i ) {
819 op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES;
820 if( op == LDAP_MOD_ADD && ( pmods[i]->mod_bvalues == NULL )) {
822 _("%s: attribute \"%s\" has no values (entry=\"%s\")\n"),
823 prog, pmods[i]->mod_type, dn );
824 return LDAP_PARAM_ERROR;
829 for ( i = 0; pmods[ i ] != NULL; ++i ) {
830 op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES;
832 op == LDAP_MOD_REPLACE ? _("replace") : op == LDAP_MOD_ADD
833 ? _("add") : _("delete"),
834 pmods[ i ]->mod_type );
835 if ( pmods[ i ]->mod_bvalues != NULL ) {
836 for ( j = 0; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) {
837 bvp = pmods[ i ]->mod_bvalues[ j ];
839 for ( k = 0; (unsigned long) k < bvp->bv_len; ++k ) {
840 if ( !isascii( bvp->bv_val[ k ] )) {
846 printf( _("\tNOT ASCII (%ld bytes)\n"), bvp->bv_len );
848 printf( "\t%s\n", bvp->bv_val );
856 printf( "%sadding new entry \"%s\"\n", not ? "!" : "", dn );
858 printf( "%smodifying entry \"%s\"\n", not ? "!" : "", dn );
863 i = ldap_add_ext_s( ld, dn, pmods, pctrls, NULL );
865 i = ldap_modify_ext_s( ld, dn, pmods, pctrls, NULL );
867 if ( i != LDAP_SUCCESS ) {
868 /* print error message about failed update including DN */
869 fprintf( stderr, _("%s: update failed: %s\n"), prog, dn );
870 ldap_perror( ld, newentry ? "ldap_add" : "ldap_modify" );
871 } else if ( verbose ) {
872 printf( _("modify complete\n") );
887 LDAPControl **pctrls )
891 printf( _("%sdeleting entry \"%s\"\n"), not ? "!" : "", dn );
893 if (( rc = ldap_delete_ext_s( ld, dn, pctrls, NULL )) != LDAP_SUCCESS ) {
894 fprintf( stderr, _("%s: delete failed: %s\n"), prog, dn );
895 ldap_perror( ld, "ldap_delete" );
896 } else if ( verbose ) {
897 printf( _("delete complete") );
915 LDAPControl **pctrls )
920 printf( _("%smodifying rdn of entry \"%s\"\n"), not ? "!" : "", dn );
922 printf( _("\tnew RDN: \"%s\" (%skeep existing values)\n"),
923 newrdn, deleteoldrdn ? _("do not ") : "" );
926 if (( rc = ldap_rename_s( ld, dn, newrdn, newsup, deleteoldrdn, pctrls, NULL ))
928 fprintf( stderr, _("%s: rename failed: %s\n"), prog, dn );
929 ldap_perror( ld, "ldap_modrdn" );
931 printf( _("modrdn completed\n") );
944 read_one_record( FILE *fp )
946 char *buf, line[ LDAPMOD_MAXLINE ];
952 while ( fgets( line, sizeof(line), fp ) != NULL ) {
953 int len = strlen( line );
955 if( len < 2 || ( len == 2 && *line == '\r' )) {
963 if ( lcur + len + 1 > lmax ) {
964 lmax = LDAPMOD_MAXLINE
965 * (( lcur + len + 1 ) / LDAPMOD_MAXLINE + 1 );
967 if (( buf = (char *)ber_memrealloc( buf, lmax )) == NULL ) {
969 exit( EXIT_FAILURE );
973 strcpy( buf + lcur, line );