drm_auth.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
  3. *
  4. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  5. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  6. * All Rights Reserved.
  7. *
  8. * Author Rickard E. (Rik) Faith <faith@valinux.com>
  9. * Author Gareth Hughes <gareth@valinux.com>
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice (including the next
  19. * paragraph) shall be included in all copies or substantial portions of the
  20. * Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  25. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  26. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  27. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  28. * OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30. #include <drm/drmP.h>
  31. #include "drm_internal.h"
  32. /**
  33. * drm_getmagic - Get unique magic of a client
  34. * @dev: DRM device to operate on
  35. * @data: ioctl data containing the drm_auth object
  36. * @file_priv: DRM file that performs the operation
  37. *
  38. * This looks up the unique magic of the passed client and returns it. If the
  39. * client did not have a magic assigned, yet, a new one is registered. The magic
  40. * is stored in the passed drm_auth object.
  41. *
  42. * Returns: 0 on success, negative error code on failure.
  43. */
  44. int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
  45. {
  46. struct drm_auth *auth = data;
  47. int ret = 0;
  48. mutex_lock(&dev->struct_mutex);
  49. if (!file_priv->magic) {
  50. ret = idr_alloc(&file_priv->master->magic_map, file_priv,
  51. 1, 0, GFP_KERNEL);
  52. if (ret >= 0)
  53. file_priv->magic = ret;
  54. }
  55. auth->magic = file_priv->magic;
  56. mutex_unlock(&dev->struct_mutex);
  57. DRM_DEBUG("%u\n", auth->magic);
  58. return ret < 0 ? ret : 0;
  59. }
  60. /**
  61. * drm_authmagic - Authenticate client with a magic
  62. * @dev: DRM device to operate on
  63. * @data: ioctl data containing the drm_auth object
  64. * @file_priv: DRM file that performs the operation
  65. *
  66. * This looks up a DRM client by the passed magic and authenticates it.
  67. *
  68. * Returns: 0 on success, negative error code on failure.
  69. */
  70. int drm_authmagic(struct drm_device *dev, void *data,
  71. struct drm_file *file_priv)
  72. {
  73. struct drm_auth *auth = data;
  74. struct drm_file *file;
  75. DRM_DEBUG("%u\n", auth->magic);
  76. mutex_lock(&dev->struct_mutex);
  77. file = idr_find(&file_priv->master->magic_map, auth->magic);
  78. if (file) {
  79. file->authenticated = 1;
  80. idr_replace(&file_priv->master->magic_map, NULL, auth->magic);
  81. }
  82. mutex_unlock(&dev->struct_mutex);
  83. return file ? 0 : -EINVAL;
  84. }