コード例 #1
0
ファイル: grabs.c プロジェクト: dlespiau/xserver
void
PrintDeviceGrabInfo(DeviceIntPtr dev)
{
    ClientPtr client;
    LocalClientCredRec *lcc;
    int i, j;
    GrabInfoPtr devGrab = &dev->deviceGrab;
    GrabPtr grab = devGrab->grab;
    Bool clientIdPrinted = FALSE;

    ErrorF("Active grab 0x%lx (%s) on device '%s' (%d):\n",
           (unsigned long) grab->resource,
           (grab->grabtype == XI2) ? "xi2" :
           ((grab->grabtype == CORE) ? "core" : "xi1"), dev->name, dev->id);

    client = clients[CLIENT_ID(grab->resource)];
    if (client) {
        pid_t clientpid = GetClientPid(client);
        const char *cmdname = GetClientCmdName(client);
        const char *cmdargs = GetClientCmdArgs(client);

        if ((clientpid > 0) && (cmdname != NULL)) {
            ErrorF("      client pid %ld %s %s\n",
                   (long) clientpid, cmdname, cmdargs ? cmdargs : "");
            clientIdPrinted = TRUE;
        }
        else if (GetLocalClientCreds(client, &lcc) != -1) {
            ErrorF("      client pid %ld uid %ld gid %ld\n",
                   (lcc->fieldsSet & LCC_PID_SET) ? (long) lcc->pid : 0,
                   (lcc->fieldsSet & LCC_UID_SET) ? (long) lcc->euid : 0,
                   (lcc->fieldsSet & LCC_GID_SET) ? (long) lcc->egid : 0);
            FreeLocalClientCreds(lcc);
            clientIdPrinted = TRUE;
        }
    }
    if (!clientIdPrinted) {
        ErrorF("      (no client information available for client %d)\n",
               CLIENT_ID(grab->resource));
    }

    /* XXX is this even correct? */
    if (devGrab->sync.other)
        ErrorF("      grab ID 0x%lx from paired device\n",
               (unsigned long) devGrab->sync.other->resource);

    ErrorF("      at %ld (from %s grab)%s (device %s, state %d)\n",
           (unsigned long) devGrab->grabTime.milliseconds,
           devGrab->fromPassiveGrab ? "passive" : "active",
           devGrab->implicitGrab ? " (implicit)" : "",
           devGrab->sync.frozen ? "frozen" : "thawed", devGrab->sync.state);

    if (grab->grabtype == CORE) {
        ErrorF("        core event mask 0x%lx\n",
               (unsigned long) grab->eventMask);
    }
    else if (grab->grabtype == XI) {
        ErrorF("      xi1 event mask 0x%lx\n",
               devGrab->implicitGrab ? (unsigned long) grab->deviceMask :
               (unsigned long) grab->eventMask);
    }
    else if (grab->grabtype == XI2) {
        for (i = 0; i < xi2mask_num_masks(grab->xi2mask); i++) {
            const unsigned char *mask;
            int print;

            print = 0;
            for (j = 0; j < XI2MASKSIZE; j++) {
                mask = xi2mask_get_one_mask(grab->xi2mask, i);
                if (mask[j]) {
                    print = 1;
                    break;
                }
            }
            if (!print)
                continue;
            ErrorF("      xi2 event mask for device %d: 0x", dev->id);
            for (j = 0; j < xi2mask_mask_size(grab->xi2mask); j++)
                ErrorF("%x", mask[j]);
            ErrorF("\n");
        }
    }

    if (devGrab->fromPassiveGrab) {
        ErrorF("      passive grab type %d, detail 0x%x, "
               "activating key %d\n", grab->type, grab->detail.exact,
               devGrab->activatingKey);
    }

    ErrorF("      owner-events %s, kb %d ptr %d, confine %lx, cursor 0x%lx\n",
           grab->ownerEvents ? "true" : "false",
           grab->keyboardMode, grab->pointerMode,
           grab->confineTo ? (unsigned long) grab->confineTo->drawable.id : 0,
           grab->cursor ? (unsigned long) grab->cursor->id : 0);
}
コード例 #2
0
ファイル: connection.c プロジェクト: L3oV1nc3/VMGL
static void
AuthAudit (ClientPtr client, Bool letin, 
    struct sockaddr *saddr, int len, 
    unsigned int proto_n, char *auth_proto, int auth_id)
{
    char addr[128];
    char *out = addr;
    char client_uid_string[64];
    LocalClientCredRec *lcc;
#ifdef XSERVER_DTRACE
    pid_t client_pid = -1;
    zoneid_t client_zid = -1;
#endif

    if (!len)
        strcpy(out, "local host");
    else
	switch (saddr->sa_family)
	{
	case AF_UNSPEC:
#if defined(UNIXCONN) || defined(LOCALCONN)
	case AF_UNIX:
#endif
	    strcpy(out, "local host");
	    break;
#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
	case AF_INET:
	    sprintf(out, "IP %s",
		inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr));
	    break;
#if defined(IPv6) && defined(AF_INET6)
	case AF_INET6: {
	    char ipaddr[INET6_ADDRSTRLEN];
	    inet_ntop(AF_INET6, &((struct sockaddr_in6 *) saddr)->sin6_addr,
	      ipaddr, sizeof(ipaddr));
	    sprintf(out, "IP %s", ipaddr);
	}
	    break;
#endif
#endif
#ifdef DNETCONN
	case AF_DECnet:
	    sprintf(out, "DN %s",
		    dnet_ntoa(&((struct sockaddr_dn *) saddr)->sdn_add));
	    break;
#endif
	default:
	    strcpy(out, "unknown address");
	}

    if (GetLocalClientCreds(client, &lcc) != -1) {
	int slen; /* length written to client_uid_string */

	strcpy(client_uid_string, " ( ");
	slen = 3;

	if (lcc->fieldsSet & LCC_UID_SET) {
	    snprintf(client_uid_string + slen,
		     sizeof(client_uid_string) - slen,
		     "uid=%ld ", (long) lcc->euid);
	    slen = strlen(client_uid_string);
	}

	if (lcc->fieldsSet & LCC_GID_SET) {
	    snprintf(client_uid_string + slen,
		     sizeof(client_uid_string) - slen,
		     "gid=%ld ", (long) lcc->egid);
	    slen = strlen(client_uid_string);
	}

	if (lcc->fieldsSet & LCC_PID_SET) {
#ifdef XSERVER_DTRACE	    
	    client_pid = lcc->pid;
#endif
	    snprintf(client_uid_string + slen,
		     sizeof(client_uid_string) - slen,
		     "pid=%ld ", (long) lcc->pid);
	    slen = strlen(client_uid_string);
	}
	
	if (lcc->fieldsSet & LCC_ZID_SET) {
#ifdef XSERVER_DTRACE
	    client_zid = lcc->zoneid;
#endif	    
	    snprintf(client_uid_string + slen,
		     sizeof(client_uid_string) - slen,
		     "zoneid=%ld ", (long) lcc->zoneid);
	    slen = strlen(client_uid_string);
	}

	snprintf(client_uid_string + slen, sizeof(client_uid_string) - slen,
		 ")");
	FreeLocalClientCreds(lcc);
    }
    else {
	client_uid_string[0] = '\0';
    }
    
#ifdef XSERVER_DTRACE
    XSERVER_CLIENT_AUTH(client->index, addr, client_pid, client_zid);
#endif
    if (auditTrailLevel > 1) {
      if (proto_n)
	AuditF("client %d %s from %s%s\n  Auth name: %.*s ID: %d\n", 
	       client->index, letin ? "connected" : "rejected", addr,
	       client_uid_string, (int)proto_n, auth_proto, auth_id);
      else 
	AuditF("client %d %s from %s%s\n", 
	       client->index, letin ? "connected" : "rejected", addr,
	       client_uid_string);

    }
}
コード例 #3
0
ファイル: shm.c プロジェクト: Agnarr/xserver
/*
 * Simulate the access() system call for a shared memory segement,
 * using the credentials from the client if available
 */
static int
shm_access(ClientPtr client, SHMPERM_TYPE *perm, int readonly)
{
    int uid, gid;
    mode_t mask;
    int uidset = 0, gidset = 0;
    LocalClientCredRec *lcc;
    
    if (GetLocalClientCreds(client, &lcc) != -1) {

	if (lcc->fieldsSet & LCC_UID_SET) {
	    uid = lcc->euid;
	    uidset = 1;
	}
	if (lcc->fieldsSet & LCC_GID_SET) {
	    gid = lcc->egid;
	    gidset = 1;
	}

#if defined(HAVE_GETZONEID) && defined(SHMPERM_ZONEID)
	if ( ((lcc->fieldsSet & LCC_ZID_SET) == 0) || (lcc->zoneid == -1)
	     || (lcc->zoneid != SHMPERM_ZONEID(perm))) {
		uidset = 0;
		gidset = 0;
	}
#endif
	FreeLocalClientCreds(lcc);
	
	if (uidset) {
	    /* User id 0 always gets access */
	    if (uid == 0) {
		return 0;
	    }
	    /* Check the owner */
	    if (SHMPERM_UID(perm) == uid || SHMPERM_CUID(perm) == uid) {
		mask = S_IRUSR;
		if (!readonly) {
		    mask |= S_IWUSR;
		}
		return (SHMPERM_MODE(perm) & mask) == mask ? 0 : -1;
	    }
	}

	if (gidset) {
	    /* Check the group */
	    if (SHMPERM_GID(perm) == gid || SHMPERM_CGID(perm) == gid) {
		mask = S_IRGRP;
		if (!readonly) {
		    mask |= S_IWGRP;
		}
		return (SHMPERM_MODE(perm) & mask) == mask ? 0 : -1;
	    }
	}
    }
    /* Otherwise, check everyone else */
    mask = S_IROTH;
    if (!readonly) {
	mask |= S_IWOTH;
    }
    return (SHMPERM_MODE(perm) & mask) == mask ? 0 : -1;
}
コード例 #4
0
ファイル: grabs.c プロジェクト: nikai3d/xserver
void
PrintDeviceGrabInfo(DeviceIntPtr dev)
{
    ClientPtr client;
    LocalClientCredRec *lcc;
    int i, j;
    GrabInfoPtr devGrab = &dev->deviceGrab;
    GrabPtr grab = devGrab->grab;

    ErrorF("Active grab 0x%lx (%s) on device '%s' (%d):",
           (unsigned long) grab->resource,
           (grab->grabtype == GRABTYPE_XI2) ? "xi2" :
            ((grab->grabtype == GRABTYPE_CORE) ? "core" : "xi1"),
           dev->name, dev->id);

    client = clients[CLIENT_ID(grab->resource)];
    if (client && GetLocalClientCreds(client, &lcc) != -1)
    {
        ErrorF("      client pid %ld uid %ld gid %ld\n",
               (lcc->fieldsSet & LCC_PID_SET) ? (long) lcc->pid : 0,
               (lcc->fieldsSet & LCC_UID_SET) ? (long) lcc->euid : 0,
               (lcc->fieldsSet & LCC_GID_SET) ? (long) lcc->egid : 0);
        FreeLocalClientCreds(lcc);
    }
    else
    {
        ErrorF("      (no client information available)\n");
    }

    /* XXX is this even correct? */
    if (devGrab->sync.other)
        ErrorF("      grab ID 0x%lx from paired device\n",
               (unsigned long) devGrab->sync.other->resource);

    ErrorF("      at %ld (from %s grab)%s (device %s, state %d)\n",
           (unsigned long) devGrab->grabTime.milliseconds,
           devGrab->fromPassiveGrab ? "passive" : "active",
           devGrab->implicitGrab ? " (implicit)" : "",
           devGrab->sync.frozen ? "frozen" : "thawed",
           devGrab->sync.state);

    if (grab->grabtype == GRABTYPE_CORE)
    {
        ErrorF("        core event mask 0x%lx\n",
               (unsigned long) grab->eventMask);
    }
    else if (grab->grabtype == GRABTYPE_XI)
    {
        ErrorF("      xi1 event mask 0x%lx\n",
               devGrab->implicitGrab ? (unsigned long) grab->deviceMask :
                                       (unsigned long) grab->eventMask);
    }
    else if (grab->grabtype == GRABTYPE_XI2)
    {
        for (i = 0; i < EMASKSIZE; i++)
        {
            int print;
            print = 0;
            for (j = 0; j < XI2MASKSIZE; j++)
            {
                if (grab->xi2mask[i][j])
                {
                    print = 1;
                    break;
                }
            }
            if (!print)
                continue;
            ErrorF("      xi2 event mask for device %d: 0x", dev->id);
            for (j = 0; j < XI2MASKSIZE; j++)
                ErrorF("%x", grab->xi2mask[i][j]);
            ErrorF("\n");
        }
    }

    if (devGrab->fromPassiveGrab)
    {
        ErrorF("      passive grab type %d, detail 0x%x, "
               "activating key %d\n", grab->type, grab->detail.exact,
               devGrab->activatingKey);
    }

    ErrorF("      owner-events %s, kb %d ptr %d, confine %lx, cursor 0x%lx\n",
           grab->ownerEvents ? "true" : "false",
           grab->keyboardMode, grab->pointerMode,
           grab->confineTo ? (unsigned long) grab->confineTo->drawable.id : 0,
           grab->cursor ? (unsigned long) grab->cursor->id : 0);
}