Beispiel #1
0
int cmd_gidit(int argc, const char **argv, const char *prefix)
{
	int flags = 0;
	int tags = 0, init = 0, verbose = 0, pushobj = 0, updatepl = 0, sign = 0,
		proj_init = 0, polist = 0, store_bundle = 0, get_bundle = 0, pobj_val = 0,
		create_bundle = 0;

	const char *basepath = NULL;
	const char *keyid = NULL;

	int rc;

	struct option options[] = {
		OPT__VERBOSE(&verbose),
		OPT_GROUP(""),
		OPT_BOOLEAN( 0 , "tags", &tags, "include tags"),
		OPT_BOOLEAN('s', NULL, &sign, "annotated and GPG-signed tag"),
		OPT_STRING('u', NULL, &keyid, "key-id",
					"use another key to sign the tag"),
		OPT_BOOLEAN( 0 , "pushobj", &pushobj, "generate push object"),
		OPT_BOOLEAN( 0 , "verify-pobj", &pobj_val, "validate a given pushobject"),
		OPT_BOOLEAN( 0 , "create-bundle", &create_bundle, "validate a given pushobject"),
		OPT_GROUP(""),
		OPT_BOOLEAN( 0 , "updatepl", &updatepl, "Update push list"),
		OPT_STRING('b', NULL, &basepath, "base-path", "base-path for daemon"),
		OPT_BOOLEAN( 0 , "init", &init, "init gidit directory"),
		OPT_BOOLEAN( 0 , "proj-init", &proj_init, "init user's gidit project directory"),
		OPT_BOOLEAN( 0 , "polist", &polist, "Generate list of push objects"),
		OPT_BOOLEAN( 0 , "store-bundle", &store_bundle, "store a given bundle"),
		OPT_BOOLEAN( 0 , "get-bundle", &get_bundle, "get a bundle"),
		OPT_END()
	};

	git_config(git_gidit_config, NULL);

	argc = parse_options(argc, argv, options, gidit_usage, 0);

	if (keyid) {
		sign = 1;
		set_signingkey(keyid);
	} else if (sign) {
		if (strlcpy(signingkey, git_committer_info(IDENT_ERROR_ON_NO_NAME),
				sizeof(signingkey)) > sizeof(signingkey) - 1)
			return error("committer info too long.");
		char * bracket = strchr(signingkey, '>');
		if (bracket)
			bracket[1] = '\0';
	}

	if (tags)
		flags |= INCLUDE_TAGS;


	if (pushobj)
		return !!gidit_pushobj(stdout, signingkey, sign, flags);
	else if (pobj_val)
		return !!gidit_verify_pushobj(stdin, flags);
	else if (create_bundle)
		return !!gidit_gen_bundle(stdin, flags);

	if (!basepath)
		usage_with_options(gidit_usage, options);

	if (base_path_test(basepath))
		return -1;

	if (init)
		rc = gidit_init(basepath);
	else if (proj_init)
		rc = gidit_proj_init(stdin, basepath, flags);
	else if (updatepl)
		rc = gidit_update_pl(stdin, basepath, flags);
	else if (polist)
		rc = gidit_po_list(stdin, basepath, flags);
	else if (store_bundle)
		rc = gidit_store_bundle(stdin, basepath, flags);
	else if (get_bundle)
		rc = gidit_get_bundle(stdin, stdout, basepath, flags);
	else
		rc = -1;

	if (rc == -1)
		usage_with_options(gidit_usage, options);
	else
		return rc;
}
Beispiel #2
0
int cmd_gidit(int argc, const char **argv, const char *prefix)
{
	int flags = 0;
	int init = 0, verbose = 0, pushobj = 0, updatepl = 0, sign = 0,
		proj_init = 0, polist = 0, store_bundle = 0, get_bundle = 0, pobj_val = 0,
		create_bundle = 0, push = 0, verify_polist = 0, list_missing = 0;

	const char *basepath = NULL;
	const char *keyid = NULL;
	const char *projname = NULL;
	char * url = NULL;
	char *nodekey = NULL;
	char *message = NULL;

	int rc;

	struct option options[] = {
		OPT__VERBOSE(&verbose),
		OPT_GROUP(""),
		OPT_BIT( 0 , "tags", &flags, "include tags", INCLUDE_TAGS),
		OPT_BIT( 0 , "force", &flags, "force", TRANSPORT_PUSH_FORCE),
		OPT_BOOLEAN('s', NULL, &sign, "annotated and GPG-signed tag"),
		OPT_STRING('u', NULL, &keyid, "key-id",
					"use another key to sign the tag"),
		OPT_BOOLEAN( 0 , "pushobj", &pushobj, "generate push object"),
		OPT_STRING('k',NULL, &nodekey, "nodekey", "key of node"),
		OPT_STRING('m',NULL, &message, "message", "message to send"),
		OPT_STRING('p',NULL, &projname, "project-name", "Project name"),
		OPT_BOOLEAN( 0 , "verify-pobj", &pobj_val, "validate a given pushobject"),
		OPT_BOOLEAN( 0 , "verify-polist", &verify_polist, "verify given polist as all known"),
		OPT_BOOLEAN( 0 , "list-missing", &list_missing, "List sha1's of missing pushobjs"),
		OPT_BOOLEAN( 0 , "push", &push, "Do a push over gidit"),
		OPT_BOOLEAN( 0 , "create-bundle", &create_bundle, 
					"validate a given pushobject"),
		OPT_GROUP(""),
		OPT_BOOLEAN( 0 , "updatepl", &updatepl, "Update push list"),
		OPT_STRING('b', NULL, &basepath, "base-path", "base-path for daemon"),
		OPT_BOOLEAN( 0 , "init", &init, "init gidit directory"),
		OPT_BOOLEAN( 0 , "proj-init", &proj_init, 
					"init user's gidit project directory"),
		OPT_BOOLEAN( 0 , "polist", &polist, "Generate list of push objects"),
		OPT_BOOLEAN( 0 , "store-bundle", &store_bundle, "store a given bundle"),
		OPT_BOOLEAN( 0 , "get-bundle", &get_bundle, "get a bundle"),
		OPT_END()
	};

	git_config(git_gidit_config, NULL);

	argc = parse_options(argc, argv, options, gidit_usage, 0);

	if (push)
		sign = 1;

	if (keyid) {
		sign = 1;
		set_signingkey(keyid);
	} else if (sign) {
		set_default_signingkey();
	}

	if (sign)
		flags |= SIGN;

	if (pushobj)
		return !!gidit_pushobj(stdout, signingkey, flags);
	else if (pobj_val)
		return !!gidit_verify_pushobj(stdin, flags);
	else if (pushobj)
		return !!gidit_pushobj(stdout, signingkey, flags);
	else if (create_bundle)
		return !!gidit_gen_bundle(stdin, flags);
	else if (verify_polist)
		return !!gidit_verify_pushobj_list(stdin);
	else if (list_missing)
		return !!gidit_missing_pushobjs(stdin);
	else if (push) {
		url = (char*)malloc(strlen("gidit://127.0.0.1:9418/") + 
				strlen(projname) + 1 + strlen(signingkey) + 1);
		sprintf(url, "gidit://127.0.0.1:9418/%s:%s", projname, signingkey);
		return !!gidit_push(url, 0, NULL, flags);
	}

	if (!basepath)
		usage_with_options(gidit_usage, options);

	if (base_path_test(basepath))
		return -1;

	if (init)
		rc = gidit_init(basepath);
	else if (proj_init)
		rc = gidit_proj_init_stream(stdin, basepath, flags);
	else if (updatepl)
		rc = gidit_update_pl(stdin, basepath, flags);
	else if (polist)
		rc = gidit_po_list_stream(stdin, basepath, flags);
	else if (store_bundle)
		rc = gidit_store_bundle_stream(stdin, basepath, flags);
	else if (get_bundle)
		rc = gidit_get_bundle(stdin, stdout, basepath, flags);
	else
		rc = -1;

	if (rc == -1)
		usage_with_options(gidit_usage, options);
	else
		return rc;
}
Beispiel #3
0
int main(int argc, char **argv)
{
	int listen_port = 0;
	char *listen_addr = NULL;
	int inetd_mode = 0;
	const char *pid_file = NULL, *user_name = NULL, *group_name = NULL;
	int detach = 0;
	struct passwd *pass = NULL;
	struct group *group;
	gid_t gid = 0;
	int i;

	git_extract_argv0_path(argv[0]);

	for (i = 1; i < argc; i++) {
		char *arg = argv[i];

		if (!prefixcmp(arg, "--listen=")) {
			listen_addr = xstrdup_tolower(arg + 9);
			continue;
		}

		if(!prefixcmp(arg, "--bootstrap")){
			gidit_init(arg+11,CHIMERA_PORT);
		}

		if (!prefixcmp(arg, "--port=")) {
			char *end;
			unsigned long n;
			n = strtoul(arg+7, &end, 0);
			if (arg[7] && !*end) {
				listen_port = n;
				continue;
			}
		}
		if (!strcmp(arg, "--inetd")) {
			inetd_mode = 1;
			log_syslog = 1;
			continue;
		}
		if (!strcmp(arg, "--verbose")) {
			verbose = 1;
			continue;
		}
		if (!strcmp(arg, "--syslog")) {
			log_syslog = 1;
			continue;
		}
		if (!strcmp(arg, "--export-all")) {
			export_all_trees = 1;
			continue;
		}
		if (!prefixcmp(arg, "--timeout=")) {
			timeout = atoi(arg+10);
			continue;
		}
		if (!prefixcmp(arg, "--init-timeout=")) {
			init_timeout = atoi(arg+15);
			continue;
		}
		if (!prefixcmp(arg, "--max-connections=")) {
			max_connections = atoi(arg+18);
			if (max_connections < 0)
				max_connections = 0;	        /* unlimited */
			continue;
		}
		if (!strcmp(arg, "--strict-paths")) {
			strict_paths = 1;
			continue;
		}
		if (!prefixcmp(arg, "--base-path=")) {
			base_path = arg+12;
			continue;
		}
		if (!strcmp(arg, "--base-path-relaxed")) {
			base_path_relaxed = 1;
			continue;
		}
		if (!prefixcmp(arg, "--interpolated-path=")) {
			interpolated_path = arg+20;
			continue;
		}
		if (!strcmp(arg, "--reuseaddr")) {
			reuseaddr = 1;
			continue;
		}
		if (!strcmp(arg, "--user-path")) {
			user_path = "";
			continue;
		}
		if (!prefixcmp(arg, "--user-path=")) {
			user_path = arg + 12;
			continue;
		}
		if (!prefixcmp(arg, "--pid-file=")) {
			pid_file = arg + 11;
			continue;
		}
		if (!strcmp(arg, "--detach")) {
			detach = 1;
			log_syslog = 1;
			continue;
		}
		if (!prefixcmp(arg, "--user="******"--group=")) {
			group_name = arg + 8;
			continue;
		}
		if (!prefixcmp(arg, "--enable=")) {
			enable_service(arg + 9, 1);
			continue;
		}
		if (!prefixcmp(arg, "--disable=")) {
			enable_service(arg + 10, 0);
			continue;
		}
		if (!prefixcmp(arg, "--allow-override=")) {
			make_service_overridable(arg + 17, 1);
			continue;
		}
		if (!prefixcmp(arg, "--forbid-override=")) {
			make_service_overridable(arg + 18, 0);
			continue;
		}
		if (!strcmp(arg, "--")) {
			ok_paths = &argv[i+1];
			break;
		} else if (arg[0] != '-') {
			ok_paths = &argv[i];
			break;
		}

		usage(daemon_usage);
	}

	if (log_syslog) {
		openlog("git-daemon", LOG_PID, LOG_DAEMON);
		set_die_routine(daemon_die);
	} else
		/* avoid splitting a message in the middle */
		setvbuf(stderr, NULL, _IOLBF, 0);

	if (inetd_mode && (group_name || user_name))
		die("--user and --group are incompatible with --inetd");

	if (inetd_mode && (listen_port || listen_addr))
		die("--listen= and --port= are incompatible with --inetd");
	else if (listen_port == 0)
		listen_port = DEFAULT_GIT_PORT;

	if (group_name && !user_name)
		die("--group supplied without --user");

	if (user_name) {
		pass = getpwnam(user_name);
		if (!pass)
			die("user not found - %s", user_name);

		if (!group_name)
			gid = pass->pw_gid;
		else {
			group = getgrnam(group_name);
			if (!group)
				die("group not found - %s", group_name);

			gid = group->gr_gid;
		}
	}

	if (strict_paths && (!ok_paths || !*ok_paths))
		die("option --strict-paths requires a whitelist");

	if (base_path && !is_directory(base_path))
		die("base-path '%s' does not exist or is not a directory",
		    base_path);

	if (inetd_mode) {
		struct sockaddr_storage ss;
		struct sockaddr *peer = (struct sockaddr *)&ss;
		socklen_t slen = sizeof(ss);

		if (!freopen("/dev/null", "w", stderr))
			die("failed to redirect stderr to /dev/null: %s",
			    strerror(errno));

		if (getpeername(0, peer, &slen))
			peer = NULL;

		return execute(peer);
	}

	if (detach) {
		daemonize();
		loginfo("Ready to rumble");
	}
	else
		sanitize_stdfds();

	if (pid_file)
		store_pid(pid_file);

	return serve(listen_addr, listen_port, pass, gid);
}