MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sctp_getcred

Function sctp_getcred

freebsd/netinet/sctp_usrreq.c:349–406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347#endif
348
349static int
350sctp_getcred(SYSCTL_HANDLER_ARGS)
351{
352 struct xucred xuc;
353 struct sockaddr_in addrs[2];
354 struct sctp_inpcb *inp;
355 struct sctp_nets *net;
356 struct sctp_tcb *stcb;
357 int error;
358 uint32_t vrf_id;
359
360 /* FIX, for non-bsd is this right? */
361 vrf_id = SCTP_DEFAULT_VRFID;
362
363 error = priv_check(req->td, PRIV_NETINET_GETCRED);
364
365 if (error)
366 return (error);
367
368 error = SYSCTL_IN(req, addrs, sizeof(addrs));
369 if (error)
370 return (error);
371
372 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
373 sintosa(&addrs[0]),
374 &inp, &net, 1, vrf_id);
375 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
376 if ((inp != NULL) && (stcb == NULL)) {
377 /* reduce ref-count */
378 SCTP_INP_WLOCK(inp);
379 SCTP_INP_DECR_REF(inp);
380 goto cred_can_cont;
381 }
382
383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
384 error = ENOENT;
385 goto out;
386 }
387 SCTP_TCB_UNLOCK(stcb);
388 /*
389 * We use the write lock here, only since in the error leg we need
390 * it. If we used RLOCK, then we would have to
391 * wlock/decr/unlock/rlock. Which in theory could create a hole.
392 * Better to use higher wlock.
393 */
394 SCTP_INP_WLOCK(inp);
395cred_can_cont:
396 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
397 if (error) {
398 SCTP_INP_WUNLOCK(inp);
399 goto out;
400 }
401 cru2x(inp->sctp_socket->so_cred, &xuc);
402 SCTP_INP_WUNLOCK(inp);
403 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
404out:
405 return (error);
406}

Callers

nothing calls this directly

Calls 4

priv_checkFunction · 0.50
cr_canseesocketFunction · 0.50
cru2xFunction · 0.50

Tested by

no test coverage detected