/samba-3.5.6/source3/registry/reg_backend_shares.c

https://github.com/theuni/XBMC-deps · C · 164 lines · 71 code · 37 blank · 56 comment · 8 complexity · a4cdd70b8a92ec8f7b684534b900ebd3 MD5 · raw file

  1. /*
  2. * Unix SMB/CIFS implementation.
  3. * Virtual Windows Registry Layer
  4. * Copyright (C) Gerald Carter 2005
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /* Implementation of registry virtual views for printing information */
  20. #include "includes.h"
  21. #undef DBGC_CLASS
  22. #define DBGC_CLASS DBGC_REGISTRY
  23. /**********************************************************************
  24. It is safe to assume that every registry path passed into on of
  25. the exported functions here begins with KEY_PRINTING else
  26. these functions would have never been called. This is a small utility
  27. function to strip the beginning of the path and make a copy that the
  28. caller can modify. Note that the caller is responsible for releasing
  29. the memory allocated here.
  30. **********************************************************************/
  31. static char* trim_reg_path( const char *path )
  32. {
  33. const char *p;
  34. uint16 key_len = strlen(KEY_SHARES);
  35. /*
  36. * sanity check...this really should never be True.
  37. * It is only here to prevent us from accessing outside
  38. * the path buffer in the extreme case.
  39. */
  40. if ( strlen(path) < key_len ) {
  41. DEBUG(0,("trim_reg_path: Registry path too short! [%s]\n", path));
  42. return NULL;
  43. }
  44. p = path + strlen( KEY_SHARES );
  45. if ( *p == '\\' )
  46. p++;
  47. if ( *p )
  48. return SMB_STRDUP(p);
  49. else
  50. return NULL;
  51. }
  52. /**********************************************************************
  53. Enumerate registry subkey names given a registry path.
  54. Caller is responsible for freeing memory to **subkeys
  55. *********************************************************************/
  56. static int shares_subkey_info( const char *key, struct regsubkey_ctr *subkey_ctr )
  57. {
  58. char *path;
  59. bool top_level = False;
  60. int num_subkeys = 0;
  61. DEBUG(10,("printing_subkey_info: key=>[%s]\n", key));
  62. path = trim_reg_path( key );
  63. /* check to see if we are dealing with the top level key */
  64. if ( !path )
  65. top_level = True;
  66. if ( top_level ) {
  67. num_subkeys = 1;
  68. regsubkey_ctr_addkey( subkey_ctr, "Security" );
  69. }
  70. #if 0
  71. else
  72. num_subkeys = handle_share_subpath( path, subkey_ctr, NULL );
  73. #endif
  74. SAFE_FREE( path );
  75. return num_subkeys;
  76. }
  77. /**********************************************************************
  78. Enumerate registry values given a registry path.
  79. Caller is responsible for freeing memory
  80. *********************************************************************/
  81. static int shares_value_info(const char *key, struct regval_ctr *val)
  82. {
  83. char *path;
  84. bool top_level = False;
  85. int num_values = 0;
  86. DEBUG(10,("printing_value_info: key=>[%s]\n", key));
  87. path = trim_reg_path( key );
  88. /* check to see if we are dealing with the top level key */
  89. if ( !path )
  90. top_level = True;
  91. /* fill in values from the getprinterdata_printer_server() */
  92. if ( top_level )
  93. num_values = 0;
  94. #if 0
  95. else
  96. num_values = handle_printing_subpath( path, NULL, val );
  97. #endif
  98. SAFE_FREE(path);
  99. return num_values;
  100. }
  101. /**********************************************************************
  102. Stub function which always returns failure since we don't want
  103. people storing printing information directly via regostry calls
  104. (for now at least)
  105. *********************************************************************/
  106. static bool shares_store_subkey( const char *key, struct regsubkey_ctr *subkeys )
  107. {
  108. return False;
  109. }
  110. /**********************************************************************
  111. Stub function which always returns failure since we don't want
  112. people storing printing information directly via regostry calls
  113. (for now at least)
  114. *********************************************************************/
  115. static bool shares_store_value(const char *key, struct regval_ctr *val)
  116. {
  117. return False;
  118. }
  119. /*
  120. * Table of function pointers for accessing printing data
  121. */
  122. struct registry_ops shares_reg_ops = {
  123. .fetch_subkeys = shares_subkey_info,
  124. .fetch_values = shares_value_info,
  125. .store_subkeys = shares_store_subkey,
  126. .store_values = shares_store_value,
  127. };