Changeset 58368 in vbox for trunk/src/VBox
- Timestamp:
- Oct 22, 2015 10:23:35 AM (9 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/Makefile.kmk
r58233 r58368 726 726 VBoxC_SOURCES = \ 727 727 $(VBoxAPIWrap_0_OUTDIR)/VBoxAPI.d \ 728 src-all/AuthLibrary.cpp \ 728 729 src-all/DisplayPNGUtil.cpp \ 729 730 src-all/DisplayResampleImage.cpp \ -
trunk/src/VBox/Main/include/ConsoleVRDPServer.h
r52923 r58368 23 23 #include "HGCM.h" 24 24 25 #include <VBox/VBoxAuth.h>25 #include "AuthLibrary.h" 26 26 27 27 #include <VBox/RemoteDesktop/VRDEImage.h> … … 245 245 #endif /* VBOX_WITH_USB */ 246 246 247 /* External authentication library handle. The library is loaded in the247 /* External authentication library context. The library is loaded in the 248 248 * Authenticate method and unloaded at the object destructor. 249 249 */ 250 RTLDRMOD mAuthLibrary; 251 PAUTHENTRY mpfnAuthEntry; 252 PAUTHENTRY2 mpfnAuthEntry2; 253 PAUTHENTRY3 mpfnAuthEntry3; 250 AUTHLIBRARYCONTEXT mAuthLibCtx; 254 251 255 252 uint32_t volatile mu32AudioInputClientId; -
trunk/src/VBox/Main/src-client/ConsoleVRDPServer.cpp
r56085 r58368 1362 1362 mVRDPBindPort = -1; 1363 1363 1364 mAuthLibrary = 0;1364 RT_ZERO(mAuthLibCtx); 1365 1365 1366 1366 mu32AudioInputClientId = 0; … … 3004 3004 } 3005 3005 3006 mpfnAuthEntry = NULL; 3007 mpfnAuthEntry2 = NULL; 3008 mpfnAuthEntry3 = NULL; 3009 3010 if (mAuthLibrary) 3011 { 3012 RTLdrClose(mAuthLibrary); 3013 mAuthLibrary = 0; 3014 } 3006 AuthLibUnload(&mAuthLibCtx); 3015 3007 } 3016 3008 … … 3131 3123 #endif /* VBOX_WITH_USB */ 3132 3124 3133 typedef struct AuthCtx3134 {3135 AuthResult result;3136 3137 PAUTHENTRY3 pfnAuthEntry3;3138 PAUTHENTRY2 pfnAuthEntry2;3139 PAUTHENTRY pfnAuthEntry;3140 3141 const char *pszCaller;3142 PAUTHUUID pUuid;3143 AuthGuestJudgement guestJudgement;3144 const char *pszUser;3145 const char *pszPassword;3146 const char *pszDomain;3147 int fLogon;3148 unsigned clientId;3149 } AuthCtx;3150 3151 static DECLCALLBACK(int) authThread(RTTHREAD self, void *pvUser)3152 {3153 AuthCtx *pCtx = (AuthCtx *)pvUser;3154 3155 if (pCtx->pfnAuthEntry3)3156 {3157 pCtx->result = pCtx->pfnAuthEntry3(pCtx->pszCaller, pCtx->pUuid, pCtx->guestJudgement,3158 pCtx->pszUser, pCtx->pszPassword, pCtx->pszDomain,3159 pCtx->fLogon, pCtx->clientId);3160 }3161 else if (pCtx->pfnAuthEntry2)3162 {3163 pCtx->result = pCtx->pfnAuthEntry2(pCtx->pUuid, pCtx->guestJudgement,3164 pCtx->pszUser, pCtx->pszPassword, pCtx->pszDomain,3165 pCtx->fLogon, pCtx->clientId);3166 }3167 else if (pCtx->pfnAuthEntry)3168 {3169 pCtx->result = pCtx->pfnAuthEntry(pCtx->pUuid, pCtx->guestJudgement,3170 pCtx->pszUser, pCtx->pszPassword, pCtx->pszDomain);3171 }3172 return VINF_SUCCESS;3173 }3174 3175 static AuthResult authCall(AuthCtx *pCtx)3176 {3177 AuthResult result = AuthResultAccessDenied;3178 3179 /* Use a separate thread because external modules might need a lot of stack space. */3180 RTTHREAD thread = NIL_RTTHREAD;3181 int rc = RTThreadCreate(&thread, authThread, pCtx, 512*_1K,3182 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "VRDEAuth");3183 LogFlow(("authCall: RTThreadCreate %Rrc\n", rc));3184 3185 if (RT_SUCCESS(rc))3186 {3187 rc = RTThreadWait(thread, RT_INDEFINITE_WAIT, NULL);3188 LogFlow(("authCall: RTThreadWait %Rrc\n", rc));3189 }3190 3191 if (RT_SUCCESS(rc))3192 {3193 /* Only update the result if the thread finished without errors. */3194 result = pCtx->result;3195 }3196 else3197 {3198 LogRel(("AUTH: unable to execute the auth thread %Rrc\n", rc));3199 }3200 3201 return result;3202 }3203 3204 3125 AuthResult ConsoleVRDPServer::Authenticate(const Guid &uuid, AuthGuestJudgement guestJudgement, 3205 3126 const char *pszUser, const char *pszPassword, const char *pszDomain, 3206 3127 uint32_t u32ClientId) 3207 3128 { 3208 AUTHUUID rawuuid; 3209 3210 memcpy(rawuuid, uuid.raw(), sizeof(rawuuid)); 3211 3212 LogFlow(("ConsoleVRDPServer::Authenticate: uuid = %RTuuid, guestJudgement = %d, pszUser = %s, pszPassword = %s, pszDomain = %s, u32ClientId = %d\n", 3213 rawuuid, guestJudgement, pszUser, pszPassword, pszDomain, u32ClientId)); 3129 LogFlowFunc(("uuid = %RTuuid, guestJudgement = %d, pszUser = %s, pszPassword = %s, pszDomain = %s, u32ClientId = %d\n", 3130 uuid.raw(), guestJudgement, pszUser, pszPassword, pszDomain, u32ClientId)); 3214 3131 3215 3132 /* … … 3217 3134 */ 3218 3135 3219 if (!mAuthLib rary)3136 if (!mAuthLibCtx.hAuthLibrary) 3220 3137 { 3221 3138 /* Load the external authentication library. */ … … 3225 3142 Utf8Str filename = authLibrary; 3226 3143 3227 LogRel(("AUTH: loading external authentication library '%ls'\n", authLibrary.raw())); 3228 3229 int rc; 3230 if (RTPathHavePath(filename.c_str())) 3231 rc = RTLdrLoad(filename.c_str(), &mAuthLibrary); 3232 else 3233 { 3234 rc = RTLdrLoadAppPriv(filename.c_str(), &mAuthLibrary); 3235 if (RT_FAILURE(rc)) 3236 { 3237 /* Backward compatibility with old default 'VRDPAuth' name. 3238 * Try to load new default 'VBoxAuth' instead. 3239 */ 3240 if (filename == "VRDPAuth") 3241 { 3242 LogRel(("AUTH: ConsoleVRDPServer::Authenticate: loading external authentication library VBoxAuth\n")); 3243 rc = RTLdrLoadAppPriv("VBoxAuth", &mAuthLibrary); 3244 } 3245 } 3246 } 3247 3248 if (RT_FAILURE(rc)) 3249 LogRel(("AUTH: Failed to load external authentication library. Error code: %Rrc\n", rc)); 3250 3251 if (RT_SUCCESS(rc)) 3252 { 3253 typedef struct AuthEntryInfoStruct 3254 { 3255 const char *pszName; 3256 void **ppvAddress; 3257 3258 } AuthEntryInfo; 3259 AuthEntryInfo entries[] = 3260 { 3261 { AUTHENTRY3_NAME, (void **)&mpfnAuthEntry3 }, 3262 { AUTHENTRY2_NAME, (void **)&mpfnAuthEntry2 }, 3263 { AUTHENTRY_NAME, (void **)&mpfnAuthEntry }, 3264 { NULL, NULL } 3265 }; 3266 3267 /* Get the entry point. */ 3268 AuthEntryInfo *pEntryInfo = &entries[0]; 3269 while (pEntryInfo->pszName) 3270 { 3271 *pEntryInfo->ppvAddress = NULL; 3272 3273 int rc2 = RTLdrGetSymbol(mAuthLibrary, pEntryInfo->pszName, pEntryInfo->ppvAddress); 3274 if (RT_SUCCESS(rc2)) 3275 { 3276 /* Found an entry point. */ 3277 LogRel(("AUTH: Using entry point '%s'.\n", pEntryInfo->pszName)); 3278 rc = VINF_SUCCESS; 3279 break; 3280 } 3281 3282 if (rc2 != VERR_SYMBOL_NOT_FOUND) 3283 { 3284 LogRel(("AUTH: Could not resolve import '%s'. Error code: %Rrc\n", pEntryInfo->pszName, rc2)); 3285 } 3286 rc = rc2; 3287 3288 pEntryInfo++; 3289 } 3290 } 3144 int rc = AuthLibLoad(&mAuthLibCtx, filename.c_str()); 3291 3145 3292 3146 if (RT_FAILURE(rc)) … … 3297 3151 rc); 3298 3152 3299 mpfnAuthEntry = NULL;3300 mpfnAuthEntry2 = NULL;3301 mpfnAuthEntry3 = NULL;3302 3303 if (mAuthLibrary)3304 {3305 RTLdrClose(mAuthLibrary);3306 mAuthLibrary = 0;3307 }3308 3309 3153 return AuthResultAccessDenied; 3310 3154 } 3311 3155 } 3312 3156 3313 Assert(mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2 || mpfnAuthEntry3)); 3314 3315 AuthCtx ctx; 3316 ctx.result = AuthResultAccessDenied; /* Denied by default. */ 3317 ctx.pfnAuthEntry3 = mpfnAuthEntry3; 3318 ctx.pfnAuthEntry2 = mpfnAuthEntry2; 3319 ctx.pfnAuthEntry = mpfnAuthEntry; 3320 ctx.pszCaller = "vrde"; 3321 ctx.pUuid = &rawuuid; 3322 ctx.guestJudgement = guestJudgement; 3323 ctx.pszUser = pszUser; 3324 ctx.pszPassword = pszPassword; 3325 ctx.pszDomain = pszDomain; 3326 ctx.fLogon = true; 3327 ctx.clientId = u32ClientId; 3328 3329 AuthResult result = authCall(&ctx); 3157 AuthResult result = AuthLibAuthenticate(&mAuthLibCtx, 3158 uuid.raw(), guestJudgement, 3159 pszUser, pszPassword, pszDomain, 3160 u32ClientId); 3330 3161 3331 3162 switch (result) … … 3345 3176 } 3346 3177 3347 LogFlow (("ConsoleVRDPServer::Authenticate:result = %d\n", result));3178 LogFlowFunc(("result = %d\n", result)); 3348 3179 3349 3180 return result; … … 3352 3183 void ConsoleVRDPServer::AuthDisconnect(const Guid &uuid, uint32_t u32ClientId) 3353 3184 { 3354 AUTHUUID rawuuid;3355 3356 memcpy(rawuuid, uuid.raw(), sizeof(rawuuid));3357 3358 3185 LogFlow(("ConsoleVRDPServer::AuthDisconnect: uuid = %RTuuid, u32ClientId = %d\n", 3359 rawuuid, u32ClientId)); 3360 3361 Assert(mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2 || mpfnAuthEntry3)); 3362 3363 AuthCtx ctx; 3364 ctx.result = AuthResultAccessDenied; /* Not used. */ 3365 ctx.pfnAuthEntry3 = mpfnAuthEntry3; 3366 ctx.pfnAuthEntry2 = mpfnAuthEntry2; 3367 ctx.pfnAuthEntry = NULL; /* Does not use disconnect notification. */ 3368 ctx.pszCaller = "vrde"; 3369 ctx.pUuid = &rawuuid; 3370 ctx.guestJudgement = AuthGuestNotAsked; 3371 ctx.pszUser = NULL; 3372 ctx.pszPassword = NULL; 3373 ctx.pszDomain = NULL; 3374 ctx.fLogon = false; 3375 ctx.clientId = u32ClientId; 3376 3377 authCall(&ctx); 3186 uuid.raw(), u32ClientId)); 3187 3188 AuthLibDisconnect(&mAuthLibCtx, uuid.raw(), u32ClientId); 3378 3189 } 3379 3190
Note:
See TracChangeset
for help on using the changeset viewer.