Changeset 4214 for pjproject/trunk
- Timestamp:
- Jul 25, 2012 2:29:28 PM (12 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip/sip_auth.h
r3553 r4214 276 276 pjsip_cred_info *cred_info ); 277 277 278 279 /** 280 * This structure describes input param for credential lookup. 281 */ 282 typedef struct pjsip_auth_lookup_cred_param 283 { 284 pj_str_t realm; /**< Realm to find the account. */ 285 pj_str_t acc_name; /**< Account name to look for. */ 286 pjsip_rx_data *rdata; /**< Incoming request to be authenticated. */ 287 288 } pjsip_auth_lookup_cred_param; 289 290 291 /** 292 * Type of function to lookup credential for the specified name. 293 * 294 * @param pool Pool to initialize the credential info. 295 * @param param The input param for credential lookup. 296 * @param cred_info The structure to put the credential when it's found. 297 * 298 * @return The function MUST return PJ_SUCCESS when it found 299 * a correct credential for the specified account and 300 * realm. Otherwise it may return PJSIP_EAUTHACCNOTFOUND 301 * or PJSIP_EAUTHACCDISABLED. 302 */ 303 typedef pj_status_t pjsip_auth_lookup_cred2( 304 pj_pool_t *pool, 305 const pjsip_auth_lookup_cred_param *param, 306 pjsip_cred_info *cred_info ); 307 308 278 309 /** Flag to specify that server is a proxy. */ 279 310 #define PJSIP_AUTH_SRV_IS_PROXY 1 … … 287 318 pj_bool_t is_proxy; /**< Will issue 407 instead of 401 */ 288 319 pjsip_auth_lookup_cred *lookup; /**< Lookup function. */ 289 320 pjsip_auth_lookup_cred2 *lookup2; /**< Lookup function with additional 321 info in its input param. */ 290 322 } pjsip_auth_srv; 291 323 … … 433 465 unsigned options ); 434 466 467 468 /** 469 * This structure describes initialization settings of server authorization 470 * session. 471 */ 472 typedef struct pjsip_auth_srv_init_param 473 { 474 /** 475 * Realm to be served by the server. 476 */ 477 const pj_str_t *realm; 478 479 /** 480 * Account lookup function. 481 */ 482 pjsip_auth_lookup_cred2 *lookup2; 483 484 /** 485 * Options, bitmask of: 486 * - PJSIP_AUTH_SRV_IS_PROXY: to specify that the server will authorize 487 * clients as a proxy server (instead of as UAS), which means that 488 * Proxy-Authenticate will be used instead of WWW-Authenticate. 489 */ 490 unsigned options; 491 492 } pjsip_auth_srv_init_param; 493 494 495 /** 496 * Initialize server authorization session data structure to serve the 497 * specified realm and to use lookup_func function to look for the credential 498 * info. 499 * 500 * @param pool Pool used to initialize the authentication server. 501 * @param auth_srv The authentication server structure. 502 * @param param The initialization param. 503 * 504 * @return PJ_SUCCESS on success. 505 */ 506 PJ_DECL(pj_status_t) pjsip_auth_srv_init2( 507 pj_pool_t *pool, 508 pjsip_auth_srv *auth_srv, 509 const pjsip_auth_srv_init_param *param); 435 510 436 511 /** -
pjproject/trunk/pjsip/src/pjsip/sip_auth_server.c
r3553 r4214 41 41 PJ_ASSERT_RETURN(pool && auth_srv && realm && lookup, PJ_EINVAL); 42 42 43 pj_bzero(auth_srv, sizeof(*auth_srv)); 43 44 pj_strdup( pool, &auth_srv->realm, realm); 44 45 auth_srv->lookup = lookup; 45 46 auth_srv->is_proxy = (options & PJSIP_AUTH_SRV_IS_PROXY); 47 48 return PJ_SUCCESS; 49 } 50 51 /* 52 * Initialize server authorization session data structure to serve the 53 * specified realm and to use lookup_func function to look for the credential 54 * info. 55 */ 56 PJ_DEF(pj_status_t) pjsip_auth_srv_init2( 57 pj_pool_t *pool, 58 pjsip_auth_srv *auth_srv, 59 const pjsip_auth_srv_init_param *param) 60 { 61 PJ_ASSERT_RETURN(pool && auth_srv && param, PJ_EINVAL); 62 63 pj_bzero(auth_srv, sizeof(*auth_srv)); 64 pj_strdup( pool, &auth_srv->realm, param->realm); 65 auth_srv->lookup2 = param->lookup2; 66 auth_srv->is_proxy = (param->options & PJSIP_AUTH_SRV_IS_PROXY); 46 67 47 68 return PJ_SUCCESS; … … 149 170 150 171 /* Find the credential information for the account. */ 151 status = (*auth_srv->lookup)(rdata->tp_info.pool, &auth_srv->realm, 152 &acc_name, &cred_info); 153 if (status != PJ_SUCCESS) { 154 *status_code = PJSIP_SC_FORBIDDEN; 155 return status; 172 if (auth_srv->lookup2) { 173 pjsip_auth_lookup_cred_param param; 174 175 pj_bzero(¶m, sizeof(param)); 176 param.realm = auth_srv->realm; 177 param.acc_name = acc_name; 178 param.rdata = rdata; 179 status = (*auth_srv->lookup2)(rdata->tp_info.pool, ¶m, &cred_info); 180 if (status != PJ_SUCCESS) { 181 *status_code = PJSIP_SC_FORBIDDEN; 182 return status; 183 } 184 } else { 185 status = (*auth_srv->lookup)(rdata->tp_info.pool, &auth_srv->realm, 186 &acc_name, &cred_info); 187 if (status != PJ_SUCCESS) { 188 *status_code = PJSIP_SC_FORBIDDEN; 189 return status; 190 } 156 191 } 157 192
Note: See TracChangeset
for help on using the changeset viewer.