Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.6 KiB

  1. //#pragma title( "SDRCommon.cpp - SDResolve: Common routines for sdresolve" )
  2. /*
  3. Copyright (c) 1995-1998, Mission Critical Software, Inc. All rights reserved.
  4. ===============================================================================
  5. Module - sdrCommon.cpp
  6. System - Domain Consolidation Toolkit
  7. Author - Christy Boles
  8. Created - 97/07/11
  9. Description - Command line parsing, help text, and utilities for EADCFILE and EADCEXCH
  10. Updates -
  11. ===============================================================================
  12. */
  13. #include "stdafx.h"
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <iostream.h>
  17. #include <fstream.h>
  18. #include <assert.h>
  19. #include <lm.h>
  20. #include <lmwksta.h>
  21. #include "Common.hpp"
  22. #include "ErrDct.hpp"
  23. #include "UString.hpp"
  24. #include "sd.hpp"
  25. #include "SecObj.hpp"
  26. #include "sidcache.hpp"
  27. #include "enumvols.hpp"
  28. #include "ealen.hpp"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. extern TErrorDct err;
  35. bool ignoreall;
  36. extern bool enforce;
  37. bool silent;
  38. extern bool ContainsWildcard(WCHAR const * name);
  39. #define MAX_BUFFER_LENGTH 10000
  40. int ColonIndex(TCHAR * str)
  41. {
  42. if ( ! str )
  43. return 0;
  44. int i;
  45. for (i = 0 ; str[i] && str[i] != ':' ; i++)
  46. ;
  47. if ( str[i] != ':' )
  48. i = 0;
  49. return i;
  50. }
  51. WCHAR * // ret -machine-name prefix of pathname if pathname is a UNC path, otherwise returns NULL
  52. GetMachineName(
  53. const LPWSTR pathname // in -pathname from which to extract machine name
  54. )
  55. {
  56. int i;
  57. WCHAR * machinename = NULL;
  58. if ( pathname
  59. && pathname[0] == L'\\'
  60. && pathname[1] == L'\\'
  61. )
  62. {
  63. for ( i = 2 ; pathname[i] && pathname[i] != L'\\' ; i++ )
  64. ;
  65. machinename = new WCHAR[i+2];
  66. if(!machinename)
  67. {
  68. // memory allocation failed, just return NULL
  69. return machinename;
  70. }
  71. UStrCpy(machinename,pathname,i+1);
  72. machinename[i] = 0;
  73. }
  74. return machinename;
  75. }
  76. int EqualSignIndex(char * str)
  77. {
  78. if ( ! str )
  79. return 0;
  80. int i;
  81. for (i = 0 ; str[i] && str[i] != '=' ; i++)
  82. ;
  83. if ( str[i] != '=' )
  84. i = 0;
  85. return i;
  86. }
  87. BOOL BuiltinRid(DWORD rid)
  88. {
  89. // returns TRUE if rid is the rid of a builtin account
  90. BOOL result;
  91. // 500 Administrator
  92. // 501 Guest
  93. // 512 Domain Admins
  94. // 513 Domain Users
  95. // 514 Domain Guests
  96. // 544 Administrators
  97. // 545 Users
  98. // 546 Guests
  99. // 547 Power Users
  100. // 548 Account Operators
  101. // 549 Server Operators
  102. // 550 Print Operators
  103. // 551 Backup Operators
  104. // 552 Replicator
  105. if ( rid < 500 )
  106. return TRUE;
  107. switch ( rid )
  108. {
  109. case DOMAIN_USER_RID_ADMIN:
  110. case DOMAIN_USER_RID_GUEST:
  111. case DOMAIN_ALIAS_RID_ADMINS:
  112. case DOMAIN_ALIAS_RID_USERS:
  113. case DOMAIN_ALIAS_RID_GUESTS:
  114. case DOMAIN_ALIAS_RID_POWER_USERS:
  115. case DOMAIN_ALIAS_RID_ACCOUNT_OPS:
  116. case DOMAIN_ALIAS_RID_SYSTEM_OPS:
  117. case DOMAIN_ALIAS_RID_PRINT_OPS:
  118. case DOMAIN_ALIAS_RID_BACKUP_OPS:
  119. case DOMAIN_ALIAS_RID_REPLICATOR:
  120. result = TRUE;
  121. break;
  122. default:
  123. result = FALSE;
  124. }
  125. return result;
  126. }