Deleted Added
full compact
drm_auth.c (182080) drm_auth.c (183573)
1/*-
2 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation

--- 15 unchanged lines hidden (view full) ---

24 *
25 * Authors:
26 * Rickard E. (Rik) Faith <faith@valinux.com>
27 * Gareth Hughes <gareth@valinux.com>
28 *
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation

--- 15 unchanged lines hidden (view full) ---

24 *
25 * Authors:
26 * Rickard E. (Rik) Faith <faith@valinux.com>
27 * Gareth Hughes <gareth@valinux.com>
28 *
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/drm/drm_auth.c 182080 2008-08-23 20:59:12Z rnoland $");
32__FBSDID("$FreeBSD: head/sys/dev/drm/drm_auth.c 183573 2008-10-03 16:59:11Z rnoland $");
33
34/** @file drm_auth.c
35 * Implementation of the get/authmagic ioctls implementing the authentication
36 * scheme between the master and clients.
37 */
38
39#include "dev/drm/drmP.h"
40
41static int drm_hash_magic(drm_magic_t magic)
42{
43 return magic & (DRM_HASH_SIZE-1);
44}
45
46/**
47 * Returns the file private associated with the given magic number.
48 */
33
34/** @file drm_auth.c
35 * Implementation of the get/authmagic ioctls implementing the authentication
36 * scheme between the master and clients.
37 */
38
39#include "dev/drm/drmP.h"
40
41static int drm_hash_magic(drm_magic_t magic)
42{
43 return magic & (DRM_HASH_SIZE-1);
44}
45
46/**
47 * Returns the file private associated with the given magic number.
48 */
49static drm_file_t *drm_find_file(struct drm_device *dev, drm_magic_t magic)
49static struct drm_file *drm_find_file(struct drm_device *dev, drm_magic_t magic)
50{
51 drm_magic_entry_t *pt;
52 int hash = drm_hash_magic(magic);
53
54 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
55
56 for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
57 if (pt->magic == magic) {
58 return pt->priv;
59 }
60 }
61
62 return NULL;
63}
64
65/**
66 * Inserts the given magic number into the hash table of used magic number
67 * lists.
68 */
50{
51 drm_magic_entry_t *pt;
52 int hash = drm_hash_magic(magic);
53
54 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
55
56 for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
57 if (pt->magic == magic) {
58 return pt->priv;
59 }
60 }
61
62 return NULL;
63}
64
65/**
66 * Inserts the given magic number into the hash table of used magic number
67 * lists.
68 */
69static int drm_add_magic(struct drm_device *dev, drm_file_t *priv,
69static int drm_add_magic(struct drm_device *dev, struct drm_file *priv,
70 drm_magic_t magic)
71{
72 int hash;
73 drm_magic_entry_t *entry;
74
75 DRM_DEBUG("%d\n", magic);
76
77 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
78
79 hash = drm_hash_magic(magic);
80 entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT);
70 drm_magic_t magic)
71{
72 int hash;
73 drm_magic_entry_t *entry;
74
75 DRM_DEBUG("%d\n", magic);
76
77 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
78
79 hash = drm_hash_magic(magic);
80 entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT);
81 if (!entry) return ENOMEM;
81 if (!entry)
82 return ENOMEM;
82 entry->magic = magic;
83 entry->priv = priv;
84 entry->next = NULL;
85
86 if (dev->magiclist[hash].tail) {
87 dev->magiclist[hash].tail->next = entry;
88 dev->magiclist[hash].tail = entry;
89 } else {

--- 44 unchanged lines hidden (view full) ---

134 *
135 * The master may use its own knowledge of the client (such as the X
136 * connection that the magic is passed over) to determine if the magic number
137 * should be authenticated.
138 */
139int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
140{
141 static drm_magic_t sequence = 0;
83 entry->magic = magic;
84 entry->priv = priv;
85 entry->next = NULL;
86
87 if (dev->magiclist[hash].tail) {
88 dev->magiclist[hash].tail->next = entry;
89 dev->magiclist[hash].tail = entry;
90 } else {

--- 44 unchanged lines hidden (view full) ---

135 *
136 * The master may use its own knowledge of the client (such as the X
137 * connection that the magic is passed over) to determine if the magic number
138 * should be authenticated.
139 */
140int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
141{
142 static drm_magic_t sequence = 0;
142 drm_auth_t *auth = data;
143 struct drm_auth *auth = data;
143
144
144 /* Find unique magic */
145 /* Find unique magic */
145 if (file_priv->magic) {
146 auth->magic = file_priv->magic;
147 } else {
148 DRM_LOCK();
149 do {
150 int old = sequence;
151
152 auth->magic = old+1;

--- 12 unchanged lines hidden (view full) ---

165}
166
167/**
168 * Marks the client associated with the given magic number as authenticated.
169 */
170int drm_authmagic(struct drm_device *dev, void *data,
171 struct drm_file *file_priv)
172{
146 if (file_priv->magic) {
147 auth->magic = file_priv->magic;
148 } else {
149 DRM_LOCK();
150 do {
151 int old = sequence;
152
153 auth->magic = old+1;

--- 12 unchanged lines hidden (view full) ---

166}
167
168/**
169 * Marks the client associated with the given magic number as authenticated.
170 */
171int drm_authmagic(struct drm_device *dev, void *data,
172 struct drm_file *file_priv)
173{
173 drm_auth_t *auth = data;
174 drm_file_t *priv;
174 struct drm_auth *auth = data;
175 struct drm_file *priv;
175
176 DRM_DEBUG("%u\n", auth->magic);
177
178 DRM_LOCK();
179 priv = drm_find_file(dev, auth->magic);
180 if (priv != NULL) {
181 priv->authenticated = 1;
182 drm_remove_magic(dev, auth->magic);
183 DRM_UNLOCK();
184 return 0;
185 } else {
186 DRM_UNLOCK();
187 return EINVAL;
188 }
189}
176
177 DRM_DEBUG("%u\n", auth->magic);
178
179 DRM_LOCK();
180 priv = drm_find_file(dev, auth->magic);
181 if (priv != NULL) {
182 priv->authenticated = 1;
183 drm_remove_magic(dev, auth->magic);
184 DRM_UNLOCK();
185 return 0;
186 } else {
187 DRM_UNLOCK();
188 return EINVAL;
189 }
190}