Beispiel #1
0
static void
enter_record(
    char *	name,
    int		level,
    time_t	dumpdate)
{
    amandates_t *amdp;
    char *qname;

    amdp = lookup(name, 0);

    if (level < 0 || level >= DUMP_LEVELS) {
	qname = quote_string(name);
	/* this is not allowed, but we can ignore it */
        dbprintf(_("amandates botch: %s lev %d: new dumpdate %ld\n"),
		  qname, level, (long) dumpdate);
	amfree(qname);
	return;
    } else if(dumpdate < amdp->dates[level]) {
	qname = quote_string(name);
	/* this is not allowed, but we can ignore it */
        dbprintf(_("amandates botch: %s lev %d: new dumpdate %ld old %ld\n"),
		  qname, level, (long) dumpdate, (long) amdp->dates[level]);
	amfree(qname);
	return;
    }

    amdp->dates[level] = dumpdate;
}
Beispiel #2
0
/****
 * Test the strquotedstr function
 */
static int
test_strquotedstr_skipping(void)
{
    char **iter1, **iter2;
    gboolean success = TRUE;

    /* the idea here is to loop over all pairs of strings, forming a
     * string by quoting them with quote_string and inserting a space, then
     * re-splitting with strquotedstr.  This should get us back to our
     * starting point. Note that we have to begin with a non-quoted identifier,
     * becuse strquotedstr requires that strtok_r has already been called. */

    for (iter1 = quotable_strings; *iter1; iter1++) {
	for (iter2 = quotable_strings; *iter2; iter2++) {
	    char *q1 = quote_string(*iter1);
	    char *q2 = quote_string(*iter2);
	    char *combined = vstralloc("START ", q1, " ", q2, NULL);
	    char *copy = g_strdup(combined);
	    char *saveptr = NULL;
	    char *tok;
	    int i;

	    tok = strtok_r(copy, " ", &saveptr);

	    for (i = 1; i <= 2; i++) {
		char *expected = (i == 1)? q1:q2;
		tok = strquotedstr(&saveptr);
		if (!tok) {
		    g_fprintf(stderr, "while parsing '%s', call %d to strquotedstr returned NULL\n",
			      combined, i);
		    success = FALSE;
		    goto next;
		}
		if (0 != strcmp(tok, expected)) {
		    char *safe = safestr(tok);

		    g_fprintf(stderr, "while parsing '%s', call %d to strquotedstr returned '%s' "
			      "but '%s' was expected.\n",
			      combined, i, safe, expected);
		    success = FALSE;
		    goto next;
		}
	    }

	    if (strquotedstr(&saveptr) != NULL) {
		g_fprintf(stderr, "while parsing '%s', call 3 to strquotedstr did not return NULL\n",
			  combined);
		success = FALSE;
		goto next;
	    }
next:
	    amfree(q1);
	    amfree(q2);
	    amfree(copy);
	    amfree(combined);
	}
    }

    return success;
}
Beispiel #3
0
void
amandates_updateone(
    char *	name,
    int		level,
    time_t	dumpdate)
{
    amandates_t *amdp;
    char *qname;

    assert(!readonly);

    amdp = lookup(name, 1);

    if (level < 0 || level >= DUMP_LEVELS) {
	/* this is not allowed, but we can ignore it */
	qname = quote_string(name);
	dbprintf(_("amandates updateone: %s lev %d: bad level, dumpdate %ld"),
		  name, level, (long) dumpdate);
	amfree(qname);
	return;
    } else if (dumpdate < amdp->dates[level]) {
	/* this is not allowed, but we can ignore it */
	qname = quote_string(name);
	dbprintf(_("amandates updateone: %s lev %d: new dumpdate %ld old %ld"),
		  name, level, (long) dumpdate, (long) amdp->dates[level]);
	amfree(qname);
	return;
    }

    amdp->dates[level] = dumpdate;
    updated = 1;
}
Beispiel #4
0
/* Print a user ID, with a default string (like "everyone") for NULL. */
static void print_id(struct gale_text var,struct gale_text dfl) {
	struct gale_text value = gale_var(var);
	int i = 1;

	if (0 == value.l) {
		gale_print(stdout,0,G_(" *"));
		gale_print(stdout,gale_print_bold,dfl);
		gale_print(stdout,0,G_("*"));
		return;
	}

	do {
                int at;
		struct gale_text local,domain;
		gale_print(stdout,0,G_(" "));
                for (at = 0; at < value.l && '@' != value.p[at]; ++at) ;
		local = gale_text_left(value,at);
		domain = gale_text_right(value,-at);
		if (quote_string(&local) || quote_string(&domain)) {
			gale_print(stdout,0,G_("'"));
			gale_print(stdout,gale_print_bold,local);
			gale_print(stdout,0,domain);
			gale_print(stdout,0,G_("'"));
		} else {
			gale_print(stdout,gale_print_bold,local);
			gale_print(stdout,0,domain);
		}

		value = gale_var(gale_text_concat(3,var,G_("_"),
			gale_text_from_number(++i,10,0)));
	} while (0 != value.l);
}
Beispiel #5
0
/* We call this when we can't find a tape to write data to. This could
   happen with the first (or only) part of a file, but it could also
   happen with an intermediate part of a split dump. dump_bytes
   is 0 if this is the first part of a dump. */
static void bail_no_volume(
    dump_info_t *dump_info,
    char *errmsg)
{
    char *errstr;
    if (errmsg)
	errstr = quote_string(errmsg);
    else
	errstr = quote_string("no new tape");
    if (dump_info->total_bytes > 0) {
        /* Second or later part of a split dump, so PARTIAL message. */
        double dump_time = g_timeval_to_double(dump_info->total_time);
        guint64 dump_kbytes = dump_info->total_bytes / 1024;
        double dump_kbps = get_kbps(dump_kbytes, dump_time);
        putresult(PARTIAL,
                  "%s INPUT-GOOD TAPE-ERROR "
                  "\"[sec %f kb %ju kps %f]\" \"\" %s\n",
                  dump_info->handle, 
                  dump_time, (uintmax_t)dump_kbytes, dump_kbps, errstr);
        put_partial_log(dump_info, dump_time, dump_kbytes, errstr);
    } else {
        char * qdiskname = quote_string(dump_info->diskname);
        putresult(FAILED,
                  "%s INPUT-GOOD TAPE-ERROR \"\" %s\n",
                  dump_info->handle, errstr);
        log_add(L_FAIL, "%s %s %s %d %s",
                dump_info->hostname, qdiskname, dump_info->timestamp,
                dump_info->level, errstr);
	amfree(qdiskname);
    }
    amfree(errstr);
}
Beispiel #6
0
int copy_file(
    char  *dst,
    char  *src,
    char **errmsg)
{
    int     infd, outfd;
    int     save_errno;
    ssize_t nb;
    char    buf[32768];
    char   *quoted;

    if ((infd = open(src, O_RDONLY)) == -1) {
	save_errno = errno;
	quoted = quote_string(src);
	*errmsg = g_strdup_printf(_("Can't open file '%s' for reading: %s"),
			    quoted, strerror(save_errno));
	amfree(quoted);
	return -1;
    }

    if ((outfd = open(dst, O_WRONLY|O_CREAT, 0600)) == -1) {
	save_errno = errno;
	quoted = quote_string(dst);
	*errmsg = g_strdup_printf(_("Can't open file '%s' for writting: %s"),
			    quoted, strerror(save_errno));
	amfree(quoted);
	close(infd);
	return -1;
    }

    while ((nb=read(infd, &buf, sizeof(buf))) > 0) {
	if (full_write(outfd,&buf,nb) < (size_t)nb) {
	    save_errno = errno;
	    quoted = quote_string(dst);
	    *errmsg = g_strdup_printf(_("Error writing to '%s': %s"),
				quoted, strerror(save_errno));
	    amfree(quoted);
	    close(infd);
	    close(outfd);
	    return -1;
	}
    }

    if (errno != 0) {
	save_errno = errno;
	quoted = quote_string(src);
	*errmsg = g_strdup_printf(_("Error reading from '%s': %s"),
			    quoted, strerror(save_errno));
	amfree(quoted);
	close(infd);
	close(outfd);
	return -1;
    }

    close(infd);
    close(outfd);
    return 0;
}
Beispiel #7
0
static krb5_error_code
unparse_name_fixed(krb5_context context,
		   krb5_const_principal principal,
		   char *name,
		   size_t len,
		   int flags)
{
    size_t idx = 0;
    int i;
    int short_form = (flags & KRB5_PRINCIPAL_UNPARSE_SHORT) != 0;
    int no_realm = (flags & KRB5_PRINCIPAL_UNPARSE_NO_REALM) != 0;
    int display = (flags & KRB5_PRINCIPAL_UNPARSE_DISPLAY) != 0;

    if (!no_realm && princ_realm(principal) == NULL) {
	krb5_set_error_message(context, ERANGE,
			       N_("Realm missing from principal, "
				  "can't unparse", ""));
	return ERANGE;
    }

    for(i = 0; i < princ_num_comp(principal); i++){
	if(i)
	    add_char(name, idx, len, '/');
	idx = quote_string(princ_ncomp(principal, i), name, idx, len, display);
	if(idx == len) {
	    krb5_set_error_message(context, ERANGE,
				   N_("Out of space printing principal", ""));
	    return ERANGE;
	}
    }
    /* add realm if different from default realm */
    if(short_form && !no_realm) {
	krb5_realm r;
	krb5_error_code ret;
	ret = krb5_get_default_realm(context, &r);
	if(ret)
	    return ret;
	if(strcmp(princ_realm(principal), r) != 0)
	    short_form = 0;
	free(r);
    }
    if(!short_form && !no_realm) {
	add_char(name, idx, len, '@');
	idx = quote_string(princ_realm(principal), name, idx, len, display);
	if(idx == len) {
	    krb5_set_error_message(context, ERANGE,
				   N_("Out of space printing "
				      "realm of principal", ""));
	    return ERANGE;
	}
    }
    return 0;
}
Beispiel #8
0
static void
amstar_selfcheck(
    application_argument_t *argument)
{
    fprintf(stdout, "OK amstar\n");
    if (argument->dle.disk) {
	char *qdisk = quote_string(argument->dle.disk);
	fprintf(stdout, "OK %s\n", qdisk);
	amfree(qdisk);
    }
    if (argument->dle.device) {
	char *qdevice = quote_string(argument->dle.device);
	fprintf(stdout, "OK %s\n", qdevice);
	amfree(qdevice);
    }
    if (star_directory) {
	char *qdirectory = quote_string(star_directory);
	fprintf(stdout, "OK %s\n", qdirectory);
	amfree(qdirectory);
    }

    if (argument->dle.include_list &&
	argument->dle.include_list->nb_element >= 0) {
	fprintf(stdout, "ERROR include-list not supported for backup\n");
    }

    if (!star_path) {
	fprintf(stdout, "ERROR STAR-PATH not defined\n");
    } else {
	check_file(star_path, X_OK);
    }

    if (argument->calcsize) {
	char *calcsize = vstralloc(amlibexecdir, "/", "calcsize", NULL);
	check_file(calcsize, X_OK);
	check_suid(calcsize);
	amfree(calcsize);
    }

    {
	char *amandates_file;
	amandates_file = getconf_str(CNF_AMANDATES);
	check_file(amandates_file, R_OK|W_OK);
    }

    set_root_privs(1);
    if (argument->dle.device) {
	check_dir(argument->dle.device, R_OK);
    }
    set_root_privs(0);
}
Beispiel #9
0
static void
check_space(
    char *	dir,
    off_t	kbytes)
{
    struct fs_usage fsusage;
    char *quoted = quote_string(dir);
    intmax_t kb_avail;

    if(get_fs_usage(dir, NULL, &fsusage) == -1) {
	g_printf(_("ERROR [cannot get filesystem usage for %s: %s]\n"), quoted, strerror(errno));
	amfree(quoted);
	return;
    }

    /* do the division first to avoid potential integer overflow */
    kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize;

    if (fsusage.fsu_bavail_top_bit_set || fsusage.fsu_bavail == 0) {
	g_printf(_("ERROR [dir %s needs %lldKB, has nothing available.]\n"), quoted,
		(long long)kbytes);
    } else if (kb_avail < kbytes) {
	g_printf(_("ERROR [dir %s needs %lldKB, only has %lldKB available.]\n"), quoted,
		(long long)kbytes,
		(long long)kb_avail);
    } else {
	g_printf(_("OK %s has more than %lldKB available.\n"),
		quoted, (long long)kbytes);
    }
    amfree(quoted);
}
Beispiel #10
0
static void
amgtar_selfcheck(
    application_argument_t *argument)
{
    amgtar_build_exinclude(&argument->dle, 1, NULL, NULL, NULL, NULL);

    printf("OK amgtar\n");
    if (gnutar_path) {
	check_file(gnutar_path, X_OK);
    } else {
	printf(_("ERROR [GNUTAR program not available]\n"));
    }

    set_root_privs(1);
    if (gnutar_listdir && strlen(gnutar_listdir) == 0)
	gnutar_listdir = NULL;
    if (gnutar_listdir) {
	check_dir(gnutar_listdir, R_OK|W_OK);
    } else {
	printf(_("ERROR [No GNUTAR-LISTDIR]\n"));
    }

    if (argument->dle.disk) {
	char *qdisk = quote_string(argument->dle.disk);
	fprintf(stdout, "OK %s\n", qdisk);
	amfree(qdisk);
    }
    if (gnutar_directory) {
	check_dir(gnutar_directory, R_OK);
    } else if (argument->dle.device) {
	check_dir(argument->dle.device, R_OK);
    }
    set_root_privs(0);
}
Beispiel #11
0
GncSqlStatementPtr
GncSqlBackend::build_update_statement(const gchar* table_name,
                                      QofIdTypeConst obj_name, gpointer pObject,
                                      const EntryVec& table) const noexcept
{
    GncSqlStatementPtr stmt;
    std::ostringstream sql;

    g_return_val_if_fail (table_name != nullptr, nullptr);
    g_return_val_if_fail (obj_name != nullptr, nullptr);
    g_return_val_if_fail (pObject != nullptr, nullptr);


    PairVec values{get_object_values (obj_name, pObject, table)};

    // Create the SQL statement
    sql <<  "UPDATE " << table_name << " SET ";

    for (auto const& col_value : values)
    {
        if (col_value != *values.begin())
            sql << ",";
        sql << col_value.first << "=" <<
            quote_string(col_value.second);
    }

    stmt = create_statement_from_sql(sql.str());
    /* We want our where condition to be just the first column and
     * value, i.e. the guid of the object.
     */
    values.erase(values.begin() + 1, values.end());
    stmt->add_where_cond(obj_name, values);
    return stmt;
}
Beispiel #12
0
GncSqlStatementPtr
GncSqlBackend::build_insert_statement (const char* table_name,
                                       QofIdTypeConst obj_name,
                                       gpointer pObject,
                                       const EntryVec& table) const noexcept
{
    GncSqlStatementPtr stmt;
    PairVec col_values;
    std::ostringstream sql;

    g_return_val_if_fail (table_name != nullptr, nullptr);
    g_return_val_if_fail (obj_name != nullptr, nullptr);
    g_return_val_if_fail (pObject != nullptr, nullptr);
    PairVec values{get_object_values(obj_name, pObject, table)};

    sql << "INSERT INTO " << table_name <<"(";
    for (auto const& col_value : values)
    {
        if (col_value != *values.begin())
            sql << ",";
        sql << col_value.first;
    }

    sql << ") VALUES(";
    for (auto col_value : values)
    {
        if (col_value != *values.begin())
            sql << ",";
        sql << quote_string(col_value.second);
    }
    sql << ")";

    stmt = create_statement_from_sql(sql.str());
    return stmt;
}
Beispiel #13
0
/* In running mode (not startup mode), get a command from driver and
   deal with it. */
static gboolean process_driver_command(taper_state_t * state) {
    struct cmdargs *cmdargs;
    char * q;

    /* This will return QUIT if driver has died. */
    cmdargs = getcmd();
    switch (cmdargs->cmd) {
    case PORT_WRITE:
        /*
         * PORT-WRITE
         *   handle
         *   hostname
         *   features
         *   diskname
         *   level
         *   datestamp
         *   splitsize
         *   split_diskbuffer
         */
        process_port_write(state, cmdargs);
        break;
        
    case FILE_WRITE:
        /*
         * FILE-WRITE
         *   handle
         *   filename
         *   hostname
         *   features
         *   diskname
         *   level
         *   datestamp
         *   splitsize
         */
        process_file_write(state, cmdargs);
        break;
        
    case QUIT:
	free_cmdargs(cmdargs);
	if (state->device && state->device->volume_label) {
	    log_add(L_INFO, "tape %s kb %lld fm %d [OK]\n",
		    state->device->volume_label,
		    (long long)((state->total_bytes+(off_t)1023) / (off_t)1024),
		    state->device->file);
	}
        return send_quitting(state);
    default:
        if (cmdargs->argc >= 1) {
            q = quote_string(cmdargs->argv[0]);
        } else {
            q = stralloc("(no input?)");
        }
        putresult(BAD_COMMAND, "%s\n", q);
        amfree(q);
        break;
    }
    free_cmdargs(cmdargs);

    return TRUE;
}
Beispiel #14
0
static int
test_round_trip(void)
{
    char **strp;
    gboolean success = TRUE;

    for (strp = quotable_strings; *strp; strp++) {
	char *quoted, *unquoted;

	quoted = quote_string(*strp);
	unquoted = unquote_string(quoted);

	/* if they're not the same, complain */
	if (0 != strcmp(*strp, unquoted)) {
	    char *safe_orig = safestr(*strp);
	    char *safe_quoted = safestr(quoted);
	    char *safe_unquoted = safestr(unquoted);

	    printf("  bad round-trip: %s -quote_string-> %s -unquote_string-> %s\n",
		safe_orig, safe_quoted, safe_unquoted);

	    amfree(safe_orig);
	    amfree(safe_quoted);
	    amfree(safe_unquoted);

	    success = FALSE;
	}

	amfree(quoted);
	amfree(unquoted);
    }

    return success;
}
Beispiel #15
0
static int
test_split_quoted_strings(void)
{
    char **iter1, **iter2, **iter3;
    gboolean success = TRUE;
    char *middle_strings[] = {
	"",
	"foo",
	"\"foo\"",
	"sp aces",
	NULL,
    };

    /* the idea here is to loop over all triples of strings, forming a
     * string by quoting them with quote_string and inserting a space, then
     * re-splitting with split_quoted_string.  This should get us back to our
     * starting point. */

    for (iter1 = quotable_strings; *iter1; iter1++) {
	for (iter2 = middle_strings; *iter2; iter2++) {
	    for (iter3 = quotable_strings; *iter3; iter3++) {
		char *q1 = quote_string(*iter1);
		char *q2 = quote_string(*iter2);
		char *q3 = quote_string(*iter3);
		const char *expected[4] = { *iter1, *iter2, *iter3, NULL };
		char *combined = vstralloc(q1, " ", q2, " ", q3, NULL);
		char **tokens;

		tokens = split_quoted_strings(combined);

		success = compare_strv(expected, tokens, "split_quoted_strings", combined)
			&& success;

		amfree(q1);
		amfree(q2);
		amfree(q3);
		amfree(combined);
		g_strfreev(tokens);
	    }
	}
    }

    return success;
}
Beispiel #16
0
static void
quote_string_test(void)
{
    char const source[] = "foobar";
    char buffer[12];
    char *buffer_end = buffer + sizeof buffer;
    
    int result = quote_string(source, "<%=", "%>", buffer, buffer_end);
    assert(0 == result);
    ASSERT_STR_EQ("<%=foobar%>", buffer);
}
Beispiel #17
0
/* Put an L_PARTIAL message to the logfile. */
static void put_partial_log(dump_info_t * dump_info, double dump_time,
                            guint64 dump_kbytes, char *errstr) {
    char * qdiskname = quote_string(dump_info->diskname);

    log_add(L_PARTIAL, "%s %s %s %d %d [sec %f kb %ju kps %f] %s",
            dump_info->hostname, qdiskname, dump_info->timestamp,
            dump_info->current_part, dump_info->level, dump_time,
            (uintmax_t)dump_kbytes, get_kbps(dump_kbytes, dump_time),
	    errstr);
    amfree(qdiskname);
}
Beispiel #18
0
static void
quote_string_for_empty_quotes_test(void)
{
    char const source[] = "foobar";
    char buffer[7];
    char *buffer_end = buffer + sizeof buffer;
    
    int result = quote_string(source, "", "", buffer, buffer_end);
    
    assert(0 == result);
    ASSERT_STR_EQ("foobar", buffer);
}
Beispiel #19
0
/* Error.chpl:67 */
static void ioerror2(syserr error, chpl_string msg, chpl_string path, int64_t offset, int64_t _ln, c_string _fn) {
  int32_t call_tmp;
  chpl_bool call_tmp2;
  int32_t strerror_err;
  c_string call_tmp3;
  _ref_int32_t _ref_tmp_ = NULL;
  c_string call_tmp4;
  int64_t call_tmp5;
  c_string call_tmp6;
  c_string_copy call_tmp7;
  c_string call_tmp8;
  c_string call_tmp9;
  c_string_copy call_tmp10;
  c_string call_tmp11;
  c_string_copy call_tmp12;
  c_string call_tmp13;
  c_string_copy call_tmp14;
  c_string call_tmp15;
  c_string_copy call_tmp16;
  c_string_copy call_tmp17;
  uint32_t call_tmp18;
  c_string call_tmp19;
  c_string call_tmp20;
  c_string_copy call_tmp21;
  call_tmp = qio_err_iserr(error);
  call_tmp2 = (call_tmp != INT32(0));
  if (call_tmp2) {
    strerror_err = INT32(0);
    _ref_tmp_ = &strerror_err;
    call_tmp3 = sys_strerror_syserr_str(error, _ref_tmp_);
    c_string_from_string(&call_tmp4, &path, _ln, _fn);
    call_tmp5 = string_length(call_tmp4);
    call_tmp6 = quote_string(path, call_tmp5, _ln, _fn);
    call_tmp7 = string_concat(call_tmp3, " ", _ln, _fn);
    c_string_from_string(&call_tmp8, &msg, _ln, _fn);
    call_tmp9 = ((c_string)(call_tmp7));
    call_tmp10 = string_concat(call_tmp9, call_tmp8, _ln, _fn);
    call_tmp11 = ((c_string)(call_tmp10));
    call_tmp12 = string_concat(call_tmp11, " with path ", _ln, _fn);
    call_tmp13 = ((c_string)(call_tmp12));
    call_tmp14 = string_concat(call_tmp13, call_tmp6, _ln, _fn);
    call_tmp15 = ((c_string)(call_tmp14));
    call_tmp16 = string_concat(call_tmp15, " offset ", _ln, _fn);
    call_tmp18 = ((uint32_t)(INT64(8)));
    call_tmp17 = integral_to_c_string_copy(offset, call_tmp18, true);
    call_tmp19 = ((c_string)(call_tmp16));
    call_tmp20 = ((c_string)(call_tmp17));
    call_tmp21 = string_concat(call_tmp19, call_tmp20, _ln, _fn);
    chpl_error(call_tmp21, _ln, _fn);
  }
  return;
}
Beispiel #20
0
static int id_width(struct gale_text var,struct gale_text dfl) {
	struct gale_text value = gale_var(var);
	int i = 1,len = 0;
	if (0 == value.l) return 3 + dfl.l;

	do {
		if (quote_string(&value)) len += 2;
		len += 1 + value.l;
		value = gale_var(gale_text_concat(3,var,G_("_"),
			gale_text_from_number(++i,10,0)));
	} while (0 != value.l);
	return len;
}
void
cupsBackendReport(
    const char *device_scheme,		/* I - device-scheme string */
    const char *device_uri,		/* I - device-uri string */
    const char *device_make_and_model,	/* I - device-make-and-model string or @code NULL@ */
    const char *device_info,		/* I - device-info string or @code NULL@ */
    const char *device_id,		/* I - device-id string or @code NULL@ */
    const char *device_location)	/* I - device-location string or @code NULL@ */
{
  if (!device_scheme || !device_uri)
    return;

  printf("%s %s", device_scheme, device_uri);
  if (device_make_and_model && *device_make_and_model)
    quote_string(device_make_and_model);
  else
    quote_string("unknown");
  quote_string(device_info);
  quote_string(device_id);
  quote_string(device_location);
  putchar('\n');
  fflush(stdout);
}
Beispiel #22
0
static void
quote_string_for_buffer_too_small_test(void)
{
    char const source[] = "foobar";
    char buffer[8];
    char *buffer_end = buffer + sizeof buffer;
    errno = 0;
    
    int result = quote_string(source, "<%=", "%>", buffer, buffer_end);
    
    assert(EINVAL == errno);
    assert(-1 == result);
    ASSERT_STR_EQ("", buffer);
}
Beispiel #23
0
static void
amstar_selfcheck(
    application_argument_t *argument)
{
    fprintf(stdout, "OK amstar\n");
    if (argument->dle.disk) {
	char *qdisk = quote_string(argument->dle.disk);
	fprintf(stdout, "OK %s\n", qdisk);
	amfree(qdisk);
    }
    if (argument->dle.device) {
	char *qdevice = quote_string(argument->dle.device);
	fprintf(stdout, "OK %s\n", qdevice);
	amfree(qdevice);
    }

    if (!star_path) {
	fprintf(stdout, "ERROR STAR-PATH not defined\n");
    } else {
	check_file(star_path, X_OK);
    }

    if (argument->calcsize) {
	char *calcsize = vstralloc(amlibexecdir, "/", "calcsize", NULL);
	check_file(calcsize, X_OK);
	check_suid(calcsize);
	amfree(calcsize);
    }

    {
	char *amandates_file;
	amandates_file = getconf_str(CNF_AMANDATES);
	check_file(amandates_file, R_OK|W_OK);
    }

}
Beispiel #24
0
void
set_storage(void)
{
    char *qstorage = quote_string(storage_in);
    char *cmd = g_strconcat("STORAGE ", qstorage, NULL);
    storage_in = NULL;
    g_free(qstorage);

    if (exchange(cmd) == -1)
	exit(1);
    g_free(cmd);
    if (!server_happy()) {
    }
    suck_dir_list_from_server();	/* get list of directory contents */
}
Beispiel #25
0
/*
 * get pattern which match to #include lines.
 *
 *	i)	arg	include file name
 *	r)		pattern which match to #include lines
 */
static char *
include_pattern(const char *arg)
{
#if defined(_WIN32)
#define INCLUDE "^[ \t]*#[ \t]*include[ \t].*[\\\"\"</\\]%s[\\\"\">]"
#elif defined(__DJGPP__)
#define INCLUDE "^[ \t]*#[ \t]*include[ \t].*[\"</\\]%s[\">]"
#else
#define INCLUDE "^[ \t]*#[ \t]*include[ \t].*[\"</]%s[\">]"
#endif
	STATIC_STRBUF(pat);

	strbuf_clear(pat);
	strbuf_sprintf(pat, INCLUDE, quote_string(arg));
	return strbuf_value(pat);
}
Beispiel #26
0
/* sets a date, mapping given date into standard form if needed */
int
set_date(
    char *	date)
{
    char *cmd = NULL;
    char *qdisk_path;

    clear_dir_list();

    cmd = g_strconcat("DATE ", date, NULL);
    if (converse(cmd) == -1)
	exit(1);

    /* if a host/disk/directory is set, then check if that directory
       is still valid at the new date, and if not set directory to
       mount_point */
    if (disk_path != NULL) {
	qdisk_path = quote_string(disk_path);
	g_free(cmd);
	cmd = g_strconcat("OISD ", qdisk_path, NULL);
	amfree(qdisk_path);
	if (exchange(cmd) == -1)
	    exit(1);
	if (server_happy())
	{
	    suck_dir_list_from_server();
	}
	else
	{
	    g_printf(_("No index records for cwd on new date\n"));
	    g_printf(_("Setting cwd to mount point\n"));
	    g_free(disk_path);
	    g_free(disk_tpath);
	    disk_path = g_strdup("/");	/* fake it */
	    disk_tpath = g_strdup("/");	/* fake it */
	    clear_dir_list();
	}
    }
    amfree(cmd);
    return 0;
}
Beispiel #27
0
/**
 * Write the header information. 
 * @param arg ignored optional user param
 * @param style the name of the format style (for transformation)
 * @param dst the destination markup file handle
 * @return 1 if successful, 0 otherwise
 */
int STIL_write_header( void *arg, dest_file *dst, UChar *style )
{
    int res = 1;
    U_COMMA = utf8toutf16(",");
    U_COMMANL = utf8toutf16(",\n");
    U_LF = utf8toutf16("\n");
    U_HEAD = utf8toutf16( "{\n");
    U_TAIL = utf8toutf16( "\n  ]\n}\n");
    U_STYLE = utf8toutf16("  \"style\": ");
    U_RANGES_START = utf8toutf16("  \"ranges\": [\n");
	U_RANGE_START = utf8toutf16("  {\n");
    U_RANGE_END = utf8toutf16("  }");
    U_NAME = utf8toutf16("    \"name\": ");
    U_RELOFF = utf8toutf16("    \"reloff\": ");
    U_LEN = utf8toutf16("    \"len\": ");
    U_REMOVED = utf8toutf16("    \"removed\": ");
    U_CONTENT = utf8toutf16("    \"content\": ");
    U_ANNOTATIONS = utf8toutf16("    \"annotations\": [ ");
    U_ANNOTATIONS_END = utf8toutf16(" ]\n");
    U_ANNOTATION = utf8toutf16("{ ");
    U_ANNOTATION_END = utf8toutf16(" }");
    U_TRUE = utf8toutf16("true");
    U_COLON = utf8toutf16(": ");
    // write header
    UChar **items = calloc(5,sizeof(UChar*));
    if ( items != NULL )
    {
        items[0] = U_HEAD;
        items[1] = U_STYLE;
        items[2] = quote_string(style,u_strlen(style));
        items[3] = U_COMMANL;
        items[4] = U_RANGES_START;
        res = write_utf16_array( items, 5, dst );
        if ( items[2] != NULL )
            free( items[2] );
        free( items );
    }
    else
        res = 0;
	return res;
}
Beispiel #28
0
static int
append_string(char **str, size_t *total_len, const char *ss, 
	      size_t len, int quote)
{
    char *s, *qs;

    if (quote)
	qs = quote_string(ss, len, &len);
    else
	qs = rk_UNCONST(ss);

    s = realloc(*str, len + *total_len + 1);
    if (s == NULL)
	_hx509_abort("allocation failure"); /* XXX */
    memcpy(s + *total_len, qs, len);
    if (qs != ss)
	free(qs);
    s[*total_len + len] = '\0';
    *str = s;
    *total_len += len;
    return 0;
}
Beispiel #29
0
/* Error.chpl:55 */
static void ioerror(syserr error, chpl_string msg, chpl_string path, int64_t _ln, c_string _fn) {
  int32_t call_tmp;
  chpl_bool call_tmp2;
  int32_t strerror_err;
  c_string call_tmp3;
  _ref_int32_t _ref_tmp_ = NULL;
  c_string call_tmp4;
  int64_t call_tmp5;
  c_string call_tmp6;
  c_string_copy call_tmp7;
  c_string call_tmp8;
  c_string call_tmp9;
  c_string_copy call_tmp10;
  c_string call_tmp11;
  c_string_copy call_tmp12;
  c_string call_tmp13;
  c_string_copy call_tmp14;
  call_tmp = qio_err_iserr(error);
  call_tmp2 = (call_tmp != INT32(0));
  if (call_tmp2) {
    strerror_err = INT32(0);
    _ref_tmp_ = &strerror_err;
    call_tmp3 = sys_strerror_syserr_str(error, _ref_tmp_);
    c_string_from_string(&call_tmp4, &path, _ln, _fn);
    call_tmp5 = string_length(call_tmp4);
    call_tmp6 = quote_string(path, call_tmp5, _ln, _fn);
    call_tmp7 = string_concat(call_tmp3, " ", _ln, _fn);
    c_string_from_string(&call_tmp8, &msg, _ln, _fn);
    call_tmp9 = ((c_string)(call_tmp7));
    call_tmp10 = string_concat(call_tmp9, call_tmp8, _ln, _fn);
    call_tmp11 = ((c_string)(call_tmp10));
    call_tmp12 = string_concat(call_tmp11, " with path ", _ln, _fn);
    call_tmp13 = ((c_string)(call_tmp12));
    call_tmp14 = string_concat(call_tmp13, call_tmp6, _ln, _fn);
    chpl_error(call_tmp14, _ln, _fn);
  }
  return;
}
Beispiel #30
0
void
finish_amandates(void)
{
    amandates_t *amdp;
    int level;
    char *qname;

    if(amdf == NULL)
	return;

    if(updated) {
	if(readonly) {
	    error(_("updated amandates after opening readonly"));
	    /*NOTREACHED*/
	}

	rewind(amdf);
	for(amdp = amandates_list; amdp != NULL; amdp = amdp->next) {
	    for(level = 0; level < DUMP_LEVELS; level++) {
		if(amdp->dates[level] == EPOCH) continue;
		qname = quote_string(amdp->name);
		g_fprintf(amdf, "%s %d %ld\n",
			qname, level, (long) amdp->dates[level]);
		amfree(qname);
	    }
	}
    }

    if(amfunlock(fileno(amdf), g_amandates_file) == -1) {
	error(_("could not unlock %s: %s"), g_amandates_file, strerror(errno));
	/*NOTREACHED*/
    }
    if (fclose(amdf) == EOF) {
	error(_("error [closing %s: %s]"), g_amandates_file, strerror(errno));
	/*NOTREACHED*/
    }
    amdf = NULL;
}