Exemplo n.º 1
0
/* This implements svn_editor_cb_copy_t */
static svn_error_t *
copy_cb(void *baton,
        const char *src_relpath,
        svn_revnum_t src_revision,
        const char *dst_relpath,
        svn_revnum_t replaces_rev,
        apr_pool_t *scratch_pool)
{
    struct edit_baton *eb = baton;
    const char *src_fspath = FSPATH(src_relpath, scratch_pool);
    const char *dst_fspath = FSPATH(dst_relpath, scratch_pool);
    svn_fs_root_t *root;
    svn_fs_root_t *src_root;

    SVN_ERR(get_root(&root, eb));

    /* Check if we can we replace the maybe-specified destination (revision).  */
    if (SVN_IS_VALID_REVNUM(replaces_rev))
    {
        SVN_ERR(can_modify(root, dst_fspath, replaces_rev, scratch_pool));
        SVN_ERR(svn_fs_delete(root, dst_fspath, scratch_pool));
    }
    else
    {
        SVN_ERR(can_create(root, dst_fspath, scratch_pool));
    }

    SVN_ERR(svn_fs_revision_root(&src_root, svn_fs_root_fs(root), src_revision,
                                 scratch_pool));
    SVN_ERR(svn_fs_copy(src_root, src_fspath, root, dst_fspath, scratch_pool));
    svn_fs_close_root(src_root);

    return SVN_NO_ERROR;
}
Exemplo n.º 2
0
/* This implements svn_editor_cb_add_file_t */
static svn_error_t *
add_file_cb(void *baton,
            const char *relpath,
            const svn_checksum_t *checksum,
            svn_stream_t *contents,
            apr_hash_t *props,
            svn_revnum_t replaces_rev,
            apr_pool_t *scratch_pool)
{
    struct edit_baton *eb = baton;
    const char *fspath = FSPATH(relpath, scratch_pool);
    svn_fs_root_t *root;

    SVN_ERR(get_root(&root, eb));

    if (SVN_IS_VALID_REVNUM(replaces_rev))
    {
        SVN_ERR(can_modify(root, fspath, replaces_rev, scratch_pool));
        SVN_ERR(svn_fs_delete(root, fspath, scratch_pool));
    }
    else
    {
        SVN_ERR(can_create(root, fspath, scratch_pool));
    }

    SVN_ERR(svn_fs_make_file(root, fspath, scratch_pool));

    SVN_ERR(set_text(root, fspath, checksum, contents,
                     eb->cancel_func, eb->cancel_baton, scratch_pool));
    SVN_ERR(add_new_props(root, fspath, props, scratch_pool));

    return SVN_NO_ERROR;
}
Exemplo n.º 3
0
/* This implements svn_editor_cb_add_directory_t */
static svn_error_t *
add_directory_cb(void *baton,
                 const char *relpath,
                 const apr_array_header_t *children,
                 apr_hash_t *props,
                 svn_revnum_t replaces_rev,
                 apr_pool_t *scratch_pool)
{
    struct edit_baton *eb = baton;
    const char *fspath = FSPATH(relpath, scratch_pool);
    svn_fs_root_t *root;

    /* Note: we ignore CHILDREN. We have no "incomplete" state to worry about,
       so we don't need to be aware of what children will be created.  */

    SVN_ERR(get_root(&root, eb));

    if (SVN_IS_VALID_REVNUM(replaces_rev))
    {
        SVN_ERR(can_modify(root, fspath, replaces_rev, scratch_pool));
        SVN_ERR(svn_fs_delete(root, fspath, scratch_pool));
    }
    else
    {
        SVN_ERR(can_create(root, fspath, scratch_pool));
    }

    SVN_ERR(svn_fs_make_dir(root, fspath, scratch_pool));
    SVN_ERR(add_new_props(root, fspath, props, scratch_pool));

    return SVN_NO_ERROR;
}
Exemplo n.º 4
0
/* This implements svn_editor_cb_move_t */
static svn_error_t *
move_cb(void *baton,
        const char *src_relpath,
        svn_revnum_t src_revision,
        const char *dst_relpath,
        svn_revnum_t replaces_rev,
        apr_pool_t *scratch_pool)
{
    struct edit_baton *eb = baton;
    const char *src_fspath = FSPATH(src_relpath, scratch_pool);
    const char *dst_fspath = FSPATH(dst_relpath, scratch_pool);
    svn_fs_root_t *root;
    svn_fs_root_t *src_root;

    SVN_ERR(get_root(&root, eb));

    /* Check if we delete the specified source (revision), and can we replace
       the maybe-specified destination (revision).  */
    SVN_ERR(can_modify(root, src_fspath, src_revision, scratch_pool));
    if (SVN_IS_VALID_REVNUM(replaces_rev))
    {
        SVN_ERR(can_modify(root, dst_fspath, replaces_rev, scratch_pool));
        SVN_ERR(svn_fs_delete(root, dst_fspath, scratch_pool));
    }
    else
    {
        SVN_ERR(can_create(root, dst_fspath, scratch_pool));
    }

    /* ### would be nice to have svn_fs_move()  */

    /* Copy the src to the dst. */
    SVN_ERR(svn_fs_revision_root(&src_root, svn_fs_root_fs(root), src_revision,
                                 scratch_pool));
    SVN_ERR(svn_fs_copy(src_root, src_fspath, root, dst_fspath, scratch_pool));
    svn_fs_close_root(src_root);

    /* Notice: we're deleting the src repos path from the dst root. */
    SVN_ERR(svn_fs_delete(root, src_fspath, scratch_pool));

    return SVN_NO_ERROR;
}
Exemplo n.º 5
0
/* This implements svn_editor_cb_add_symlink_t */
static svn_error_t *
add_symlink_cb(void *baton,
               const char *relpath,
               const char *target,
               apr_hash_t *props,
               svn_revnum_t replaces_rev,
               apr_pool_t *scratch_pool)
{
    struct edit_baton *eb = baton;
    const char *fspath = FSPATH(relpath, scratch_pool);
    svn_fs_root_t *root;

    SVN_ERR(get_root(&root, eb));

    if (SVN_IS_VALID_REVNUM(replaces_rev))
    {
        SVN_ERR(can_modify(root, fspath, replaces_rev, scratch_pool));
        SVN_ERR(svn_fs_delete(root, fspath, scratch_pool));
    }
    else
    {
        SVN_ERR(can_create(root, fspath, scratch_pool));
    }

    /* ### we probably need to construct a file with specific contents
       ### (until the FS grows some symlink APIs)  */
#if 0
    SVN_ERR(svn_fs_make_file(root, fspath, scratch_pool));
    SVN_ERR(svn_fs_apply_text(&fs_contents, root, fspath,
                              NULL /* result_checksum */,
                              scratch_pool));
    /* ### SVN_ERR(svn_stream_printf(fs_contents, ..., scratch_pool));  */
    apr_hash_set(props, SVN_PROP_SPECIAL, APR_HASH_KEY_STRING,
                 SVN_PROP_SPECIAL_VALUE);

    SVN_ERR(add_new_props(root, fspath, props, scratch_pool));
#endif

    SVN__NOT_IMPLEMENTED();
}
Exemplo n.º 6
0
int load_config(const char *file)
{
	FILE *f;
	char line[BUFSIZ];
	int ln = 1;
	struct passwd *p;

	if(file == (const char *) 0)
	{
		fprintf(stderr, "please supply a configuration file.\n");
		fprintf(stderr, "EASHD_CONFIG = %.100s\n", EASHD_CONFIG);
		exit(EXIT_FAILURE);
	}

	if((f = fopen(file, "r")) == (FILE *) 0)
	{
		fprintf(stderr, "%.100s: %.100s (%i)\n", file, strerror(errno), errno);
		exit(EXIT_FAILURE);
	}

	for(ln = 1; fgets(line, sizeof(line), f); ln++)
	{
		char key[1024];
		char val[1024];
		char *ptr;
		int x = 0;

		ptr = line;

		/* skip initial white space */
		while(isspace(*ptr))
			ptr++;

		if(strlen(ptr) <= 0)
			continue;

		if(*ptr == '#' || *ptr == '\n' || *ptr == '\r')
			continue;

		switch(sscanf(ptr, "%1000[^ \t]%1000s\n", (char *) &key, (char *) &val))
		{
			/* found both key and value pairs */
			case 2:
				switch(get_token(key))
				{
					case eHookTimeout:
						option.hook_timeout = atol(val);

						if(option.hook_timeout < 1 || option.hook_timeout > 65536)
						{
							fprintf(stderr, "[%.100s, line %i]: HookTimeout %i out of range.\n", file, ln, option.port);
							return(-1);
						}
						break;
					case ePort:
						option.port = atol(val);

						if(option.port < 1 || option.port > 65536)
						{
							fprintf(stderr, "[%.100s, line %i]: port %i out of range.\n", file, ln, option.port);
							return(-1);
						}
						break;
					case eListenAddress:
						option.listenaddress = strdup(val);
						break;
					case ePidFile:
						option.pidfile = strdup(val);
						if(can_create(file, ln, option.pidfile) < 0)
							return(-1);
						break;
					case eLogLevel:
						if(!strcasecmp(val, "info"))
							option.level = eINFO;
						else if(!strcasecmp(val, "debug1"))
							option.level = eDEBUG1;
						else if(!strcasecmp(val, "debug2"))
							option.level = eDEBUG2;
						else if(!strcasecmp(val, "debug3"))
							option.level = eDEBUG3;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid log level.\n", file, ln);
							return(-1);
						}
						break;
					case eSyslogFacility:
						if(!strcasecmp(val, "log_kern"))
							option.facility = LOG_KERN;
						else if(!strcasecmp(val, "log_user"))
							option.facility = LOG_USER;
						else if(!strcasecmp(val, "log_mail"))
							option.facility = LOG_MAIL;
						else if(!strcasecmp(val, "log_daemon"))
							option.facility = LOG_DAEMON;
						else if(!strcasecmp(val, "log_auth"))
							option.facility = LOG_AUTH;
						else if(!strcasecmp(val, "log_lpr"))
							option.facility = LOG_LPR;
						else if(!strcasecmp(val, "log_news"))
							option.facility = LOG_NEWS;
						else if(!strcasecmp(val, "log_uucp"))
							option.facility = LOG_UUCP;
						else if(!strcasecmp(val, "log_cron"))
							option.facility = LOG_CRON;
						else if(!strcasecmp(val, "log_local0"))
							option.facility = LOG_LOCAL0;
						else if(!strcasecmp(val, "log_local1"))
							option.facility = LOG_LOCAL1;
						else if(!strcasecmp(val, "log_local2"))
							option.facility = LOG_LOCAL2;
						else if(!strcasecmp(val, "log_local3"))
							option.facility = LOG_LOCAL3;
						else if(!strcasecmp(val, "log_local4"))
							option.facility = LOG_LOCAL4;
						else if(!strcasecmp(val, "log_local5"))
							option.facility = LOG_LOCAL5;
						else if(!strcasecmp(val, "log_local6"))
							option.facility = LOG_LOCAL6;
						else if(!strcasecmp(val, "log_local7"))
							option.facility = LOG_LOCAL7;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid syslog facility.\n", file, ln);
							return(-1);
						}
						break;
					case eSyslogPriority:
						if(!strcasecmp(val, "log_emerg"))
							option.priority = LOG_EMERG;
						else if(!strcasecmp(val, "log_alert"))
							option.priority = LOG_ALERT;
						else if(!strcasecmp(val, "log_crit"))
							option.priority = LOG_CRIT;
						else if(!strcasecmp(val, "log_err"))
							option.priority = LOG_ERR;
						else if(!strcasecmp(val, "log_warning"))
							option.priority = LOG_WARNING;
						else if(!strcasecmp(val, "log_notice"))
							option.priority = LOG_NOTICE;
						else if(!strcasecmp(val, "log_info"))
							option.priority = LOG_INFO;
						else if(!strcasecmp(val, "log_debug"))
							option.priority = LOG_DEBUG;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid syslog priority.\n", file, ln);
							return(-1);
						}
						break;
					case eCipher:
						option.cipher = strdup(val);
						break;
					case eMethod:
						if(!strcasecmp(val, "tlsv1"))
						{
							option.eash_method = TLSv1;
							option.method = TLSv1_server_method();
						}
						else if(!strcasecmp(val, "sslv2"))
						{
							option.eash_method = SSLv2;
							option.method = SSLv2_server_method();
						}
						else if(!strcasecmp(val, "sslv3"))
						{
							option.eash_method = SSLv3;
							option.method = SSLv3_server_method();
						}
						else if(!strcasecmp(val, "sslv23"))
						{
							option.eash_method = SSLv23;
							option.method = SSLv23_server_method();
						}
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid SSL method.\n", file, ln);
							return(-1);
						}
						break;
					case eNotificationHook:
						option.hook = strdup(val);
						if(verify_file(file, ln, option.hook) < 0)
							return(-1);
						break;
					case ePrivateKey:
						option.pemfile = strdup(val);
						if(verify_file(file, ln, option.pemfile) < 0)
							return(-1);
						break;
					case eRandomFile:
						option.randomfile = strdup(val);
						if(verify_file(file, ln, option.randomfile) < 0)
							return(-1);
						break;
					case eEGDFile:
						option.egdfile = strdup(val);
						if(verify_file(file, ln, option.egdfile) < 0)
							return(-1);
						break;
					case eSessionDirectory:
						option.sessiondirectory = strdup(val);
						if(verify_file_silent(file, ln, option.sessiondirectory) < 0)
						{
							fprintf(stderr, "info: creating SessionDirectory %.100s\n", option.sessiondirectory);
							if(mkdir(option.sessiondirectory, 0700) < 0)
							{
								fprintf(stderr, "[%.100s, line %i]: mkdir: %.100s (%i)\n", file, ln, strerror(errno), errno);
								return(-1);
							}

							if(chmod(option.sessiondirectory, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
							{
								fprintf(stderr, "[%.100s, line %i]: chmod: %.100s (%i)\n", file, ln, strerror(errno), errno);
								return(-1);
							}
						}
						snprintf(option.sessiondb, sizeof(option.sessiondb) - 1, "%s/db", option.sessiondirectory);
						break;
					case eCertificateAuthority:
						x = 0;

						while(option.cafiles[x] != NULL)
							x++;

						if(!(option.cafiles = realloc(option.cafiles, sizeof(char *) * (x + 2))))
						{
							fprintf(stderr, "realloc: %.100s (%i)\n", strerror(errno), errno);
							return(-1);
						}

						if(!(option.cafiles[x] = strdup(val)))
						{
							fprintf(stderr, "strdup: %.100s (%i)\n", strerror(errno), errno);
							return(-1);
						}

						option.cafiles[x + 1] = 0;
						break;
					case eUser:
						if(is_string(val))
						{
							if((p = getpwnam(val)) == (struct passwd *) 0)
							{
								fprintf(stderr, "[%.100s, line %i]: unknown username.\n", file, ln);
								return(-1);
							}
							else
							{
								option.uid = p->pw_uid;
								option.gid = p->pw_gid;
							}
						}
						else
						{
							if((p = getpwuid((uid_t) atol(val))) == (struct passwd *) 0)
							{
								fprintf(stderr, "[%.100s, line %i]: unknown UID.\n", file, ln);
								return(-1);
							}
							else
							{
								option.uid = p->pw_uid;
								option.gid = p->pw_gid;
							}
						}
						break;
					case eSync:
						if(!(strcasecmp(val, "_IONBF")))
							option.sync = _IONBF;
						else if(!(strcasecmp(val, "_IOLBF")))
							option.sync = _IOLBF;
						else if(!(strcasecmp(val, "_IOFBF")))
							option.sync = _IOFBF;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid argument.\n", file, ln);
							fprintf(stderr, " _IONBF unbuffered\n");
							fprintf(stderr, " _IOLBF line buffered\n");
							fprintf(stderr, " _IOFBF fully buffered\n");
							return(-1);
						}
						break;
					case eSignInode:
						if(!(strcasecmp(val, "yes")))
							option.strict_inode = 1;
						else if(!(strcasecmp(val, "no")))
							option.strict_inode = 0;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid argument.  yes or no.\n", file, ln);
							return(-1);
						}
						break;
					case eSignMode:
						if(!(strcasecmp(val, "yes")))
							option.strict_mode = 1;
						else if(!(strcasecmp(val, "no")))
							option.strict_mode = 0;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid argument.  yes or no.\n", file, ln);
							return(-1);
						}
						break;
					case eSignOwner:
						if(!(strcasecmp(val, "yes")))
							option.strict_owner = 1;
						else if(!(strcasecmp(val, "no")))
							option.strict_owner = 0;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid argument.  yes or no.\n", file, ln);
							return(-1);
						}
						break;
					case eSignCtime:
						if(!(strcasecmp(val, "yes")))
							option.strict_ctime = 1;
						else if(!(strcasecmp(val, "no")))
							option.strict_ctime = 0;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid argument.  yes or no.\n", file, ln);
							return(-1);
						}
						break;
					case eSignMtime:
						if(!(strcasecmp(val, "yes")))
							option.strict_mtime = 1;
						else if(!(strcasecmp(val, "no")))
							option.strict_mtime = 0;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid argument.  yes or no.\n", file, ln);
							return(-1);
						}
						break;
					case eHookFailureCritical:
						if(!(strcasecmp(val, "yes")))
							option.hook_failure_critical = 1;
						else if(!(strcasecmp(val, "no")))
							option.hook_failure_critical = 0;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid argument.  yes or no.\n", file, ln);
							return(-1);
						}
						break;
					case eKeepAlive:
						if(!(strcasecmp(val, "yes")))
							option.keepalive = 1;
						else if(!(strcasecmp(val, "no")))
							option.keepalive = 0;
						else
						{
							fprintf(stderr, "[%.100s, line %i]: invalid argument.  yes or no.\n", file, ln);
							return(-1);
						}
						break;
					case eIdleTimeout:
						option.idletimeout = atol(val);
						if(option.idletimeout == -1)
							s_log(eDEBUG1, "IdleTimeout = -1 -- disabling session timeout.");
						else if(option.idletimeout < 60)
						{
							fprintf(stderr, "[%.100s, line %i]: set a timeout over 60 seconds\n", file, ln);
							return(-1);
						}
						break;
					case eBadOption:
						fprintf(stderr, "[%.100s, line %i]: bad configuration option: %.63s\n", file, ln, key);
						return(-1);
						break;
                                        case emysql_IP:
                                                option.mysql_IP = strdup(val);
						break;
                                                
                                        case emysql_user:
                                                option.mysql_user = strdup(val);
						break;
                                                
                                        case emysql_pass:
                                                option.mysql_pass = strdup(val);
						break;
                                                
                                        case emysql_db:
                                                option.mysql_db = strdup(val);
						break;
                                                
                                        case emysql_port:
						option.mysql_port = atol(val);
						if(option.mysql_port < 1 || option.mysql_port > 65536)
						{
							fprintf(stderr, "[%.100s, line %i]: mysqlport %i out of range.\n", file, ln, option.port);
							return(-1);
						}
						break;
				}
				break;
			case 1:
				if(key[strlen(key)-1] == '\n')
					key[strlen(key)-1] = '\0';

				switch(get_token(key))
				{
					case eBadOption:
						fprintf(stderr, "[%.100s, line %i]: bad configuration option: %.63s\n", file, ln, key);
						return(-1);
						break;
					default:
						fprintf(stderr, "[%.100s, line %i]: missing arguement.\n", file, ln);
						return(-1);
						break;
				}
				break;
			default:
				fprintf(stderr, "[%.100s, line %i]: invalid syntax.\n", file, ln);
				return(-1);
				break;
		}
	}

	fclose(f);

	return(0);
}