Check-in [1e1d242f28]
Overview
Comment:Updated to use uid/gid instead of usernames
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1e1d242f28b61129b33b620ece88bbbfaa36a06b
User & Date: rkeene on 2012-09-17 13:23:44
Other Links: manifest | tags
Context
2012-09-17
13:24
Added UNIX domain socket support check-in: 396386bf82 user: rkeene tags: trunk
13:23
Updated to use uid/gid instead of usernames check-in: 1e1d242f28 user: rkeene tags: trunk
2012-09-15
06:53
Removed unneeded casts check-in: e91caa4ecf user: rkeene tags: trunk
Changes

Modified system.c from [2a84d834a9] to [9210e80361].

1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935










1936
1937
1938
1939
1940
1941
1942
	}

	return(retval);
}

static int tclsystem_tsmf_start_svc(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
	struct timeval select_timeout;
	Tcl_WideInt umask_val, timeout_val;
	Tcl_Obj *filename_obj, *env_obj, *logfile_obj, **env_entry_objv, *cwd_obj, *umask_obj, *user_obj, *group_obj;
	Tcl_Obj *sri_obj, *timeout_obj;
	pid_t child, child_pgid = -1, waitpid_ret;
	ssize_t read_ret;
	time_t currtime;
	char *argv[3], *envv[512];
	char *logfile, *filename, *cwd, *user, *group;
	char logmsg[2048];
	fd_set read_fdset;
	int pipe_ret, setsid_ret, execve_ret, tcl_ret, select_ret, chdir_ret;
	int null_fd, log_fd, tmp_fd, max_fd;
	int env_entry_objc;
	int fds[2], fd;
	int status;
	int idx;

	/* 1. Parse arguments */
	/* 1.a. Ensure the correct number of arguments were passed */
	if (objc != 10) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args: should be \"::system::syscall::tsmf_start_svc sri filename logfile env cwd umask user group timeout\"", -1));

		return(TCL_ERROR);
	}

	/* 1.b. Identify Tcl_Objs to use for each argument */
	sri_obj = objv[1];
	filename_obj = objv[2];
	logfile_obj = objv[3];
	env_obj = objv[4];
	cwd_obj = objv[5];
	umask_obj = objv[6];
	user_obj = objv[7];
	group_obj = objv[8];
	timeout_obj = objv[9];

	/* 1.c. Store string arguments */
	filename = Tcl_GetString(filename_obj);
	logfile = Tcl_GetString(logfile_obj);
	cwd = Tcl_GetString(cwd_obj);
	user = Tcl_GetString(user_obj);
	group = Tcl_GetString(group_obj);

	/* 1.d. Integer objects */
	tcl_ret = Tcl_GetWideIntFromObj(interp, umask_obj, &umask_val);
	if (tcl_ret != TCL_OK) {
		return(tcl_ret);
	}

	tcl_ret = Tcl_GetWideIntFromObj(interp, timeout_obj, &timeout_val);
	if (tcl_ret != TCL_OK) {
		return(tcl_ret);
	}











	/* 1.e. Process environment */
	tcl_ret = Tcl_ListObjGetElements(interp, env_obj, &env_entry_objc, &env_entry_objv);
	if (tcl_ret != TCL_OK) {
		return(tcl_ret);
	}








|
|





|












|











|
|






<
<











>
>
>
>
>
>
>
>
>
>







1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922


1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
	}

	return(retval);
}

static int tclsystem_tsmf_start_svc(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
	struct timeval select_timeout;
	Tcl_WideInt umask_val, timeout_val, uid_val, gid_val;
	Tcl_Obj *filename_obj, *env_obj, *logfile_obj, **env_entry_objv, *cwd_obj, *umask_obj, *uid_obj, *gid_obj;
	Tcl_Obj *sri_obj, *timeout_obj;
	pid_t child, child_pgid = -1, waitpid_ret;
	ssize_t read_ret;
	time_t currtime;
	char *argv[3], *envv[512];
	char *logfile, *filename, *cwd;
	char logmsg[2048];
	fd_set read_fdset;
	int pipe_ret, setsid_ret, execve_ret, tcl_ret, select_ret, chdir_ret;
	int null_fd, log_fd, tmp_fd, max_fd;
	int env_entry_objc;
	int fds[2], fd;
	int status;
	int idx;

	/* 1. Parse arguments */
	/* 1.a. Ensure the correct number of arguments were passed */
	if (objc != 10) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args: should be \"::system::syscall::tsmf_start_svc sri filename logfile env cwd umask uid gid timeout\"", -1));

		return(TCL_ERROR);
	}

	/* 1.b. Identify Tcl_Objs to use for each argument */
	sri_obj = objv[1];
	filename_obj = objv[2];
	logfile_obj = objv[3];
	env_obj = objv[4];
	cwd_obj = objv[5];
	umask_obj = objv[6];
	uid_obj = objv[7];
	gid_obj = objv[8];
	timeout_obj = objv[9];

	/* 1.c. Store string arguments */
	filename = Tcl_GetString(filename_obj);
	logfile = Tcl_GetString(logfile_obj);
	cwd = Tcl_GetString(cwd_obj);



	/* 1.d. Integer objects */
	tcl_ret = Tcl_GetWideIntFromObj(interp, umask_obj, &umask_val);
	if (tcl_ret != TCL_OK) {
		return(tcl_ret);
	}

	tcl_ret = Tcl_GetWideIntFromObj(interp, timeout_obj, &timeout_val);
	if (tcl_ret != TCL_OK) {
		return(tcl_ret);
	}

	tcl_ret = Tcl_GetWideIntFromObj(interp, uid_obj, &uid_val);
	if (tcl_ret != TCL_OK) {
		return(tcl_ret);
	}

	tcl_ret = Tcl_GetWideIntFromObj(interp, gid_obj, &gid_val);
	if (tcl_ret != TCL_OK) {
		return(tcl_ret);
	}

	/* 1.e. Process environment */
	tcl_ret = Tcl_ListObjGetElements(interp, env_obj, &env_entry_objc, &env_entry_objv);
	if (tcl_ret != TCL_OK) {
		return(tcl_ret);
	}

2069
2070
2071
2072
2073
2074
2075
2076

2077
2078
2079

2080
2081
2082
2083
2084
2085
2086
		}

		close(tmp_fd);
	}

	/* 6.g. Switch to appropriate user/group */
	/* 6.g.i. Group */
	/* XXX: TODO */


	/* 6.g.ii. User */
	/* XXX: TODO */


	/* 7. Create a new process to actually spawn the process */
	child = fork();
	if (child == -1) {
		write(fd, &child_pgid, sizeof(child_pgid));

		_exit(0);







<
>


<
>







2077
2078
2079
2080
2081
2082
2083

2084
2085
2086

2087
2088
2089
2090
2091
2092
2093
2094
		}

		close(tmp_fd);
	}

	/* 6.g. Switch to appropriate user/group */
	/* 6.g.i. Group */

	setgid(gid_val);

	/* 6.g.ii. User */

	setuid(uid_val);

	/* 7. Create a new process to actually spawn the process */
	child = fork();
	if (child == -1) {
		write(fd, &child_pgid, sizeof(child_pgid));

		_exit(0);