Check-in [a48ac76ac7]
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:a48ac76ac782be4b99f28ceec2c44379051bc1c4
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: fc10a2ba9a user: rkeene tags: trunk
13:23
Updated to use uid/gid instead of usernames check-in: a48ac76ac7 user: rkeene tags: trunk
2012-09-15
06:53
Removed unneeded casts check-in: 413d9011a9 user: rkeene tags: trunk
Changes

Modified initrd/admin-tclkit/kitcreator-modules/system/system.c from [2a84d834a9] to [9210e80361].

  1876   1876   	}
  1877   1877   
  1878   1878   	return(retval);
  1879   1879   }
  1880   1880   
  1881   1881   static int tclsystem_tsmf_start_svc(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
  1882   1882   	struct timeval select_timeout;
  1883         -	Tcl_WideInt umask_val, timeout_val;
  1884         -	Tcl_Obj *filename_obj, *env_obj, *logfile_obj, **env_entry_objv, *cwd_obj, *umask_obj, *user_obj, *group_obj;
         1883  +	Tcl_WideInt umask_val, timeout_val, uid_val, gid_val;
         1884  +	Tcl_Obj *filename_obj, *env_obj, *logfile_obj, **env_entry_objv, *cwd_obj, *umask_obj, *uid_obj, *gid_obj;
  1885   1885   	Tcl_Obj *sri_obj, *timeout_obj;
  1886   1886   	pid_t child, child_pgid = -1, waitpid_ret;
  1887   1887   	ssize_t read_ret;
  1888   1888   	time_t currtime;
  1889   1889   	char *argv[3], *envv[512];
  1890         -	char *logfile, *filename, *cwd, *user, *group;
         1890  +	char *logfile, *filename, *cwd;
  1891   1891   	char logmsg[2048];
  1892   1892   	fd_set read_fdset;
  1893   1893   	int pipe_ret, setsid_ret, execve_ret, tcl_ret, select_ret, chdir_ret;
  1894   1894   	int null_fd, log_fd, tmp_fd, max_fd;
  1895   1895   	int env_entry_objc;
  1896   1896   	int fds[2], fd;
  1897   1897   	int status;
  1898   1898   	int idx;
  1899   1899   
  1900   1900   	/* 1. Parse arguments */
  1901   1901   	/* 1.a. Ensure the correct number of arguments were passed */
  1902   1902   	if (objc != 10) {
  1903         -		Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args: should be \"::system::syscall::tsmf_start_svc sri filename logfile env cwd umask user group timeout\"", -1));
         1903  +		Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args: should be \"::system::syscall::tsmf_start_svc sri filename logfile env cwd umask uid gid timeout\"", -1));
  1904   1904   
  1905   1905   		return(TCL_ERROR);
  1906   1906   	}
  1907   1907   
  1908   1908   	/* 1.b. Identify Tcl_Objs to use for each argument */
  1909   1909   	sri_obj = objv[1];
  1910   1910   	filename_obj = objv[2];
  1911   1911   	logfile_obj = objv[3];
  1912   1912   	env_obj = objv[4];
  1913   1913   	cwd_obj = objv[5];
  1914   1914   	umask_obj = objv[6];
  1915         -	user_obj = objv[7];
  1916         -	group_obj = objv[8];
         1915  +	uid_obj = objv[7];
         1916  +	gid_obj = objv[8];
  1917   1917   	timeout_obj = objv[9];
  1918   1918   
  1919   1919   	/* 1.c. Store string arguments */
  1920   1920   	filename = Tcl_GetString(filename_obj);
  1921   1921   	logfile = Tcl_GetString(logfile_obj);
  1922   1922   	cwd = Tcl_GetString(cwd_obj);
  1923         -	user = Tcl_GetString(user_obj);
  1924         -	group = Tcl_GetString(group_obj);
  1925   1923   
  1926   1924   	/* 1.d. Integer objects */
  1927   1925   	tcl_ret = Tcl_GetWideIntFromObj(interp, umask_obj, &umask_val);
  1928   1926   	if (tcl_ret != TCL_OK) {
  1929   1927   		return(tcl_ret);
  1930   1928   	}
  1931   1929   
  1932   1930   	tcl_ret = Tcl_GetWideIntFromObj(interp, timeout_obj, &timeout_val);
  1933   1931   	if (tcl_ret != TCL_OK) {
  1934   1932   		return(tcl_ret);
  1935   1933   	}
         1934  +
         1935  +	tcl_ret = Tcl_GetWideIntFromObj(interp, uid_obj, &uid_val);
         1936  +	if (tcl_ret != TCL_OK) {
         1937  +		return(tcl_ret);
         1938  +	}
         1939  +
         1940  +	tcl_ret = Tcl_GetWideIntFromObj(interp, gid_obj, &gid_val);
         1941  +	if (tcl_ret != TCL_OK) {
         1942  +		return(tcl_ret);
         1943  +	}
  1936   1944   
  1937   1945   	/* 1.e. Process environment */
  1938   1946   	tcl_ret = Tcl_ListObjGetElements(interp, env_obj, &env_entry_objc, &env_entry_objv);
  1939   1947   	if (tcl_ret != TCL_OK) {
  1940   1948   		return(tcl_ret);
  1941   1949   	}
  1942   1950   
................................................................................
  2069   2077   		}
  2070   2078   
  2071   2079   		close(tmp_fd);
  2072   2080   	}
  2073   2081   
  2074   2082   	/* 6.g. Switch to appropriate user/group */
  2075   2083   	/* 6.g.i. Group */
  2076         -	/* XXX: TODO */
         2084  +	setgid(gid_val);
  2077   2085   
  2078   2086   	/* 6.g.ii. User */
  2079         -	/* XXX: TODO */
         2087  +	setuid(uid_val);
  2080   2088   
  2081   2089   	/* 7. Create a new process to actually spawn the process */
  2082   2090   	child = fork();
  2083   2091   	if (child == -1) {
  2084   2092   		write(fd, &child_pgid, sizeof(child_pgid));
  2085   2093   
  2086   2094   		_exit(0);