PermissionsData_t *perm_create (Permissions_t perm, DDS_ReturnCode_t *ret) { PermissionsData_t *p; unsigned h; p = perm_lookup (perm, &h); if (p) { *ret = DDS_RETCODE_OK; return (p); } p = perm_new (perm); if (!p) { *ret = DDS_RETCODE_OUT_OF_RESOURCES; return (NULL); } perm_add (p, h); *ret = DDS_RETCODE_OK; return (p); }
void perm_release (Permissions_t perm) { unsigned h; perm_free (perm_lookup (perm, &h)); }
static Token_t *sd_get_perm_token (const SEC_PERM *pp, Permissions_t perm) { Token_t *token; DDS_IdentityToken *tp; DDS_OctetSeq *p; PermissionsData_t *pdp; DDS_SecurityReqData data; char buf [128]; char *bp; MD5_CONTEXT md5; DDS_ReturnCode_t ret; ARG_NOT_USED (pp) token = xmalloc (sizeof (Token_t)); if (!token) return (NULL); pdp = perm_lookup (perm, NULL); if (!pdp) goto no_perm; data.handle = pdp->id; data.data = NULL; data.length = 0; ret = sec_authentication_request (DDS_GET_ID_NAME, &data); if (ret || !data.rlength) goto no_perm; if (data.rlength >= sizeof (buf)) { bp = Alloc (data.rlength); if (!bp) goto no_perm; } else bp = buf; data.handle = pdp->id; data.data = bp; data.length = data.rlength; ret = sec_authentication_request (DDS_GET_ID_NAME, &data); if (ret) goto done; tp = DDS_DataHolder__alloc (GMCLASSID_SECURITY_DTLS_PERM_TOKEN); if (!tp) goto done; tp->binary_value1 = p = DDS_OctetSeq__alloc (); if (!p) goto out_of_mem; ret = dds_seq_require (p, 16); if (ret) { DDS_DataHolder__free (tp); return (NULL); } md5_init (&md5); md5_update (&md5, (unsigned char *) bp, strlen (bp)); md5_final (DDS_SEQ_DATA (*p), &md5); if (bp != buf) Free (bp); token->data = tp; token->encoding = PID_V_PERMS; token->integral = 0; token->nusers = 1; token->next = NULL; return (token); out_of_mem: DDS_DataHolder__free (tp); done: if (bp != buf) Free (bp); no_perm: xfree (token); return (NULL); }