示例#1
0
/*
 * dcmd ::cred - display a credential (cred_t)
 */
int
cmd_cred(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	credgrp_t cr_grps;
	cred_t	*cr;
	mdb_arg_t cmdarg;
	uint_t opts = FALSE;

	if (mdb_getopts(argc, argv,
	    'v', MDB_OPT_SETBITS, OPT_VERBOSE, &opts, NULL) != argc)
		return (DCMD_USAGE);

	if (!(flags & DCMD_ADDRSPEC)) {
		return (DCMD_USAGE);
	}

	cr = mdb_alloc(sizeof (*cr), UM_SLEEP | UM_GC);
	if (mdb_vread(cr, sizeof (*cr), addr) == -1) {
		mdb_warn("error reading cred_t at %p", addr);
		return (DCMD_ERR);
	}

	if (cr->cr_grps == NULL) {
		bzero(&cr_grps, sizeof (cr_grps));
	} else {
		if (mdb_vread(&cr_grps, sizeof (cr_grps),
		    (uintptr_t)cr->cr_grps) == -1) {
			mdb_warn("error reading credgrp_t at %p",
			    cr->cr_grps);
			return (DCMD_ERR);
		}
	}

	if (opts & OPT_VERBOSE) {
		cmdarg.a_type = MDB_TYPE_STRING;
		cmdarg.a_un.a_str = "cred_t";
		(void) mdb_call_dcmd("print", addr, flags, 1, &cmdarg);
		cmdarg.a_un.a_str = "-v";

		mdb_printf("%<u>cr_grps:%</u>\n");
		mdb_inc_indent(4);
		if (cr->cr_grps == NULL) {
			mdb_printf("(null)\n");
		} else {
			(void) mdb_call_dcmd("credgrp",
			    (uintptr_t)cr->cr_grps, flags, 1, &cmdarg);
		}
		mdb_dec_indent(4);

		mdb_printf("%<u>cr_ksid:%</u>\n");
		mdb_inc_indent(4);
		if (cr->cr_ksid == NULL) {
			mdb_printf("(null)\n");
		} else {
			(void) mdb_call_dcmd("credsid",
			    (uintptr_t)cr->cr_ksid, flags, 1, &cmdarg);
		}
		mdb_dec_indent(4);

		return (DCMD_OK);
	}

	if (DCMD_HDRSPEC(flags))
		mdb_printf("%<u>%?s %8s %8s %8s %8s% %8s%</u>\n",
		    "ADDR", "UID", "GID", "RUID", "RGID", "#GRP(+SIDS)");

	mdb_printf("%0?p %8u %8u %8u %8u %4u%s\n", addr,
	    cr->cr_uid,  cr->cr_gid,
	    cr->cr_ruid, cr->cr_rgid,
	    cr_grps.crg_ngroups,
	    (cr->cr_ksid == NULL) ? "" : "+");

	return (DCMD_OK);
}