- Timestamp:
- May 8, 2020 2:08:23 PM (5 years ago)
- Location:
- trunk/src/VBox/Additions/common
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestCtrl.cpp
r84198 r84215 36 36 #include <VBox/err.h> 37 37 #include <VBox/log.h> 38 #include <VBox/GuestHost/GuestControl.h> 38 39 #include <VBox/HostServices/GuestControlSvc.h> 39 40 … … 718 719 } 719 720 721 /** 722 * Initializes a session startup info, extended version. 723 * 724 * @returns VBox status code. 725 * @param pStartupInfo Session startup info to initializes. 726 * @param cbUser Size (in bytes) to use for the user name buffer. 727 * @param cbPassword Size (in bytes) to use for the password buffer. 728 * @param cbDomain Size (in bytes) to use for the domain name buffer. 729 */ 730 VBGLR3DECL(int) VbglR3GuestCtrlSessionStartupInfoInitEx(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo, 731 size_t cbUser, size_t cbPassword, size_t cbDomain) 732 { 733 AssertPtrReturn(pStartupInfo, VERR_INVALID_POINTER); 734 735 RT_BZERO(pStartupInfo, sizeof(VBGLR3GUESTCTRLSESSIONSTARTUPINFO)); 736 737 #define ALLOC_STR(a_Str, a_cb) \ 738 if ((a_cb) > 0) \ 739 { \ 740 pStartupInfo->psz##a_Str = RTStrAlloc(a_cb); \ 741 AssertPtrBreak(pStartupInfo->psz##a_Str); \ 742 pStartupInfo->cb##a_Str = (uint32_t)a_cb; \ 743 } 744 745 do 746 { 747 ALLOC_STR(User, cbUser); 748 ALLOC_STR(Password, cbPassword); 749 ALLOC_STR(Domain, cbDomain); 750 751 return VINF_SUCCESS; 752 753 } while (0); 754 755 #undef ALLOC_STR 756 757 VbglR3GuestCtrlSessionStartupInfoDestroy(pStartupInfo); 758 return VERR_NO_MEMORY; 759 } 760 761 /** 762 * Initializes a session startup info. 763 * 764 * @returns VBox status code. 765 * @param pStartupInfo Session startup info to initializes. 766 */ 767 VBGLR3DECL(int) VbglR3GuestCtrlSessionStartupInfoInit(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo) 768 { 769 return VbglR3GuestCtrlSessionStartupInfoInitEx(pStartupInfo, 770 GUESTPROCESS_MAX_USER_LEN, GUESTPROCESS_MAX_PASSWORD_LEN, 771 GUESTPROCESS_MAX_DOMAIN_LEN); 772 } 773 774 /** 775 * Destroys a session startup info. 776 * 777 * @param pStartupInfo Session startup info to destroy. 778 */ 779 VBGLR3DECL(void) VbglR3GuestCtrlSessionStartupInfoDestroy(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo) 780 { 781 if (!pStartupInfo) 782 return; 783 784 RTStrFree(pStartupInfo->pszUser); 785 RTStrFree(pStartupInfo->pszPassword); 786 RTStrFree(pStartupInfo->pszDomain); 787 788 RT_BZERO(pStartupInfo, sizeof(VBGLR3GUESTCTRLSESSIONSTARTUPINFO)); 789 } 790 791 /** 792 * Free's a session startup info. 793 * 794 * @param pStartupInfo Session startup info to free. 795 * The pointer will not be valid anymore after return. 796 */ 797 VBGLR3DECL(void) VbglR3GuestCtrlSessionStartupInfoFree(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo) 798 { 799 if (!pStartupInfo) 800 return; 801 802 VbglR3GuestCtrlSessionStartupInfoDestroy(pStartupInfo); 803 804 RTMemFree(pStartupInfo); 805 pStartupInfo = NULL; 806 } 807 808 /** 809 * Duplicates a session startup info. 810 * 811 * @returns Duplicated session startup info on success, or NULL on error. 812 * @param pStartupInfo Session startup info to duplicate. 813 */ 814 VBGLR3DECL(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO) VbglR3GuestCtrlSessionStartupInfoDup(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo) 815 { 816 AssertPtrReturn(pStartupInfo, NULL); 817 818 PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfoDup = (PVBGLR3GUESTCTRLSESSIONSTARTUPINFO) 819 RTMemDup(pStartupInfo, sizeof(VBGLR3GUESTCTRLSESSIONSTARTUPINFO)); 820 if (pStartupInfoDup) 821 { 822 do 823 { 824 pStartupInfoDup->pszUser = NULL; 825 pStartupInfoDup->pszPassword = NULL; 826 pStartupInfoDup->pszDomain = NULL; 827 828 #define DUP_STR(a_Str) \ 829 if (pStartupInfo->cb##a_Str) \ 830 { \ 831 pStartupInfoDup->psz##a_Str = (char *)RTStrDup(pStartupInfo->psz##a_Str); \ 832 AssertPtrBreak(pStartupInfoDup->psz##a_Str); \ 833 pStartupInfoDup->cb##a_Str = strlen(pStartupInfoDup->psz##a_Str) + 1 /* Include terminator */; \ 834 } 835 DUP_STR(User); 836 DUP_STR(Password); 837 DUP_STR(Domain); 838 839 #undef DUP_STR 840 841 return pStartupInfoDup; 842 843 } while (0); /* To use break macros above. */ 844 845 VbglR3GuestCtrlSessionStartupInfoFree(pStartupInfoDup); 846 } 847 848 return NULL; 849 } 720 850 721 851 /** 722 852 * Retrieves a HOST_SESSION_CREATE message. 723 * /724 VBGLR3DECL(int) VbglR3GuestCtrlSessionGetOpen(PVBGLR3GUESTCTRLCMDCTX pCtx, 725 uint32_t *puProtocol,726 char *pszUser, uint32_t cbUser,727 char *pszPassword, uint32_t cbPassword,728 char *pszDomain, uint32_t cbDomain,729 uint32_t *pfFlags, uint32_t *pidSession)853 * 854 * @returns VBox status code. 855 * @param pCtx Guest control command context to use. 856 * @param ppStartupInfo Where to store the allocated session startup info. 857 * Needs to be free'd by VbglR3GuestCtrlSessionStartupInfoFree(). 858 */ 859 VBGLR3DECL(int) VbglR3GuestCtrlSessionGetOpen(PVBGLR3GUESTCTRLCMDCTX pCtx, PVBGLR3GUESTCTRLSESSIONSTARTUPINFO *ppStartupInfo) 730 860 { 731 861 AssertPtrReturn(pCtx, VERR_INVALID_POINTER); 732 862 AssertReturn(pCtx->uNumParms == 6, VERR_INVALID_PARAMETER); 733 734 AssertPtrReturn(puProtocol, VERR_INVALID_POINTER); 735 AssertPtrReturn(pszUser, VERR_INVALID_POINTER); 736 AssertPtrReturn(pszPassword, VERR_INVALID_POINTER); 737 AssertPtrReturn(pszDomain, VERR_INVALID_POINTER); 738 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER); 739 740 int rc; 863 AssertPtrReturn(ppStartupInfo, VERR_INVALID_POINTER); 864 865 PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo 866 = (PVBGLR3GUESTCTRLSESSIONSTARTUPINFO)RTMemAlloc(sizeof(VBGLR3GUESTCTRLSESSIONSTARTUPINFO)); 867 if (!pStartupInfo) 868 return VERR_NO_MEMORY; 869 870 int rc = VbglR3GuestCtrlSessionStartupInfoInit(pStartupInfo); 871 if (RT_FAILURE(rc)) 872 { 873 VbglR3GuestCtrlSessionStartupInfoFree(pStartupInfo); 874 return rc; 875 } 876 741 877 do 742 878 { … … 745 881 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_SESSION_CREATE); 746 882 VbglHGCMParmUInt32Set(&Msg.protocol, 0); 747 VbglHGCMParmPtrSet(&Msg.username, p szUser,cbUser);748 VbglHGCMParmPtrSet(&Msg.password, p szPassword,cbPassword);749 VbglHGCMParmPtrSet(&Msg.domain, p szDomain,cbDomain);883 VbglHGCMParmPtrSet(&Msg.username, pStartupInfo->pszUser, pStartupInfo->cbUser); 884 VbglHGCMParmPtrSet(&Msg.password, pStartupInfo->pszPassword, pStartupInfo->cbPassword); 885 VbglHGCMParmPtrSet(&Msg.domain, pStartupInfo->pszDomain, pStartupInfo->cbDomain); 750 886 VbglHGCMParmUInt32Set(&Msg.flags, 0); 751 887 … … 754 890 { 755 891 Msg.context.GetUInt32(&pCtx->uContextID); 756 Msg.protocol.GetUInt32(puProtocol); 757 Msg.flags.GetUInt32(pfFlags); 758 759 if (pidSession) 760 *pidSession = VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pCtx->uContextID); 892 Msg.protocol.GetUInt32(&pStartupInfo->uProtocol); 893 Msg.flags.GetUInt32(&pStartupInfo->fFlags); 894 895 pStartupInfo->uSessionID = VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pCtx->uContextID); 761 896 } 762 897 763 898 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel); 899 900 if (RT_SUCCESS(rc)) 901 { 902 *ppStartupInfo = pStartupInfo; 903 } 904 else 905 VbglR3GuestCtrlSessionStartupInfoFree(pStartupInfo); 906 907 LogFlowFuncLeaveRC(rc); 764 908 return rc; 765 909 } … … 882 1026 } 883 1027 1028 /** 1029 * Initializes a process startup info, extended version. 1030 * 1031 * @returns VBox status code. 1032 * @param pStartupInfo Process startup info to initializes. 1033 * @param cbCmd Size (in bytes) to use for the command buffer. 1034 * @param cbUser Size (in bytes) to use for the user name buffer. 1035 * @param cbPassword Size (in bytes) to use for the password buffer. 1036 * @param cbDomain Size (in bytes) to use for the domain buffer. 1037 * @param cbArgs Size (in bytes) to use for the arguments buffer. 1038 * @param cbEnv Size (in bytes) to use for the environment buffer. 1039 */ 1040 VBGLR3DECL(int) VbglR3GuestCtrlProcStartupInfoInitEx(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo, 1041 size_t cbCmd, 1042 size_t cbUser, size_t cbPassword, size_t cbDomain, 1043 size_t cbArgs, size_t cbEnv) 1044 { 1045 AssertPtrReturn(pStartupInfo, VERR_INVALID_POINTER); 1046 AssertReturn(cbCmd, VERR_INVALID_PARAMETER); 1047 AssertReturn(cbUser, VERR_INVALID_PARAMETER); 1048 AssertReturn(cbPassword, VERR_INVALID_PARAMETER); 1049 AssertReturn(cbDomain, VERR_INVALID_PARAMETER); 1050 AssertReturn(cbArgs, VERR_INVALID_PARAMETER); 1051 AssertReturn(cbEnv, VERR_INVALID_PARAMETER); 1052 1053 RT_BZERO(pStartupInfo, sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO)); 1054 1055 #define ALLOC_STR(a_Str, a_cb) \ 1056 if ((a_cb) > 0) \ 1057 { \ 1058 pStartupInfo->psz##a_Str = RTStrAlloc(a_cb); \ 1059 AssertPtrBreak(pStartupInfo->psz##a_Str); \ 1060 pStartupInfo->cb##a_Str = (uint32_t)a_cb; \ 1061 } 1062 1063 do 1064 { 1065 ALLOC_STR(Cmd, cbCmd); 1066 ALLOC_STR(Args, cbArgs); 1067 ALLOC_STR(Env, cbEnv); 1068 ALLOC_STR(User, cbUser); 1069 ALLOC_STR(Password, cbPassword); 1070 ALLOC_STR(Domain, cbDomain); 1071 1072 return VINF_SUCCESS; 1073 1074 } while (0); 1075 1076 #undef ALLOC_STR 1077 1078 VbglR3GuestCtrlProcStartupInfoDestroy(pStartupInfo); 1079 return VERR_NO_MEMORY; 1080 } 1081 1082 /** 1083 * Initializes a process startup info with default values. 1084 * 1085 * @param pStartupInfo Process startup info to initializes. 1086 */ 1087 VBGLR3DECL(int) VbglR3GuestCtrlProcStartupInfoInit(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo) 1088 { 1089 return VbglR3GuestCtrlProcStartupInfoInitEx(pStartupInfo, 1090 GUESTPROCESS_MAX_CMD_LEN, 1091 GUESTPROCESS_MAX_USER_LEN, GUESTPROCESS_MAX_PASSWORD_LEN, 1092 GUESTPROCESS_MAX_DOMAIN_LEN, 1093 GUESTPROCESS_MAX_ARGS_LEN, GUESTPROCESS_MAX_ENV_LEN); 1094 } 1095 1096 /** 1097 * Destroys a process startup info. 1098 * 1099 * @param pStartupInfo Process startup info to destroy. 1100 */ 1101 VBGLR3DECL(void) VbglR3GuestCtrlProcStartupInfoDestroy(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo) 1102 { 1103 if (!pStartupInfo) 1104 return; 1105 1106 RTStrFree(pStartupInfo->pszCmd); 1107 RTStrFree(pStartupInfo->pszArgs); 1108 RTStrFree(pStartupInfo->pszEnv); 1109 RTStrFree(pStartupInfo->pszUser); 1110 RTStrFree(pStartupInfo->pszPassword); 1111 RTStrFree(pStartupInfo->pszDomain); 1112 1113 RT_BZERO(pStartupInfo, sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO)); 1114 } 1115 1116 /** 1117 * Free's a process startup info. 1118 * 1119 * @param pStartupInfo Process startup info to free. 1120 * The pointer will not be valid anymore after return. 1121 */ 1122 VBGLR3DECL(void) VbglR3GuestCtrlProcStartupInfoFree(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo) 1123 { 1124 if (!pStartupInfo) 1125 return; 1126 1127 VbglR3GuestCtrlProcStartupInfoDestroy(pStartupInfo); 1128 1129 RTMemFree(pStartupInfo); 1130 pStartupInfo = NULL; 1131 } 1132 1133 /** 1134 * Duplicates a process startup info. 1135 * 1136 * @returns Duplicated process startup info on success, or NULL on error. 1137 * @param pStartupInfo Process startup info to duplicate. 1138 */ 1139 VBGLR3DECL(PVBGLR3GUESTCTRLPROCSTARTUPINFO) VbglR3GuestCtrlProcStartupInfoDup(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo) 1140 { 1141 AssertPtrReturn(pStartupInfo, NULL); 1142 1143 PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfoDup = (PVBGLR3GUESTCTRLPROCSTARTUPINFO) 1144 RTMemDup(pStartupInfo, sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO)); 1145 if (pStartupInfoDup) 1146 { 1147 do 1148 { 1149 pStartupInfoDup->pszCmd = NULL; 1150 pStartupInfoDup->pszArgs = NULL; 1151 pStartupInfoDup->pszEnv = NULL; 1152 pStartupInfoDup->pszUser = NULL; 1153 pStartupInfoDup->pszPassword = NULL; 1154 pStartupInfoDup->pszDomain = NULL; 1155 1156 #define DUP_STR(a_Str) \ 1157 if (pStartupInfo->cb##a_Str) \ 1158 { \ 1159 pStartupInfoDup->psz##a_Str = (char *)RTStrDup(pStartupInfo->psz##a_Str); \ 1160 AssertPtrBreak(pStartupInfoDup->psz##a_Str); \ 1161 pStartupInfoDup->cb##a_Str = (uint32_t)strlen(pStartupInfoDup->psz##a_Str) + 1 /* Include terminator */; \ 1162 } 1163 1164 #define DUP_MEM(a_Str) \ 1165 if (pStartupInfo->cb##a_Str) \ 1166 { \ 1167 pStartupInfoDup->psz##a_Str = (char *)RTMemDup(pStartupInfo->psz##a_Str, pStartupInfo->cb##a_Str); \ 1168 AssertPtrBreak(pStartupInfoDup->psz##a_Str); \ 1169 pStartupInfoDup->cb##a_Str = (uint32_t)pStartupInfo->cb##a_Str; \ 1170 } 1171 1172 DUP_STR(Cmd); 1173 DUP_MEM(Args); 1174 DUP_MEM(Env); 1175 DUP_STR(User); 1176 DUP_STR(Password); 1177 DUP_STR(Domain); 1178 1179 #undef DUP_STR 1180 #undef DUP_MEM 1181 1182 return pStartupInfoDup; 1183 1184 } while (0); /* To use break macros above. */ 1185 1186 VbglR3GuestCtrlProcStartupInfoFree(pStartupInfoDup); 1187 } 1188 1189 return NULL; 1190 } 884 1191 885 1192 /** 886 1193 * Retrieves a HOST_EXEC_CMD message. 887 1194 * 888 * @ todo Move the parameters in an own struct!889 * /890 VBGLR3DECL(int) VbglR3GuestCtrlProcGetStart(PVBGLR3GUESTCTRLCMDCTX pCtx, 891 char *pszCmd, uint32_t cbCmd,892 uint32_t *pfFlags,893 char *pszArgs, uint32_t cbArgs, uint32_t *pcArgs, 894 char *pszEnv, uint32_t *pcbEnv, uint32_t *pcEnvVars, 895 char *pszUser, uint32_t cbUser,896 char *pszPassword, uint32_t cbPassword,897 uint32_t *puTimeoutMS, 898 uint32_t *puPriority,899 uint64_t *puAffinity, uint32_t cbAffinity, uint32_t *pcAffinity)900 { 901 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);902 903 AssertPtrReturn(pszCmd, VERR_INVALID_POINTER);904 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);905 AssertPtrReturn(pszArgs, VERR_INVALID_POINTER);906 AssertPtrReturn(pcArgs, VERR_INVALID_POINTER);907 AssertPtrReturn(pszEnv, VERR_INVALID_POINTER);908 AssertPtrReturn(pcbEnv, VERR_INVALID_POINTER);909 AssertPtrReturn(pcEnvVars, VERR_INVALID_POINTER); 910 AssertPtrReturn(puTimeoutMS, VERR_INVALID_POINTER);911 912 int rc; 1195 * @returns VBox status code. 1196 * @param pCtx Guest control command context to use. 1197 * @param ppStartupInfo Where to store the allocated session startup info. 1198 * Needs to be free'd by VbglR3GuestCtrlProcStartupInfoFree(). 1199 */ 1200 VBGLR3DECL(int) VbglR3GuestCtrlProcGetStart(PVBGLR3GUESTCTRLCMDCTX pCtx, PVBGLR3GUESTCTRLPROCSTARTUPINFO *ppStartupInfo) 1201 { 1202 AssertPtrReturn(pCtx, VERR_INVALID_POINTER); 1203 AssertPtrReturn(ppStartupInfo, VERR_INVALID_POINTER); 1204 1205 PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo 1206 = (PVBGLR3GUESTCTRLPROCSTARTUPINFO)RTMemAlloc(sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO)); 1207 if (!pStartupInfo) 1208 return VERR_NO_MEMORY; 1209 1210 int rc = VbglR3GuestCtrlProcStartupInfoInit(pStartupInfo); 1211 if (RT_FAILURE(rc)) 1212 { 1213 VbglR3GuestCtrlProcStartupInfoFree(pStartupInfo); 1214 return rc; 1215 } 1216 1217 unsigned cRetries = 0; 1218 unsigned cGrowthFactor = 2; 1219 913 1220 do 914 1221 { … … 916 1223 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms); 917 1224 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_CMD); 918 VbglHGCMParmPtrSet(&Msg.cmd, p szCmd,cbCmd);1225 VbglHGCMParmPtrSet(&Msg.cmd, pStartupInfo->pszCmd, pStartupInfo->cbCmd); 919 1226 VbglHGCMParmUInt32Set(&Msg.flags, 0); 920 1227 VbglHGCMParmUInt32Set(&Msg.num_args, 0); 921 VbglHGCMParmPtrSet(&Msg.args, p szArgs,cbArgs);1228 VbglHGCMParmPtrSet(&Msg.args, pStartupInfo->pszArgs, pStartupInfo->cbArgs); 922 1229 VbglHGCMParmUInt32Set(&Msg.num_env, 0); 923 1230 VbglHGCMParmUInt32Set(&Msg.cb_env, 0); 924 VbglHGCMParmPtrSet(&Msg.env, p szEnv, *pcbEnv);1231 VbglHGCMParmPtrSet(&Msg.env, pStartupInfo->pszEnv, pStartupInfo->cbEnv); 925 1232 if (pCtx->uProtocol < 2) 926 1233 { 927 AssertPtrReturn(pszUser, VERR_INVALID_POINTER); 928 AssertReturn(cbUser, VERR_INVALID_PARAMETER); 929 AssertPtrReturn(pszPassword, VERR_INVALID_POINTER); 930 AssertReturn(pszPassword, VERR_INVALID_PARAMETER); 931 932 VbglHGCMParmPtrSet(&Msg.u.v1.username, pszUser, cbUser); 933 VbglHGCMParmPtrSet(&Msg.u.v1.password, pszPassword, cbPassword); 1234 VbglHGCMParmPtrSet(&Msg.u.v1.username, pStartupInfo->pszUser, pStartupInfo->cbUser); 1235 VbglHGCMParmPtrSet(&Msg.u.v1.password, pStartupInfo->pszPassword, pStartupInfo->cbPassword); 934 1236 VbglHGCMParmUInt32Set(&Msg.u.v1.timeout, 0); 935 1237 } 936 1238 else 937 1239 { 938 AssertPtrReturn(puAffinity, VERR_INVALID_POINTER);939 AssertReturn(cbAffinity, VERR_INVALID_PARAMETER);940 941 1240 VbglHGCMParmUInt32Set(&Msg.u.v2.timeout, 0); 942 1241 VbglHGCMParmUInt32Set(&Msg.u.v2.priority, 0); 943 1242 VbglHGCMParmUInt32Set(&Msg.u.v2.num_affinity, 0); 944 VbglHGCMParmPtrSet(&Msg.u.v2.affinity, p uAffinity, cbAffinity);1243 VbglHGCMParmPtrSet(&Msg.u.v2.affinity, pStartupInfo->uAffinity, sizeof(pStartupInfo->uAffinity)); 945 1244 } 946 1245 947 1246 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg)); 948 if (RT_SUCCESS(rc)) 1247 if (RT_FAILURE(rc)) 1248 { 1249 if ( rc == VERR_BUFFER_OVERFLOW 1250 && cRetries++ < 4) 1251 { 1252 #define GROW_STR(a_Str, a_cbMax) \ 1253 pStartupInfo->psz##a_Str = (char *)RTMemRealloc(pStartupInfo->psz##a_Str, \ 1254 RT_MAX(pStartupInfo->cb##a_Str * cGrowthFactor, a_cbMax)); \ 1255 AssertPtrBreakStmt(pStartupInfo->psz##a_Str, VERR_NO_MEMORY); \ 1256 pStartupInfo->cb##a_Str = RT_MAX(pStartupInfo->cb##a_Str * cGrowthFactor, a_cbMax); 1257 1258 GROW_STR(Cmd , GUESTPROCESS_MAX_CMD_LEN); 1259 GROW_STR(Args, GUESTPROCESS_MAX_ARGS_LEN); 1260 GROW_STR(Env, GUESTPROCESS_MAX_ENV_LEN); 1261 1262 #undef GROW_STR 1263 cGrowthFactor *= cGrowthFactor; 1264 } 1265 else 1266 break; 1267 } 1268 else 949 1269 { 950 1270 Msg.context.GetUInt32(&pCtx->uContextID); 951 Msg.flags.GetUInt32( pfFlags);952 Msg.num_args.GetUInt32( pcArgs);953 Msg.num_env.GetUInt32( pcEnvVars);954 Msg.cb_env.GetUInt32( pcbEnv);1271 Msg.flags.GetUInt32(&pStartupInfo->fFlags); 1272 Msg.num_args.GetUInt32(&pStartupInfo->cArgs); 1273 Msg.num_env.GetUInt32(&pStartupInfo->cEnvVars); 1274 Msg.cb_env.GetUInt32(&pStartupInfo->cbEnv); 955 1275 if (pCtx->uProtocol < 2) 956 Msg.u.v1.timeout.GetUInt32( puTimeoutMS);1276 Msg.u.v1.timeout.GetUInt32(&pStartupInfo->uTimeLimitMS); 957 1277 else 958 1278 { 959 Msg.u.v2.timeout.GetUInt32( puTimeoutMS);960 Msg.u.v2.priority.GetUInt32( puPriority);961 Msg.u.v2.num_affinity.GetUInt32( pcAffinity);1279 Msg.u.v2.timeout.GetUInt32(&pStartupInfo->uTimeLimitMS); 1280 Msg.u.v2.priority.GetUInt32(&pStartupInfo->uPriority); 1281 Msg.u.v2.num_affinity.GetUInt32(&pStartupInfo->cAffinity); 962 1282 } 963 1283 } 964 1284 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel); 965 return rc; 966 } 967 1285 1286 if (RT_SUCCESS(rc)) 1287 { 1288 *ppStartupInfo = pStartupInfo; 1289 } 1290 else 1291 VbglR3GuestCtrlProcStartupInfoFree(pStartupInfo); 1292 1293 LogFlowFuncLeaveRC(rc); 1294 return rc; 1295 } 968 1296 969 1297 /** -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp
r84209 r84215 415 415 * Retrieve the message parameters. 416 416 */ 417 VBOXSERVICECTRLSESSIONSTARTUPINFO startupInfo; 418 int rc = VgsvcGstCtrlSessionStartupInfoInit(&startupInfo); 419 if (RT_FAILURE(rc)) 420 return rc; 421 422 rc = VbglR3GuestCtrlSessionGetOpen(pHostCtx, 423 &startupInfo.uProtocol, 424 startupInfo.pszUser, startupInfo.cbUser, 425 startupInfo.pszPassword, startupInfo.cbPassword, 426 startupInfo.pszDomain, startupInfo.cbDomain, 427 &startupInfo.fFlags, &startupInfo.uSessionID); 417 PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo; 418 int rc = VbglR3GuestCtrlSessionGetOpen(pHostCtx, &pStartupInfo); 428 419 if (RT_SUCCESS(rc)) 429 420 { … … 431 422 * Flat out refuse to work with protocol v1 hosts. 432 423 */ 433 if ( startupInfo.uProtocol == 2)434 { 435 pHostCtx->uProtocol = startupInfo.uProtocol;424 if (pStartupInfo->uProtocol == 2) 425 { 426 pHostCtx->uProtocol = pStartupInfo->uProtocol; 436 427 VGSvcVerbose(3, "Client ID=%RU32 now is using protocol %RU32\n", pHostCtx->uClientID, pHostCtx->uProtocol); 437 428 438 429 /** @todo Someone explain why this code isn't in this file too? v1 support? */ 439 rc = VGSvcGstCtrlSessionThreadCreate(&g_lstControlSessionThreads, &startupInfo, NULL /* ppSessionThread */);430 rc = VGSvcGstCtrlSessionThreadCreate(&g_lstControlSessionThreads, pStartupInfo, NULL /* ppSessionThread */); 440 431 /* Report failures to the host (successes are taken care of by the session thread). */ 441 432 } 442 433 else 443 434 { 444 VGSvcError("The host wants to use protocol v%u, we only support v2!\n", startupInfo.uProtocol);435 VGSvcError("The host wants to use protocol v%u, we only support v2!\n", pStartupInfo->uProtocol); 445 436 rc = VERR_VERSION_MISMATCH; 446 437 } … … 458 449 } 459 450 460 VgsvcGstCtrlSessionStartupInfoDestroy(&startupInfo); 451 VbglR3GuestCtrlSessionStartupInfoFree(pStartupInfo); 452 pStartupInfo = NULL; 461 453 462 454 VGSvcVerbose(3, "Opening a new guest session returned rc=%Rrc\n", rc); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.h
r84150 r84215 74 74 typedef VBOXSERVICECTRLFILE *PVBOXSERVICECTRLFILE; 75 75 76 typedef struct VBOXSERVICECTRLSESSIONSTARTUPINFO77 {78 /** The session's protocol version to use. */79 uint32_t uProtocol;80 /** The session's ID. */81 uint32_t uSessionID;82 /** User name (account) to start the guest session under. */83 char *pszUser;84 /** Size (in bytes) of allocated pszUser. */85 uint32_t cbUser;86 /** Password of specified user name (account). */87 char *pszPassword;88 /** Size (in bytes) of allocated pszPassword. */89 uint32_t cbPassword;90 /** Domain of the user account. */91 char *pszDomain;92 /** Size (in bytes) of allocated pszDomain. */93 uint32_t cbDomain;94 /** Session creation flags.95 * @sa VBOXSERVICECTRLSESSIONSTARTUPFLAG_* flags. */96 uint32_t fFlags;97 } VBOXSERVICECTRLSESSIONSTARTUPINFO;98 /** Pointer to thread data. */99 typedef VBOXSERVICECTRLSESSIONSTARTUPINFO *PVBOXSERVICECTRLSESSIONSTARTUPINFO;100 101 76 /** 102 77 * Structure for a guest session thread to … … 110 85 RTLISTNODE Node; 111 86 /** The sessions's startup info. */ 112 PVB OXSERVICECTRLSESSIONSTARTUPINFO87 PVBGLR3GUESTCTRLSESSIONSTARTUPINFO 113 88 pStartupInfo; 114 89 /** Critical section for thread-safe use. */ … … 185 160 { 186 161 /* The session's startup information. */ 187 VB OXSERVICECTRLSESSIONSTARTUPINFO162 VBGLR3GUESTCTRLSESSIONSTARTUPINFO 188 163 StartupInfo; 189 164 /** List of active guest process threads … … 207 182 /** Pointer to guest session. */ 208 183 typedef VBOXSERVICECTRLSESSION *PVBOXSERVICECTRLSESSION; 209 210 /**211 * Structure holding information for starting a guest212 * process.213 */214 typedef struct VBOXSERVICECTRLPROCSTARTUPINFO215 {216 /** Full qualified path of process to start (without arguments).217 * Note: This is *not* argv[0]! */218 char *pszCmd;219 /** Size (in bytes) of allocated pszCmd. */220 uint32_t cbCmd;221 /** Process execution flags. @sa */222 uint32_t fFlags;223 /** Command line arguments. */224 char *pszArgs;225 /** Size (in bytes) of allocated pszArgs. */226 uint32_t cbArgs;227 /** Number of arguments specified in pszArgs. */228 uint32_t cArgs;229 /** String of environment variables ("FOO=BAR") to pass to the process230 * to start. */231 char *pszEnv;232 /** Size (in bytes) of environment variables block. */233 uint32_t cbEnv;234 /** Number of environment variables specified in pszEnv. */235 uint32_t cEnvVars;236 /** User name (account) to start the process under. */237 char *pszUser;238 /** Size (in bytes) of allocated pszUser. */239 uint32_t cbUser;240 /** Password of specified user name (account). */241 char *pszPassword;242 /** Size (in bytes) of allocated pszPassword. */243 uint32_t cbPassword;244 /** Domain to be used for authenticating the specified user name (account). */245 char *pszDomain;246 /** Size (in bytes) of allocated pszDomain. */247 uint32_t cbDomain;248 /** Time limit (in ms) of the process' life time. */249 uint32_t uTimeLimitMS;250 /** Process priority. */251 uint32_t uPriority;252 /** Process affinity. At the moment we support253 * up to 4 * 64 = 256 CPUs. */254 uint64_t uAffinity[4];255 /** Number of used process affinity blocks. */256 uint32_t uNumAffinity;257 } VBOXSERVICECTRLPROCSTARTUPINFO;258 /** Pointer to a guest process block. */259 typedef VBOXSERVICECTRLPROCSTARTUPINFO *PVBOXSERVICECTRLPROCSTARTUPINFO;260 184 261 185 /** … … 287 211 RTCRITSECT CritSect; 288 212 /** Process startup information. */ 289 PVB OXSERVICECTRLPROCSTARTUPINFO213 PVBGLR3GUESTCTRLPROCSTARTUPINFO 290 214 pStartupInfo; 291 215 /** The process' PID assigned by the guest OS. */ … … 328 252 /** @name Guest session thread handling. 329 253 * @{ */ 330 extern int VGSvcGstCtrlSessionThreadCreate(PRTLISTANCHOR pList, const PVB OXSERVICECTRLSESSIONSTARTUPINFO pSessionStartupInfo, PVBOXSERVICECTRLSESSIONTHREAD *ppSessionThread);254 extern int VGSvcGstCtrlSessionThreadCreate(PRTLISTANCHOR pList, const PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pSessionStartupInfo, PVBOXSERVICECTRLSESSIONTHREAD *ppSessionThread); 331 255 extern int VGSvcGstCtrlSessionThreadDestroy(PVBOXSERVICECTRLSESSIONTHREAD pSession, uint32_t uFlags); 332 256 extern int VGSvcGstCtrlSessionThreadDestroyAll(PRTLISTANCHOR pList, uint32_t uFlags); … … 336 260 /** @name Per-session functions. 337 261 * @{ */ 338 extern int VgsvcGstCtrlSessionStartupInfoInit(PVBOXSERVICECTRLSESSIONSTARTUPINFO pStartupInfo);339 extern int VgsvcGstCtrlSessionStartupInfoInitEx(PVBOXSERVICECTRLSESSIONSTARTUPINFO pStartupInfo, size_t cbUser, size_t cbPassword, size_t cbDomain);340 extern void VgsvcGstCtrlSessionStartupInfoDestroy(PVBOXSERVICECTRLSESSIONSTARTUPINFO pStartupInfo);341 342 262 extern PVBOXSERVICECTRLPROCESS VGSvcGstCtrlSessionRetainProcess(PVBOXSERVICECTRLSESSION pSession, uint32_t uPID); 343 263 extern int VGSvcGstCtrlSessionClose(PVBOXSERVICECTRLSESSION pSession); … … 352 272 /** @name Per-guest process functions. 353 273 * @{ */ 354 extern int VgsvcGstCtrlProcessStartupInfoInit(PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo);355 extern int VgsvcGstCtrlProcessStartupInfoInitEx(PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo, size_t cbCmd, size_t cbUser, size_t cbPassword, size_t cbDomain, size_t cbArgs, size_t cbEnv);356 extern void VgsvcGstCtrlProcessStartupInfoDestroy(PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo);357 extern void VgsvcGstCtrlProcessStartupInfoFree(PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo);358 359 274 extern int VGSvcGstCtrlProcessFree(PVBOXSERVICECTRLPROCESS pProcess); 360 275 extern int VGSvcGstCtrlProcessHandleInput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, bool fPendingClose, void *pvBuf, uint32_t cbBuf); … … 362 277 extern int VGSvcGstCtrlProcessHandleTerm(PVBOXSERVICECTRLPROCESS pProcess); 363 278 extern void VGSvcGstCtrlProcessRelease(PVBOXSERVICECTRLPROCESS pProcess); 364 extern int VGSvcGstCtrlProcessStart(const PVBOXSERVICECTRLSESSION pSession, const PVB OXSERVICECTRLPROCSTARTUPINFO pStartupInfo, uint32_t uContext);279 extern int VGSvcGstCtrlProcessStart(const PVBOXSERVICECTRLSESSION pSession, const PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo, uint32_t uContext); 365 280 extern int VGSvcGstCtrlProcessStop(PVBOXSERVICECTRLPROCESS pProcess); 366 281 extern int VGSvcGstCtrlProcessWait(const PVBOXSERVICECTRLPROCESS pProcess, RTMSINTERVAL msTimeout, int *pRc); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlProcess.cpp
r84154 r84215 61 61 62 62 63 /**64 * Initializes a process startup info, extended version.65 *66 * @returns VBox status code.67 * @param pStartupInfo Process startup info to initializes.68 * @param cbCmd Size (in bytes) to use for the command buffer.69 * @param cbUser Size (in bytes) to use for the user name buffer.70 * @param cbPassword Size (in bytes) to use for the password buffer.71 * @param cbDomain Size (in bytes) to use for the domain buffer.72 * @param cbArgs Size (in bytes) to use for the arguments buffer.73 * @param cbEnv Size (in bytes) to use for the environment buffer.74 */75 int VgsvcGstCtrlProcessStartupInfoInitEx(PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo,76 size_t cbCmd,77 size_t cbUser, size_t cbPassword, size_t cbDomain,78 size_t cbArgs, size_t cbEnv)79 {80 AssertPtrReturn(pStartupInfo, VERR_INVALID_POINTER);81 AssertReturn(cbCmd, VERR_INVALID_PARAMETER);82 AssertReturn(cbUser, VERR_INVALID_PARAMETER);83 AssertReturn(cbPassword, VERR_INVALID_PARAMETER);84 AssertReturn(cbDomain, VERR_INVALID_PARAMETER);85 AssertReturn(cbArgs, VERR_INVALID_PARAMETER);86 AssertReturn(cbEnv, VERR_INVALID_PARAMETER);87 88 RT_BZERO(pStartupInfo, sizeof(VBOXSERVICECTRLPROCSTARTUPINFO));89 90 #define ALLOC_STR(a_Str, a_cb) \91 if ((a_cb) > 0) \92 { \93 pStartupInfo->psz##a_Str = RTStrAlloc(a_cb); \94 AssertPtrBreak(pStartupInfo->psz##a_Str); \95 pStartupInfo->cb##a_Str = (uint32_t)a_cb; \96 }97 98 do99 {100 ALLOC_STR(Cmd, cbCmd);101 ALLOC_STR(Args, cbArgs);102 ALLOC_STR(Env, cbEnv);103 ALLOC_STR(User, cbUser);104 ALLOC_STR(Password, cbPassword);105 ALLOC_STR(Domain, cbDomain);106 107 return VINF_SUCCESS;108 109 } while (0);110 111 #undef ALLOC_STR112 113 VgsvcGstCtrlProcessStartupInfoDestroy(pStartupInfo);114 return VERR_NO_MEMORY;115 }116 117 /**118 * Initializes a process startup info with default values.119 *120 * @param pStartupInfo Process startup info to initializes.121 */122 int VgsvcGstCtrlProcessStartupInfoInit(PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo)123 {124 return VgsvcGstCtrlProcessStartupInfoInitEx(pStartupInfo,125 GUESTPROCESS_MAX_CMD_LEN,126 GUESTPROCESS_MAX_USER_LEN, GUESTPROCESS_MAX_PASSWORD_LEN,127 GUESTPROCESS_MAX_DOMAIN_LEN,128 GUESTPROCESS_MAX_ARGS_LEN, GUESTPROCESS_MAX_ENV_LEN);129 }130 131 /**132 * Destroys a process startup info.133 *134 * @param pStartupInfo Process startup info to destroy.135 */136 void VgsvcGstCtrlProcessStartupInfoDestroy(PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo)137 {138 if (!pStartupInfo)139 return;140 141 RTStrFree(pStartupInfo->pszCmd);142 RTStrFree(pStartupInfo->pszArgs);143 RTStrFree(pStartupInfo->pszEnv);144 RTStrFree(pStartupInfo->pszUser);145 RTStrFree(pStartupInfo->pszPassword);146 RTStrFree(pStartupInfo->pszDomain);147 148 RT_BZERO(pStartupInfo, sizeof(VBOXSERVICECTRLPROCSTARTUPINFO));149 }150 151 /**152 * Free's a process startup info.153 *154 * @param pStartupInfo Process startup info to free.155 * The pointer will not be valid anymore after return.156 */157 void VgsvcGstCtrlProcessStartupInfoFree(PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo)158 {159 if (!pStartupInfo)160 return;161 162 VgsvcGstCtrlProcessStartupInfoDestroy(pStartupInfo);163 164 RTMemFree(pStartupInfo);165 pStartupInfo = NULL;166 }167 168 /**169 * Duplicates a process startup info.170 *171 * @returns Duplicated process startup info on success, or NULL on error.172 * @param pStartupInfo Process startup info to duplicate.173 */174 static PVBOXSERVICECTRLPROCSTARTUPINFO vgsvcGstCtrlProcessStartupInfoDup(PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo)175 {176 AssertPtrReturn(pStartupInfo, NULL);177 178 PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfoDup = (PVBOXSERVICECTRLPROCSTARTUPINFO)179 RTMemDup(pStartupInfo, sizeof(VBOXSERVICECTRLPROCSTARTUPINFO));180 if (pStartupInfoDup)181 {182 do183 {184 pStartupInfoDup->pszCmd = NULL;185 pStartupInfoDup->pszArgs = NULL;186 pStartupInfoDup->pszEnv = NULL;187 pStartupInfoDup->pszUser = NULL;188 pStartupInfoDup->pszPassword = NULL;189 pStartupInfoDup->pszDomain = NULL;190 191 #define DUP_STR(a_Str) \192 if (pStartupInfo->cb##a_Str) \193 { \194 pStartupInfoDup->psz##a_Str = (char *)RTStrDup(pStartupInfo->psz##a_Str); \195 AssertPtrBreak(pStartupInfoDup->psz##a_Str); \196 pStartupInfoDup->cb##a_Str = (uint32_t)strlen(pStartupInfoDup->psz##a_Str) + 1 /* Include terminator */; \197 }198 199 #define DUP_MEM(a_Str) \200 if (pStartupInfo->cb##a_Str) \201 { \202 pStartupInfoDup->psz##a_Str = (char *)RTMemDup(pStartupInfo->psz##a_Str, pStartupInfo->cb##a_Str); \203 AssertPtrBreak(pStartupInfoDup->psz##a_Str); \204 pStartupInfoDup->cb##a_Str = (uint32_t)pStartupInfo->cb##a_Str; \205 }206 207 DUP_STR(Cmd);208 DUP_MEM(Args);209 DUP_MEM(Env);210 DUP_STR(User);211 DUP_STR(Password);212 DUP_STR(Domain);213 214 #undef DUP_STR215 #undef DUP_MEM216 217 return pStartupInfoDup;218 219 } while (0); /* To use break macros above. */220 221 VgsvcGstCtrlProcessStartupInfoFree(pStartupInfoDup);222 }223 224 return NULL;225 }226 63 227 64 /** … … 236 73 static int vgsvcGstCtrlProcessInit(PVBOXSERVICECTRLPROCESS pProcess, 237 74 const PVBOXSERVICECTRLSESSION pSession, 238 const PVB OXSERVICECTRLPROCSTARTUPINFO pStartupInfo,75 const PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo, 239 76 uint32_t u32ContextID) 240 77 { … … 282 119 283 120 /* Duplicate startup info. */ 284 pProcess->pStartupInfo = vgsvcGstCtrlProcessStartupInfoDup(pStartupInfo);121 pProcess->pStartupInfo = VbglR3GuestCtrlProcStartupInfoDup(pStartupInfo); 285 122 AssertPtrReturn(pProcess->pStartupInfo, VERR_NO_MEMORY); 286 123 … … 317 154 AssertReturn(pProcess->fShutdown, VERR_WRONG_ORDER); 318 155 319 V gsvcGstCtrlProcessStartupInfoFree(pProcess->pStartupInfo);156 VbglR3GuestCtrlProcStartupInfoFree(pProcess->pStartupInfo); 320 157 pProcess->pStartupInfo = NULL; 321 158 … … 1991 1828 */ 1992 1829 int VGSvcGstCtrlProcessStart(const PVBOXSERVICECTRLSESSION pSession, 1993 const PVB OXSERVICECTRLPROCSTARTUPINFO pStartupInfo, uint32_t uContextID)1830 const PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo, uint32_t uContextID) 1994 1831 { 1995 1832 AssertPtrReturn(pSession, VERR_INVALID_POINTER); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp
r84209 r84215 1035 1035 1036 1036 /** 1037 * Initializes a session startup info, extended version.1038 *1039 * @returns VBox status code.1040 * @param pStartupInfo Session startup info to initializes.1041 * @param cbUser Size (in bytes) to use for the user name buffer.1042 * @param cbPassword Size (in bytes) to use for the password buffer.1043 * @param cbDomain Size (in bytes) to use for the domain name buffer.1044 */1045 int VgsvcGstCtrlSessionStartupInfoInitEx(PVBOXSERVICECTRLSESSIONSTARTUPINFO pStartupInfo,1046 size_t cbUser, size_t cbPassword, size_t cbDomain)1047 {1048 AssertPtrReturn(pStartupInfo, VERR_INVALID_POINTER);1049 1050 RT_BZERO(pStartupInfo, sizeof(VBOXSERVICECTRLSESSIONSTARTUPINFO));1051 1052 #define ALLOC_STR(a_Str, a_cb) \1053 if ((a_cb) > 0) \1054 { \1055 pStartupInfo->psz##a_Str = RTStrAlloc(a_cb); \1056 AssertPtrBreak(pStartupInfo->psz##a_Str); \1057 AssertBreak((uint32_t)a_cb == a_cb); \1058 pStartupInfo->cb##a_Str = (uint32_t)a_cb; \1059 }1060 1061 do1062 {1063 ALLOC_STR(User, cbUser);1064 ALLOC_STR(Password, cbPassword);1065 ALLOC_STR(Domain, cbDomain);1066 1067 return VINF_SUCCESS;1068 1069 } while (0);1070 1071 #undef ALLOC_STR1072 1073 VgsvcGstCtrlSessionStartupInfoDestroy(pStartupInfo);1074 return VERR_NO_MEMORY;1075 }1076 1077 /**1078 * Initializes a session startup info.1079 *1080 * @returns VBox status code.1081 * @param pStartupInfo Session startup info to initializes.1082 */1083 int VgsvcGstCtrlSessionStartupInfoInit(PVBOXSERVICECTRLSESSIONSTARTUPINFO pStartupInfo)1084 {1085 return VgsvcGstCtrlSessionStartupInfoInitEx(pStartupInfo,1086 GUESTPROCESS_MAX_USER_LEN, GUESTPROCESS_MAX_PASSWORD_LEN,1087 GUESTPROCESS_MAX_DOMAIN_LEN);1088 }1089 1090 /**1091 * Destroys a session startup info.1092 *1093 * @param pStartupInfo Session startup info to destroy.1094 */1095 void VgsvcGstCtrlSessionStartupInfoDestroy(PVBOXSERVICECTRLSESSIONSTARTUPINFO pStartupInfo)1096 {1097 if (!pStartupInfo)1098 return;1099 1100 RTStrFree(pStartupInfo->pszUser);1101 RTStrFree(pStartupInfo->pszPassword);1102 RTStrFree(pStartupInfo->pszDomain);1103 1104 RT_BZERO(pStartupInfo, sizeof(VBOXSERVICECTRLSESSIONSTARTUPINFO));1105 }1106 1107 /**1108 * Free's a session startup info.1109 *1110 * @param pStartupInfo Session startup info to free.1111 * The pointer will not be valid anymore after return.1112 */1113 static void vgsvcGstCtrlSessionStartupInfoFree(PVBOXSERVICECTRLSESSIONSTARTUPINFO pStartupInfo)1114 {1115 if (!pStartupInfo)1116 return;1117 1118 VgsvcGstCtrlSessionStartupInfoDestroy(pStartupInfo);1119 1120 RTMemFree(pStartupInfo);1121 pStartupInfo = NULL;1122 }1123 1124 /**1125 * Duplicates a session startup info.1126 *1127 * @returns Duplicated session startup info on success, or NULL on error.1128 * @param pStartupInfo Session startup info to duplicate.1129 */1130 static PVBOXSERVICECTRLSESSIONSTARTUPINFO vgsvcGstCtrlSessionStartupInfoDup(PVBOXSERVICECTRLSESSIONSTARTUPINFO pStartupInfo)1131 {1132 AssertPtrReturn(pStartupInfo, NULL);1133 1134 PVBOXSERVICECTRLSESSIONSTARTUPINFO pStartupInfoDup = (PVBOXSERVICECTRLSESSIONSTARTUPINFO)1135 RTMemDup(pStartupInfo, sizeof(VBOXSERVICECTRLSESSIONSTARTUPINFO));1136 if (pStartupInfoDup)1137 {1138 do1139 {1140 pStartupInfoDup->pszUser = NULL;1141 pStartupInfoDup->pszPassword = NULL;1142 pStartupInfoDup->pszDomain = NULL;1143 1144 #define DUP_STR(a_Str) \1145 if (pStartupInfo->cb##a_Str) \1146 { \1147 pStartupInfoDup->psz##a_Str = (char *)RTStrDup(pStartupInfo->psz##a_Str); \1148 AssertPtrBreak(pStartupInfoDup->psz##a_Str); \1149 size_t cbStr = strlen(pStartupInfoDup->psz##a_Str) + 1 /* Include terminator */; \1150 AssertBreak((uint32_t)cbStr == cbStr); \1151 pStartupInfoDup->cb##a_Str = (uint32_t)cbStr; \1152 }1153 DUP_STR(User);1154 DUP_STR(Password);1155 DUP_STR(Domain);1156 1157 #undef DUP_STR1158 1159 return pStartupInfoDup;1160 1161 } while (0); /* To use break macros above. */1162 1163 vgsvcGstCtrlSessionStartupInfoFree(pStartupInfoDup);1164 }1165 1166 return NULL;1167 }1168 1169 /**1170 1037 * Handles starting a guest processes. 1171 1038 * … … 1184 1051 * parameter to retrieve the stuff from the host. On output this then 1185 1052 * will contain the actual block size. */ 1186 VBOXSERVICECTRLPROCSTARTUPINFO startupInfo; 1187 int rc = VgsvcGstCtrlProcessStartupInfoInit(&startupInfo); 1188 if (RT_FAILURE(rc)) 1189 return rc; 1190 1191 rc = VbglR3GuestCtrlProcGetStart(pHostCtx, 1192 /* Command */ 1193 startupInfo.pszCmd, startupInfo.cbCmd, 1194 /* Flags */ 1195 &startupInfo.fFlags, 1196 /* Arguments */ 1197 startupInfo.pszArgs, startupInfo.cbArgs, &startupInfo.cArgs, 1198 /* Environment */ 1199 startupInfo.pszEnv, &startupInfo.cbEnv, &startupInfo.cEnvVars, 1200 /* Credentials; for hosts with VBox < 4.3 (protocol version 1). 1201 * For protocol v2 and up the credentials are part of the session 1202 * opening call. */ 1203 startupInfo.pszUser, startupInfo.cbUser, 1204 startupInfo.pszPassword, startupInfo.cbPassword, 1205 /* Timeout (in ms) */ 1206 &startupInfo.uTimeLimitMS, 1207 /* Process priority */ 1208 &startupInfo.uPriority, 1209 /* Process affinity */ 1210 startupInfo.uAffinity, sizeof(startupInfo.uAffinity), &startupInfo.uNumAffinity); 1053 PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo; 1054 int rc = VbglR3GuestCtrlProcGetStart(pHostCtx, &pStartupInfo); 1211 1055 if (RT_SUCCESS(rc)) 1212 1056 { 1213 1057 VGSvcVerbose(3, "Request to start process szCmd=%s, fFlags=0x%x, szArgs=%s, szEnv=%s, uTimeout=%RU32\n", 1214 startupInfo.pszCmd, startupInfo.fFlags,1215 startupInfo.cArgs ? startupInfo.pszArgs : "<None>",1216 startupInfo.cEnvVars ? startupInfo.pszEnv: "<None>",1217 startupInfo.uTimeLimitMS);1058 pStartupInfo->pszCmd, pStartupInfo->fFlags, 1059 pStartupInfo->cArgs ? pStartupInfo->pszArgs : "<None>", 1060 pStartupInfo->cEnvVars ? pStartupInfo->pszEnv : "<None>", 1061 pStartupInfo->uTimeLimitMS); 1218 1062 1219 1063 bool fStartAllowed = false; /* Flag indicating whether starting a process is allowed or not. */ … … 1224 1068 1225 1069 if (fStartAllowed) 1226 rc = VGSvcGstCtrlProcessStart(pSession, &startupInfo, pHostCtx->uContextID);1070 rc = VGSvcGstCtrlProcessStart(pSession, pStartupInfo, pHostCtx->uContextID); 1227 1071 else 1228 1072 rc = VERR_MAX_PROCS_REACHED; /* Maximum number of processes reached. */ … … 1238 1082 VGSvcError("Error sending start process status to host, rc=%Rrc\n", rc2); 1239 1083 } 1084 1085 VbglR3GuestCtrlProcStartupInfoFree(pStartupInfo); 1086 pStartupInfo = NULL; 1240 1087 } 1241 1088 else … … 1244 1091 VbglR3GuestCtrlMsgSkip(pHostCtx->uClientID, rc, UINT32_MAX); 1245 1092 } 1246 1247 VgsvcGstCtrlProcessStartupInfoDestroy(&startupInfo);1248 1093 1249 1094 return rc; … … 2350 2195 * @param uCtrlSessionThread The session thread debug ordinal. 2351 2196 */ 2352 static int vgsvcVGSvcGstCtrlSessionThreadCreateProcess(const PVB OXSERVICECTRLSESSIONSTARTUPINFO pSessionStartupInfo,2197 static int vgsvcVGSvcGstCtrlSessionThreadCreateProcess(const PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pSessionStartupInfo, 2353 2198 PVBOXSERVICECTRLSESSIONTHREAD pSessionThread, uint32_t uCtrlSessionThread) 2354 2199 { … … 2579 2424 * Optional. 2580 2425 */ 2581 int VGSvcGstCtrlSessionThreadCreate(PRTLISTANCHOR pList, const PVB OXSERVICECTRLSESSIONSTARTUPINFO pSessionStartupInfo,2426 int VGSvcGstCtrlSessionThreadCreate(PRTLISTANCHOR pList, const PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pSessionStartupInfo, 2582 2427 PVBOXSERVICECTRLSESSIONTHREAD *ppSessionThread) 2583 2428 { … … 2617 2462 2618 2463 /* Duplicate startup info. */ 2619 pSessionThread->pStartupInfo = vgsvcGstCtrlSessionStartupInfoDup(pSessionStartupInfo);2464 pSessionThread->pStartupInfo = VbglR3GuestCtrlSessionStartupInfoDup(pSessionStartupInfo); 2620 2465 AssertPtrReturn(pSessionThread->pStartupInfo, VERR_NO_MEMORY); 2621 2466 … … 2785 2630 if (RT_SUCCESS(rc)) 2786 2631 { 2787 vgsvcGstCtrlSessionStartupInfoFree(pThread->pStartupInfo);2632 VbglR3GuestCtrlSessionStartupInfoFree(pThread->pStartupInfo); 2788 2633 pThread->pStartupInfo = NULL; 2789 2634
Note:
See TracChangeset
for help on using the changeset viewer.