View | Details | Raw Unified | Return to bug 29499
Collapse All | Expand All

(-)/usr/src/sys/kern/uipc_usrreq.c (-52 / +82 lines)
Lines 897-902 Link Here
897
		}
901
		}
898
		return (EMSGSIZE);
902
		return (EMSGSIZE);
899
	}
903
	}
904
905
#if 0
900
	/*
906
	/*
901
	 * now change each pointer to an fd in the global table to 
907
	 * now change each pointer to an fd in the global table to 
902
	 * an integer that is the index to the local fd table entry
908
	 * an integer that is the index to the local fd table entry
Lines 909-914 Link Here
909
	 * do it in reverse order.
915
	 * do it in reverse order.
910
	 */
916
	 */
911
	if (sizeof (struct file *) >= sizeof (int)) {
917
	if (sizeof (struct file *) >= sizeof (int)) {
918
#endif
912
		fdp = (int *)(cm + 1);
919
		fdp = (int *)(cm + 1);
913
		rp = (struct file **)CMSG_DATA(cm);
920
		rp = (struct file **)CMSG_DATA(cm);
914
		for (i = 0; i < newfds; i++) {
921
		for (i = 0; i < newfds; i++) {
Lines 920-925 Link Here
920
			unp_rights--;
927
			unp_rights--;
921
			*fdp++ = f;
928
			*fdp++ = f;
922
		}
929
		}
930
#if 0
923
	} else {
931
	} else {
924
		fdp = (int *)(cm + 1) + newfds - 1;
932
		fdp = (int *)(cm + 1) + newfds - 1;
925
		rp = (struct file **)CMSG_DATA(cm) + newfds - 1;
933
		rp = (struct file **)CMSG_DATA(cm) + newfds - 1;
Lines 940-945 Link Here
940
	 */
948
	 */
941
	cm->cmsg_len = CMSG_LEN(newfds * sizeof(int));
949
	cm->cmsg_len = CMSG_LEN(newfds * sizeof(int));
942
	rights->m_len = cm->cmsg_len;
950
	rights->m_len = cm->cmsg_len;
951
#endif
943
	return (0);
952
	return (0);
944
}
953
}
945
954
Lines 969-1008 Link Here
969
	register int i, fd, *fdp;
978
	register int i, fd, *fdp;
970
	register struct cmsgcred *cmcred;
979
	register struct cmsgcred *cmcred;
971
	int oldfds;
980
	int oldfds;
972
	u_int newlen;
981
/*	u_int newlen; */
982
	struct cmsghdr *cmend;
973
983
984
#if 0
974
	if ((cm->cmsg_type != SCM_RIGHTS && cm->cmsg_type != SCM_CREDS) ||
985
	if ((cm->cmsg_type != SCM_RIGHTS && cm->cmsg_type != SCM_CREDS) ||
975
	    cm->cmsg_level != SOL_SOCKET || cm->cmsg_len != control->m_len)
986
	    cm->cmsg_level != SOL_SOCKET || cm->cmsg_len != control->m_len) {
987
uprintf("cmsg_type %d, cmsg_level %d, cmsg_len %d, m_len %d\n", cm->cmsg_type, cm->cmsg_level, cm->cmsg_len, control->m_len);
988
		return (EINVAL);
989
	}
990
#else
991
	if (cm->cmsg_level != SOL_SOCKET) {
976
		return (EINVAL);
992
		return (EINVAL);
993
	}
994
#endif
977
995
996
	cmend = (struct cmsghdr *)(((char*)cm) + control->m_len);
997
	for(; cm < cmend;
998
                     cm = (struct cmsghdr *)(((char*)cm)+cm->cmsg_len)) {
978
	/*
999
	/*
979
	 * Fill in credential information.
1000
	 * Fill in credential information.
980
	 */
1001
	 */
981
	if (cm->cmsg_type == SCM_CREDS) {
1002
/*uprintf("cm = %p, cmsg_type = %d\n", cm, cm->cmsg_type);*/
982
		cmcred = (struct cmsgcred *)(cm + 1);
1003
		switch(cm->cmsg_type) {
983
		cmcred->cmcred_pid = p->p_pid;
1004
			case SCM_CREDS:
984
		cmcred->cmcred_uid = p->p_cred->p_ruid;
1005
			    cmcred = (struct cmsgcred *)(cm + 1);
985
		cmcred->cmcred_gid = p->p_cred->p_rgid;
1006
			    cmcred->cmcred_pid = p->p_pid;
986
		cmcred->cmcred_euid = p->p_ucred->cr_uid;
1007
			    cmcred->cmcred_uid = p->p_cred->p_ruid;
987
		cmcred->cmcred_ngroups = MIN(p->p_ucred->cr_ngroups,
1008
			    cmcred->cmcred_gid = p->p_cred->p_rgid;
1009
			    cmcred->cmcred_euid = p->p_ucred->cr_uid;
1010
			    cmcred->cmcred_ngroups = MIN(p->p_ucred->cr_ngroups,
988
							CMGROUP_MAX);
1011
							CMGROUP_MAX);
989
		for (i = 0; i < cmcred->cmcred_ngroups; i++)
1012
			    for (i = 0; i < cmcred->cmcred_ngroups; i++)
990
			cmcred->cmcred_groups[i] = p->p_ucred->cr_groups[i];
1013
				    cmcred->cmcred_groups[i] = p->p_ucred->cr_groups[i];
991
		return(0);
1014
			    break;
992
	}
1015
			case SCM_RIGHTS:
993
1016
994
	oldfds = (cm->cmsg_len - sizeof (*cm)) / sizeof (int);
1017
			oldfds = (cm->cmsg_len - sizeof (*cm)) / sizeof (int);
995
	/*
1018
			/*
996
	 * check that all the FDs passed in refer to legal OPEN files
1019
	 		* check that all the FDs passed in refer to legal OPEN files
997
	 * If not, reject the entire operation.
1020
	 		* If not, reject the entire operation.
998
	 */
1021
	 		*/
999
	fdp = (int *)(cm + 1);
1022
			fdp = (int *)(cm + 1);
1000
	for (i = 0; i < oldfds; i++) {
1023
			for (i = 0; i < oldfds; i++) {
1001
		fd = *fdp++;
1024
				fd = *fdp++;
1002
		if ((unsigned)fd >= fdescp->fd_nfiles ||
1025
				if ((unsigned)fd >= fdescp->fd_nfiles ||
1003
		    fdescp->fd_ofiles[fd] == NULL)
1026
		    		fdescp->fd_ofiles[fd] == NULL)
1004
			return (EBADF);
1027
					return (EBADF);
1005
	}
1028
			}
1029
1030
#if 0
1006
	/*
1031
	/*
1007
	 * Now replace the integer FDs with pointers to
1032
	 * Now replace the integer FDs with pointers to
1008
	 * the associated global file table entry..
1033
	 * the associated global file table entry..
Lines 1010-1015 Link Here
1010
	 * enough, return E2BIG.
1035
	 * enough, return E2BIG.
1011
	 */
1036
	 */
1012
	newlen = CMSG_LEN(oldfds * sizeof(struct file *));
1037
	newlen = CMSG_LEN(oldfds * sizeof(struct file *));
1038
/*uprintf("newlen %d, m_len %d\n", newlen, control->m_len);*/
1013
	if (newlen > MCLBYTES)
1039
	if (newlen > MCLBYTES)
1014
		return (E2BIG);
1040
		return (E2BIG);
1015
	if (newlen - control->m_len > M_TRAILINGSPACE(control)) {
1041
	if (newlen - control->m_len > M_TRAILINGSPACE(control)) {
Lines 1029-1062 Link Here
1029
	 * differs.
1055
	 * differs.
1030
	 */
1056
	 */
1031
	control->m_len = cm->cmsg_len = newlen;
1057
	control->m_len = cm->cmsg_len = newlen;
1058
#endif
1032
1059
1033
	/*
1060
#if 0
1034
	 * Transform the file descriptors into struct file pointers.
1061
			/*
1035
	 * If sizeof (struct file *) is bigger than or equal to sizeof int,
1062
	 		* Transform the file descriptors into struct file pointers.
1036
	 * then do it in reverse order so that the int won't get until
1063
	 		* If sizeof (struct file *) is bigger than or equal to sizeof int,
1037
	 * we're done.
1064
	 		* then do it in reverse order so that the int won't get until
1038
	 * If sizeof (struct file *) is smaller than sizeof int, then
1065
	 		* we're done.
1039
	 * do it in forward order.
1066
	 		* If sizeof (struct file *) is smaller than sizeof int, then
1040
	 */
1067
	 		* do it in forward order.
1041
	if (sizeof (struct file *) >= sizeof (int)) {
1068
	 		*/
1042
		fdp = (int *)(cm + 1) + oldfds - 1;
1069
			if (sizeof (struct file *) >= sizeof (int)) {
1043
		rp = (struct file **)CMSG_DATA(cm) + oldfds - 1;
1070
#endif
1044
		for (i = 0; i < oldfds; i++) {
1071
				fdp = (int *)(cm + 1) + oldfds - 1;
1045
			fp = fdescp->fd_ofiles[*fdp--];
1072
				rp = (struct file **)CMSG_DATA(cm) + oldfds - 1;
1046
			*rp-- = fp;
1073
				for (i = 0; i < oldfds; i++) {
1047
			fp->f_count++;
1074
					fp = fdescp->fd_ofiles[*fdp--];
1048
			fp->f_msgcount++;
1075
					*rp-- = fp;
1049
			unp_rights++;
1076
					fp->f_count++;
1050
		}
1077
					fp->f_msgcount++;
1051
	} else {
1078
					unp_rights++;
1052
		fdp = (int *)(cm + 1);
1079
				}
1053
		rp = (struct file **)CMSG_DATA(cm);
1080
#if 0
1054
		for (i = 0; i < oldfds; i++) {
1081
			} else {
1055
			fp = fdescp->fd_ofiles[*fdp++];
1082
				fdp = (int *)(cm + 1);
1056
			*rp++ = fp;
1083
				rp = (struct file **)CMSG_DATA(cm);
1057
			fp->f_count++;
1084
				for (i = 0; i < oldfds; i++) {
1058
			fp->f_msgcount++;
1085
					fp = fdescp->fd_ofiles[*fdp++];
1059
			unp_rights++;
1086
					*rp++ = fp;
1087
					fp->f_count++;
1088
					fp->f_msgcount++;
1089
					unp_rights++;
1090
				}
1091
			}
1092
#endif
1093
			break;
1060
		}
1094
		}
1061
	}
1095
	}
1062
	return (0);
1096
	return (0);

Return to bug 29499