Пример #1
0
void
parse_file_header(
    const char *buffer,
    dumpfile_t *file,
    size_t	buflen)
{
    char *buf, *line, *tok, *line1;
    size_t lsize;
    char *uqname;
    int in_quotes;
    char *saveptr = NULL;

    /* put the buffer into a writable chunk of memory and nul-term it */
    buf = alloc(buflen + 1);
    memcpy(buf, buffer, buflen);
    buf[buflen] = '\0';
    fh_init(file); 

    /* extract the first unquoted line */
    in_quotes = 0;
    for (line = buf, lsize = 0; lsize < buflen; line++) {
	if ((*line == '\n') && !in_quotes)
	    break;

	if (*line == '"') {
	    in_quotes = !in_quotes;
	} else if ((*line == '\\') && (*(line + 1) == '"')) {
	    line++;
	    lsize++;
	}
	lsize++;
    }
    *line = '\0';
    line1 = alloc(lsize + 1);
    strncpy(line1, buf, lsize);
    line1[lsize] = '\0';
    *line = '\n';

    tok = strtok_r(line1, " ", &saveptr);
    if (tok == NULL) {
        g_fprintf(stderr, _("%s: Empty amanda header: buflen=%zu lsize=%zu\n"), get_pname(),
	    buflen, 
	    lsize);
	hexdump(buffer, lsize);
	strange_header(file, buffer, buflen, _("<Non-empty line>"), tok);
	goto out;
    }

    if (strcmp(tok, "NETDUMP:") != 0 && strcmp(tok, "AMANDA:") != 0) {
	amfree(buf);
	file->type = F_UNKNOWN;
	amfree(line1);
	return;
    }

    tok = strtok_r(NULL, " ", &saveptr);
    if (tok == NULL) {
	strange_header(file, buffer, buflen, _("<file type>"), tok);
	goto out;
    }
    file->type = str2filetype(tok);
    
    switch (file->type) {
    case F_TAPESTART:
	tok = strtok_r(NULL, " ", &saveptr);
	if ((tok == NULL) || (strcmp(tok, "DATE") != 0)) {
	    strange_header(file, buffer, buflen, "DATE", tok);
	    goto out;
	}

	tok = strtok_r(NULL, " ", &saveptr);
	if (tok == NULL) {
	    strange_header(file, buffer, buflen, _("<date stamp>"), tok);
	    goto out;
	}
	strncpy(file->datestamp, tok, SIZEOF(file->datestamp) - 1);

	tok = strtok_r(NULL, " ", &saveptr);
	if ((tok == NULL) || (strcmp(tok, "TAPE") != 0)) {
	    strange_header(file, buffer, buflen, "TAPE", tok);
	    goto out;
	}

	tok = strtok_r(NULL, " ", &saveptr);
	if (tok == NULL) {
	    strange_header(file, buffer, buflen, _("<file type>"), tok);
	    goto out;
	}
	strncpy(file->name, tok, SIZEOF(file->name) - 1);
	break;

    case F_DUMPFILE:
    case F_CONT_DUMPFILE:
    case F_SPLIT_DUMPFILE:
	tok = strtok_r(NULL, " ", &saveptr);
	if (tok == NULL) {
	    strange_header(file, buffer, buflen, _("<date stamp>"), tok);
	    goto out;
	}
	strncpy(file->datestamp, tok, SIZEOF(file->datestamp) - 1);

	tok = strtok_r(NULL, " ", &saveptr);
	if (tok == NULL) {
	    strange_header(file, buffer, buflen, _("<file name>"), tok);
	    goto out;
	}
	strncpy(file->name, tok, SIZEOF(file->name) - 1);

	tok = strquotedstr(&saveptr);
	if (tok == NULL) {
	    strange_header(file, buffer, buflen, _("<disk name>"), tok);
	    goto out;
	}
	uqname = unquote_string(tok);
	strncpy(file->disk, uqname, SIZEOF(file->disk) - 1);
 	amfree(uqname);
	
	if(file->type == F_SPLIT_DUMPFILE) {
	    tok = strtok_r(NULL, " ", &saveptr);
	    if (tok == NULL || strcmp(tok, "part") != 0) {
		strange_header(file, buffer, buflen, "part", tok);
		goto out;
	    }

	    tok = strtok_r(NULL, "/", &saveptr);
	    if ((tok == NULL) || (sscanf(tok, "%d", &file->partnum) != 1)) {
		strange_header(file, buffer, buflen, _("<part num param>"), tok);
		goto out;
	    }

	    /* If totalparts == -1, then the original dump was done in 
 	       streaming mode (no holding disk), thus we don't know how 
               many parts there are. */
	    tok = strtok_r(NULL, " ", &saveptr);
            if((tok == NULL) || (sscanf(tok, "%d", &file->totalparts) != 1)) {
		strange_header(file, buffer, buflen, _("<total parts param>"), tok);
		goto out;
	    }
	}

	tok = strtok_r(NULL, " ", &saveptr);
	if ((tok == NULL) || (strcmp(tok, "lev") != 0)) {
	    strange_header(file, buffer, buflen, "lev", tok);
	    goto out;
	}

	tok = strtok_r(NULL, " ", &saveptr);
	if ((tok == NULL) || (sscanf(tok, "%d", &file->dumplevel) != 1)) {
	    strange_header(file, buffer, buflen, _("<dump level param>"), tok);
	    goto out;
	}

	tok = strtok_r(NULL, " ", &saveptr);
	if ((tok == NULL) || (strcmp(tok, "comp") != 0)) {
	    strange_header(file, buffer, buflen, "comp", tok);
	    goto out;
	}

	tok = strtok_r(NULL, " ", &saveptr);
	if (tok == NULL) {
	    strange_header(file, buffer, buflen, _("<comp param>"), tok);
	    goto out;
	}
	strncpy(file->comp_suffix, tok, SIZEOF(file->comp_suffix) - 1);

	file->compressed = strcmp(file->comp_suffix, "N");
	/* compatibility with pre-2.2 amanda */
	if (strcmp(file->comp_suffix, "C") == 0)
	    strncpy(file->comp_suffix, ".Z", SIZEOF(file->comp_suffix) - 1);
	       
	tok = strtok_r(NULL, " ", &saveptr);
        /* "program" is optional */
        if (tok == NULL || strcmp(tok, "program") != 0) {
	    break;
	}

        tok = strtok_r(NULL, " ", &saveptr);
        if (tok == NULL) {
	    strange_header(file, buffer, buflen, _("<program name>"), tok);
	    goto out;
	}
        strncpy(file->program, tok, SIZEOF(file->program) - 1);
        if (file->program[0] == '\0')
            strncpy(file->program, "RESTORE", SIZEOF(file->program) - 1);

	if ((tok = strtok_r(NULL, " ", &saveptr)) == NULL)
             break;          /* reached the end of the buffer */

	/* "encryption" is optional */
	if (BSTRNCMP(tok, "crypt") == 0) {
	    tok = strtok_r(NULL, " ", &saveptr);
	    if (tok == NULL) {
		strange_header(file, buffer, buflen, _("<crypt param>"), tok);
		goto out;
	    }
	    strncpy(file->encrypt_suffix, tok,
		    SIZEOF(file->encrypt_suffix) - 1);
	    file->encrypted = BSTRNCMP(file->encrypt_suffix, "N");
	    if ((tok = strtok_r(NULL, " ", &saveptr)) == NULL)
		break;
	}

	/* "srvcompprog" is optional */
	if (BSTRNCMP(tok, "server_custom_compress") == 0) {
	    tok = strtok_r(NULL, " ", &saveptr);
	    if (tok == NULL) {
		strange_header(file, buffer, buflen,
				_("<server custom compress param>"), tok);
		goto out;
	    }
	    strncpy(file->srvcompprog, tok, SIZEOF(file->srvcompprog) - 1);
	    if ((tok = strtok_r(NULL, " ", &saveptr)) == NULL)
		break;      
	}

	/* "clntcompprog" is optional */
	if (BSTRNCMP(tok, "client_custom_compress") == 0) {
	    tok = strtok_r(NULL, " ", &saveptr);
	    if (tok == NULL) {
		strange_header(file, buffer, buflen,
				_("<client custom compress param>"), tok);
		goto out;
	    }
	    strncpy(file->clntcompprog, tok, SIZEOF(file->clntcompprog) - 1);
	    if ((tok = strtok_r(NULL, " ", &saveptr)) == NULL)
		break;
	}

	/* "srv_encrypt" is optional */
	if (BSTRNCMP(tok, "server_encrypt") == 0) {
	    tok = strtok_r(NULL, " ", &saveptr);
	    if (tok == NULL) {
		strange_header(file, buffer, buflen,
				_("<server encrypt param>"), tok);
		goto out;
	    }
	    strncpy(file->srv_encrypt, tok, SIZEOF(file->srv_encrypt) - 1);
	    if ((tok = strtok_r(NULL, " ", &saveptr)) == NULL) 
		break;
	}

	/* "clnt_encrypt" is optional */
	if (BSTRNCMP(tok, "client_encrypt") == 0) {
	    tok = strtok_r(NULL, " ", &saveptr);
	    if (tok == NULL) {
		strange_header(file, buffer, buflen,
				_("<client encrypt param>"), tok);
		goto out;
	    }
	    strncpy(file->clnt_encrypt, tok, SIZEOF(file->clnt_encrypt) - 1);
	    if ((tok = strtok_r(NULL, " ", &saveptr)) == NULL) 
		break;
	}

	/* "srv_decrypt_opt" is optional */
	if (BSTRNCMP(tok, "server_decrypt_option") == 0) {
	    tok = strtok_r(NULL, " ", &saveptr);
	    if (tok == NULL) {
		strange_header(file, buffer, buflen,
				_("<server decrypt param>"), tok);
		goto out;
	    }
	    strncpy(file->srv_decrypt_opt, tok,
		    SIZEOF(file->srv_decrypt_opt) - 1);
	    if ((tok = strtok_r(NULL, " ", &saveptr)) == NULL) 
		break;
	}

	/* "clnt_decrypt_opt" is optional */
	if (BSTRNCMP(tok, "client_decrypt_option") == 0) {
	    tok = strtok_r(NULL, " ", &saveptr);
	    if (tok == NULL) {
		strange_header(file, buffer, buflen,
				_("<client decrypt param>"), tok);
		goto out;
	    }
	    strncpy(file->clnt_decrypt_opt, tok,
		    SIZEOF(file->clnt_decrypt_opt) - 1);
	    if ((tok = strtok_r(NULL, " ", &saveptr)) == NULL) 
		break;
	}
      break;
      

    case F_TAPEEND:
	tok = strtok_r(NULL, " ", &saveptr);
	/* DATE is optional */
	if (tok != NULL) {
	    if (strcmp(tok, "DATE") == 0) {
		tok = strtok_r(NULL, " ", &saveptr);
		if(tok == NULL)
		    file->datestamp[0] = '\0';
		else
		    strncpy(file->datestamp, tok, SIZEOF(file->datestamp) - 1);
	    } else {
		strange_header(file, buffer, buflen, _("<DATE>"), tok);
	   }
	} else {
	    file->datestamp[0] = '\0';
	}
	break;

    case F_NOOP:
	/* nothing follows */
	break;

    default:
	strange_header(file, buffer, buflen,
		_("TAPESTART|DUMPFILE|CONT_DUMPFILE|SPLIT_DUMPFILE|TAPEEND|NOOP"), tok);
	goto out;
    }

    (void)strtok_r(buf, "\n", &saveptr); /* this is the first line */
    /* iterate through the rest of the lines */
    while ((line = strtok_r(NULL, "\n", &saveptr)) != NULL) {
#define SC "CONT_FILENAME="
	if (strncmp(line, SC, SIZEOF(SC) - 1) == 0) {
	    line += SIZEOF(SC) - 1;
	    strncpy(file->cont_filename, line,
		    SIZEOF(file->cont_filename) - 1);
	    continue;
	}
#undef SC

#define SC "PARTIAL="
	if (strncmp(line, SC, SIZEOF(SC) - 1) == 0) {
	    line += SIZEOF(SC) - 1;
	    file->is_partial = !strcasecmp(line, "yes");
	    continue;
	}
#undef SC
#define SC "APPLICATION="
	if (strncmp(line, SC, SIZEOF(SC) - 1) == 0) {
	    line += SIZEOF(SC) - 1;
	    strncpy(file->application, line,
		    SIZEOF(file->application) - 1);
	    continue;
	}
#undef SC

#define SC "DLE="
	if (strncmp(line, SC, SIZEOF(SC) - 1) == 0) {
	    line += SIZEOF(SC) - 1;
	    file->dle_str = parse_heredoc(line, &saveptr);
	}
#undef SC

#define SC _("To restore, position tape at start of file and run:")
	if (strncmp(line, SC, SIZEOF(SC) - 1) == 0)
	    continue;
#undef SC

#define SC "\tdd if=<tape> "
	if (strncmp(line, SC, SIZEOF(SC) - 1) == 0) {
	    char *cmd1, *cmd2, *cmd3=NULL;

	    /* skip over dd command */
	    if ((cmd1 = strchr(line, '|')) == NULL) {

	        strncpy(file->recover_cmd, "BUG",
		        SIZEOF(file->recover_cmd) - 1);
	        continue;
	    }
	    *cmd1++ = '\0';

	    /* block out first pipeline command */
	    if ((cmd2 = strchr(cmd1, '|')) != NULL) {
	      *cmd2++ = '\0';
	      if ((cmd3 = strchr(cmd2, '|')) != NULL)
		*cmd3++ = '\0';
	    }
	   
	    /* clean up some extra spaces in various fields */
	    chomp(cmd1);
	    chomp(cmd2);
	    chomp(cmd3);

	    /* three cmds: decrypt    | uncompress | recover
	     * two   cmds: uncompress | recover
	     * XXX note that if there are two cmds, the first one 
	     * XXX could be either uncompress or decrypt. Since no
	     * XXX code actually call uncompress_cmd/decrypt_cmd, it's ok
	     * XXX for header information.
	     * one   cmds: recover
	     */

	    if ( cmd3 == NULL) {
	      if (cmd2 == NULL) {
		strncpy(file->recover_cmd, cmd1,
			SIZEOF(file->recover_cmd) - 1);
	      } else {
		g_snprintf(file->uncompress_cmd,
			 SIZEOF(file->uncompress_cmd), "%s |", cmd1);
		strncpy(file->recover_cmd, cmd2,
			SIZEOF(file->recover_cmd) - 1);
	      }
	    } else {    /* cmd3 presents:  decrypt | uncompress | recover */
	      g_snprintf(file->decrypt_cmd,
		       SIZEOF(file->decrypt_cmd), "%s |", cmd1);
	      g_snprintf(file->uncompress_cmd,
		       SIZEOF(file->uncompress_cmd), "%s |", cmd2);
	      strncpy(file->recover_cmd, cmd3,
		      SIZEOF(file->recover_cmd) - 1);
	    }
	    continue;
	}
#undef SC
	/* XXX complain about weird lines? */
    }

out:
    amfree(buf);
    amfree(line1);
}
Пример #2
0
/* text is not nul-terminated */
static void
amtext(
    G_GNUC_UNUSED GMarkupParseContext *context,
		  const gchar         *text,
		  gsize                text_len,  
		  gpointer             user_data,
		  GError             **gerror)
{
    char     *tt;
    amgxml_t *data_user = user_data;
    GSList   *last_element = data_user->element_names;
    char     *last_element_name;
    GSList   *last_element2;
    char     *last_element2_name;
    dle_t    *dle = data_user->dle;
    int       i;

    if (!last_element) {
	g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
		    "XML: Invalid text");
	return;
    }
    last_element_name = last_element->data;

    tt = malloc(text_len + 1);
    strncpy(tt,text,text_len);
    tt[text_len] = '\0';

    //check if it is only space
    if (match_no_newline("^[ \f\n\r\t\v]*$", tt)) {
	amfree(tt);
	return;
    }

    if (data_user->raw) {
	amfree(tt);
	tt = stralloc(data_user->raw);
    }

    //check if it is only space
    if (match_no_newline("^[ \f\n\r\t\v]*$", tt)) {
	amfree(tt);
	return;
    }

    if (strcmp(last_element_name, "dle") == 0 ||
	strcmp(last_element_name, "backup-program") == 0 ||
	strcmp(last_element_name, "exclude") == 0 ||
	strcmp(last_element_name, "include") == 0) {
	g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
		    "XML: %s doesn't have text '%s'", last_element_name, tt);
	return;
    } else if(strcmp(last_element_name, "disk") == 0) {
	if (dle->disk != NULL) {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: multiple text in %s", last_element_name);
	    return;
	}
	dle->disk = tt;
    } else if(strcmp(last_element_name, "diskdevice") == 0) {
	if (dle->device != NULL) {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: multiple text in %s", last_element_name);
	    return;
	}
	dle->device = tt;
    } else if(strcmp(last_element_name, "calcsize") == 0) {
	if (strcasecmp(tt,"yes") == 0) {
	    dle->estimatelist = g_slist_append(dle->estimatelist,
					       GINT_TO_POINTER(ES_CALCSIZE));
	}
	amfree(tt);
    } else if(strcmp(last_element_name, "estimate") == 0) {
	char *ttt = tt;
	while (strlen(ttt) > 0) {
	    if (BSTRNCMP(ttt,"CLIENT") == 0) {
		dle->estimatelist = g_slist_append(dle->estimatelist,
						   GINT_TO_POINTER(ES_CLIENT));
		ttt += strlen("client");
	    } else if (BSTRNCMP(ttt,"CALCSIZE") == 0) {
		if (!data_user->has_calcsize)
		    dle->estimatelist = g_slist_append(dle->estimatelist,
						 GINT_TO_POINTER(ES_CALCSIZE));
		ttt += strlen("calcsize");
	    } else if (BSTRNCMP(ttt,"SERVER") == 0) {
		dle->estimatelist = g_slist_append(dle->estimatelist,
						   GINT_TO_POINTER(ES_SERVER));
		ttt += strlen("server");
	    } else {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: bad estimate: %s", tt);
		return;
	    }
	    while (*ttt == ' ')
		ttt++;
	}
	amfree(tt);
    } else if(strcmp(last_element_name, "program") == 0) {
	if (dle->program != NULL) {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: multiple text in %s", last_element_name);
	    return;
	}
	dle->program = tt;
	if (strcmp(tt, "APPLICATION") == 0) {
	    dle->program_is_application_api = 1;
	    dle->program = NULL;
	}
    } else if(strcmp(last_element_name, "plugin") == 0) {
	last_element2 = g_slist_nth(data_user->element_names, 1);
	if (!last_element2) {
	    error("Invalid name text");
	}
	last_element2_name = last_element2->data;
	if (strcmp(last_element2_name, "backup-program") == 0) {
	    dle->program = tt;
	} else if (strcmp(last_element2_name, "script") == 0) {
	    data_user->script->plugin = tt;
	} else {
	    error("plugin outside of backup-program");
	}
	data_user->has_plugin = 1;
    } else if(strcmp(last_element_name, "name") == 0) {
	last_element2 = g_slist_nth(data_user->element_names, 1);
	if (!last_element2) {
	    error("Invalid name text");
	}
	last_element2_name = last_element2->data;
	if (strcmp(last_element2_name, "property") == 0) {
	    data_user->property_name = tt;
	} else {
	    error("name outside of property");
	}
    } else if(strcmp(last_element_name, "priority") == 0) {
	last_element2 = g_slist_nth(data_user->element_names, 1);
	if (!last_element2) {
	    error("Invalid priority text");
	}
	last_element2_name = last_element2->data;
	if (strcmp(last_element2_name, "property") == 0) {
	    if (strcasecmp(tt,"yes") == 0) {
		data_user->property_data->priority = 1;
	    }
	} else {
	    error("priority outside of property");
	}
    } else if(strcmp(last_element_name, "value") == 0) {
	last_element2 = g_slist_nth(data_user->element_names, 1);
	if (!last_element2) {
	    error("Invalid name text");
	}
	last_element2_name = last_element2->data;
	if (strcmp(last_element2_name, "property") == 0) {
	    data_user->property_data->values =
			g_slist_append(data_user->property_data->values, tt);
	} else {
	    error("value outside of property");
	}
    } else if(strcmp(last_element_name, "auth") == 0) {
	if (dle->auth != NULL) {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: multiple text in %s", last_element_name);
	    return;
	}
	dle->auth = tt;
    } else if(strcmp(last_element_name, "level") == 0) {
	data_user->alevel->level = atoi(tt);
	amfree(tt);
    } else if (strcmp(last_element_name, "server") == 0) {
	if (strcasecmp(tt,"no") == 0) {
	    data_user->alevel->server = 0;
	} else if (strcasecmp(tt,"yes") == 0) {
	    data_user->alevel->server = 1;
	} else {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: Invalid %s (%s)", last_element_name, tt);
	    amfree(tt);
	    return;
	}
	amfree(tt);
    } else if(strcmp(last_element_name, "index") == 0) {
	if (strcasecmp(tt,"no") == 0) {
	    dle->create_index = 0;
	} else if (strcasecmp(tt,"yes") == 0) {
	    dle->create_index = 1;
	} else {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: Invalid %s (%s)", last_element_name, tt);
	    amfree(tt);
	    return;
	}
	amfree(tt);
    } else if(strcmp(last_element_name, "dumpdate") == 0) {
	if (dle->dumpdate != NULL) {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: multiple text in %s", last_element_name);
	    amfree(tt);
	    return;
	}
	dle->dumpdate = tt;
    } else if(strcmp(last_element_name, "record") == 0) {
	if (strcasecmp(tt, "no") == 0) {
	    dle->record = 0;
	} else if (strcasecmp(tt, "yes") == 0) {
	    dle->record = 1;
	} else {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: Invalid %s (%s)", last_element_name, tt);
	    return;
	}
    } else if(strcmp(last_element_name, "spindle") == 0) {
	dle->spindle = atoi(tt);
    } else if(strcmp(last_element_name, "compress") == 0) {
	if (strcmp(tt, "FAST") == 0) {
	    dle->compress = COMP_FAST;
	} else if (strcmp(tt, "BEST") == 0) {
	    dle->compress = COMP_BEST;
	} else if (BSTRNCMP(tt, "CUSTOM") == 0) {
	    dle->compress = COMP_CUST;
	} else if (strcmp(tt, "SERVER-FAST") == 0) {
	    dle->compress = COMP_SERVER_FAST;
	} else if (strcmp(tt, "SERVER-BEST") == 0) {
	    dle->compress = COMP_SERVER_BEST;
	} else if (BSTRNCMP(tt, "SERVER-CUSTOM") == 0) {
	    dle->compress = COMP_SERVER_CUST;
	} else {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: Invalid %s (%s)", last_element_name, tt);
	    amfree(tt);
	    return;
	}
	amfree(tt);
    } else if(strcmp(last_element_name, "custom-compress-program") == 0) {
	if (dle->compprog != NULL) {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: multiple text in %s", last_element_name);
	    amfree(tt);
	    return;
	}
	dle->compprog = tt;
    } else if(strcmp(last_element_name, "encrypt") == 0) {
	if (BSTRNCMP(tt,"NO") == 0) {
	    dle->encrypt = ENCRYPT_NONE;
	} else if (BSTRNCMP(tt, "CUSTOM") == 0) {
	    dle->encrypt = ENCRYPT_CUST;
	} else if (BSTRNCMP(tt, "SERVER-CUSTOM") == 0) {
	    dle->encrypt = ENCRYPT_SERV_CUST;
	} else {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: Invalid %s (%s)", last_element_name, tt);
	    amfree(tt);
	    return;
	}
	amfree(tt);
    } else if(strcmp(last_element_name, "kencrypt") == 0) {
	if (strcasecmp(tt,"no") == 0) {
	    dle->kencrypt = 0;
	} else if (strcasecmp(tt,"yes") == 0) {
	    dle->kencrypt = 1;
	} else {
	    g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			"XML: Invalid %s (%s)", last_element_name, tt);
	    amfree(tt);
	    return;
	}
	amfree(tt);
    } else if(strcmp(last_element_name, "custom-encrypt-program") == 0) {
	last_element2 = g_slist_nth(data_user->element_names, 1);
	if (!last_element2) {
	    error("XML: optional");
	}
	last_element2_name = last_element2->data;
	dle->clnt_encrypt = tt;
    } else if(strcmp(last_element_name, "decrypt-option") == 0) {
	last_element2 = g_slist_nth(data_user->element_names, 1);
	if (!last_element2) {
	    error("XML: optional");
	}
	last_element2_name = last_element2->data;
	dle->clnt_decrypt_opt = tt;
    } else if(strcmp(last_element_name, "exclude") == 0 ||
	      strcmp(last_element_name, "include") == 0) {
	data_user->has_optional = 0;
    } else if(strcmp(last_element_name, "file") == 0) {
	last_element2 = g_slist_nth(data_user->element_names, 1);
	if (!last_element2) {
	    error("XML: optional");
	}
	last_element2_name = last_element2->data;
	if (strcmp(last_element2_name, "exclude") == 0) {
	    dle->exclude_file = append_sl(dle->exclude_file, tt);
	} else if (strcmp(last_element2_name, "include") == 0) {
	    dle->include_file = append_sl(dle->include_file, tt);
	} else {
	    error("bad file");
	}
    } else if(strcmp(last_element_name, "list") == 0) {
	last_element2 = g_slist_nth(data_user->element_names, 1);
	if (!last_element2) {
	    error("XML: optional");
	}
	last_element2_name = last_element2->data;
	if (strcmp(last_element2_name, "exclude") == 0) {
	    dle->exclude_list = append_sl(dle->exclude_list, tt);
	} else if (strcmp(last_element2_name, "include") == 0) {
	    dle->include_list = append_sl(dle->include_list, tt);
	} else {
	    error("bad list");
	}
    } else if(strcmp(last_element_name, "optional") == 0) {
	i = atoi(tt);
	last_element2 = g_slist_nth(data_user->element_names, 1);
	if (!last_element2) {
	    error("XML: optional");
	}
	last_element2_name = last_element2->data;
	if (strcmp(last_element2_name, "exclude") == 0) {
	    dle->exclude_optional = 1;
	} else if (strcmp(last_element2_name, "include") == 0) {
	    dle->include_optional = 1;
	} else {
	    error("bad optional");
	}
	data_user->has_optional = 1;
	amfree(tt);
    } else if(strcmp(last_element_name, "script") == 0) {
    } else if(strcmp(last_element_name, "execute_on") == 0) {
	char *sep;
	char *tt1 = tt;
	do {
	    sep = strchr(tt1,',');
	    if (sep)
		*sep = '\0';
	    if (strcmp(tt1,"PRE-DLE-AMCHECK") == 0)
		data_user->script->execute_on |= EXECUTE_ON_PRE_DLE_AMCHECK;
	    else if (strcmp(tt1,"PRE-HOST-AMCHECK") == 0)
		data_user->script->execute_on |= EXECUTE_ON_PRE_HOST_AMCHECK;
	    else if (strcmp(tt1,"POST-DLE-AMCHECK") == 0)
		data_user->script->execute_on |= EXECUTE_ON_POST_DLE_AMCHECK;
	    else if (strcmp(tt1,"POST-HOST-AMCHECK") == 0)
		data_user->script->execute_on |= EXECUTE_ON_POST_HOST_AMCHECK;
	    else if (strcmp(tt1,"PRE-DLE-ESTIMATE") == 0)
		data_user->script->execute_on |= EXECUTE_ON_PRE_DLE_ESTIMATE;
	    else if (strcmp(tt1,"PRE-HOST-ESTIMATE") == 0)
		data_user->script->execute_on |= EXECUTE_ON_PRE_HOST_ESTIMATE;
	    else if (strcmp(tt1,"POST-DLE-ESTIMATE") == 0)
		data_user->script->execute_on |= EXECUTE_ON_POST_DLE_ESTIMATE;
	    else if (strcmp(tt1,"POST-HOST-ESTIMATE") == 0)
		data_user->script->execute_on |= EXECUTE_ON_POST_HOST_ESTIMATE;
	    else if (strcmp(tt1,"PRE-DLE-BACKUP") == 0)
		data_user->script->execute_on |= EXECUTE_ON_PRE_DLE_BACKUP;
	    else if (strcmp(tt1,"PRE-HOST-BACKUP") == 0)
		data_user->script->execute_on |= EXECUTE_ON_PRE_HOST_BACKUP;
	    else if (strcmp(tt1,"POST-DLE-BACKUP") == 0)
		data_user->script->execute_on |= EXECUTE_ON_POST_DLE_BACKUP;
	    else if (strcmp(tt1,"POST-HOST-BACKUP") == 0)
		data_user->script->execute_on |= EXECUTE_ON_POST_HOST_BACKUP;
	    else if (strcmp(tt1,"PRE-RECOVER") == 0)
		data_user->script->execute_on |= EXECUTE_ON_PRE_RECOVER;
	    else if (strcmp(tt1,"POST-RECOVER") == 0)
		data_user->script->execute_on |= EXECUTE_ON_POST_RECOVER;
	    else if (strcmp(tt1,"PRE-LEVEL-RECOVER") == 0)
		data_user->script->execute_on |= EXECUTE_ON_PRE_LEVEL_RECOVER;
	    else if (strcmp(tt1,"POST-LEVEL-RECOVER") == 0)
		data_user->script->execute_on |= EXECUTE_ON_POST_LEVEL_RECOVER;
	    else if (strcmp(tt1,"INTER-LEVEL-RECOVER") == 0)
		data_user->script->execute_on |= EXECUTE_ON_INTER_LEVEL_RECOVER;
	    else 
		dbprintf("BAD EXECUTE_ON: %s\n", tt1);
	    if (sep)
		tt1 = sep+1;
	} while (sep);
	amfree(tt);
    } else if(strcmp(last_element_name, "execute_where") == 0) {
	if (strcmp(tt, "CLIENT") == 0) {
	    data_user->script->execute_where = ES_CLIENT;
	} else {
	    data_user->script->execute_where = ES_SERVER;
	}
    } else {
	g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
		    "XML: amtext not defined for '%s'", last_element_name);
	return;
    }
}
Пример #3
0
void
set_disk(
    char *	dsk,
    char *	mtpt)
{
    char *cmd = NULL;
    char *qdsk;
    char *uqdsk;
    char *uqmtpt = NULL;

    if (is_extract_list_nonempty())
    {
	g_printf(_("Must clear extract list before changing disk\n"));
	return;
    }

    /* if mount point specified, check it is valid */
    if (mtpt != NULL) {
	uqmtpt = unquote_string(mtpt);
	if (*mtpt != '/') {
	    g_printf(_("Mount point \"%s\" invalid - must start with /\n"), uqmtpt);
	    amfree(uqmtpt);
	    return;
	}
    }

    clear_dir_list();
    uqdsk = unquote_string(dsk);
    qdsk = quote_string(uqdsk);
    cmd = stralloc2("DISK ", qdsk);
    amfree(qdsk);
    if (converse(cmd) == -1)
	exit(1);
    amfree(cmd);

    if (!server_happy()) {
	amfree(uqmtpt);
	amfree(uqdsk);
	return;
    }

    disk_name = newstralloc(disk_name, uqdsk);
    if (mtpt == NULL)
    {
	/* mount point not specified */
	if (*uqdsk == '/')
	{
	    /* disk specified by mount point, hence use it */
	    mount_point = newstralloc(mount_point, uqdsk);
	}
	else
	{
	    /* device name given, use '/' because nothing better */
	    mount_point = newstralloc(mount_point, "/");
	}
    }
    else
    {
	/* mount point specified */
	mount_point = newstralloc(mount_point, uqmtpt);
    }

    /* set the working directory to the mount point */
    /* there is the possibility that there are no index records for the
       disk for the given date, hence setting the directory to the
       mount point will fail. Preempt this by checking first so we can write
       a more informative message. */
    if (exchange("OISD /") == -1)
	exit(1);
    if (server_happy())
    {
	disk_path = newstralloc(disk_path, "/");
	suck_dir_list_from_server();	/* get list of directory contents */
    }
    else
    {
	g_printf(_("No index records for disk for specified date\n"));
	g_printf(_("If date correct, notify system administrator\n"));
	disk_path = newstralloc(disk_path, "/");	/* fake it */
	clear_dir_list();
    }
    amfree(uqmtpt);
    amfree(uqdsk);

    if (am_has_feature(indexsrv_features, fe_amindexd_DLE)) {
	char *dle_str;
	char *errmsg = NULL;

	cmd = stralloc("DLE");
	if (exchange(cmd) == -1)
	    exit(1);
	amfree(cmd);

	if (!server_happy())
	    return;

	dle_str = reply_line();
	if (BSTRNCMP(dle_str+4, "NODLE") == 0) {
	    dump_dle = NULL;
	} else {
	    dle_str = unquote_string(dle_str+4);
	    dump_dle = amxml_parse_node_CHAR(dle_str, &errmsg);
	    amfree(dle_str);
	}
    }
}