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.

430 lines
9.3 KiB

  1. %{
  2. /*++
  3. Copyright (c) 2000 Microsoft Corporation
  4. Module Name:
  5. adl.y/adlparser.cpp
  6. Abstract:
  7. YACC parser definition for the ADL language
  8. AdlParser::ParseAdl() function
  9. Author:
  10. t-eugenz - August 2000
  11. Environment:
  12. User mode only.
  13. Revision History:
  14. Created - August 2000
  15. --*/
  16. #include "pch.h"
  17. #include "adl.h"
  18. //
  19. // YACC generates some long->short automatic conversion, disable the warning
  20. //
  21. #pragma warning(disable : 4242)
  22. //
  23. // ISSUE-2000/08/28-t-eugenz
  24. // This is a private netlib function.
  25. //
  26. extern "C" NET_API_STATUS
  27. NetpwNameValidate(
  28. IN LPTSTR Name,
  29. IN DWORD NameType,
  30. IN DWORD Flags
  31. );
  32. //
  33. // Name types for I_NetName* and I_NetListCanonicalize
  34. //
  35. #define NAMETYPE_USER 1
  36. #define NAMETYPE_PASSWORD 2
  37. #define NAMETYPE_GROUP 3
  38. #define NAMETYPE_COMPUTER 4
  39. #define NAMETYPE_EVENT 5
  40. #define NAMETYPE_DOMAIN 6
  41. #define NAMETYPE_SERVICE 7
  42. #define NAMETYPE_NET 8
  43. #define NAMETYPE_SHARE 9
  44. #define NAMETYPE_MESSAGE 10
  45. #define NAMETYPE_MESSAGEDEST 11
  46. #define NAMETYPE_SHAREPASSWORD 12
  47. #define NAMETYPE_WORKGROUP 13
  48. //
  49. // Validate various tokens, with error handling
  50. // have to cast away const, since NetpNameValidate takes a non-const for some
  51. // reason
  52. //
  53. #define VALIDATE_USERNAME(TOK) \
  54. if( NetpwNameValidate( \
  55. (WCHAR *)(TOK)->GetValue(), \
  56. NAMETYPE_USER, \
  57. 0) != ERROR_SUCCESS) \
  58. { \
  59. this->SetErrorToken( TOK ); \
  60. throw AdlStatement::ERROR_INVALID_USERNAME; \
  61. }
  62. #define VALIDATE_DOMAIN(TOK) \
  63. if( NetpwNameValidate( \
  64. (WCHAR *)(TOK)->GetValue(), \
  65. NAMETYPE_DOMAIN, \
  66. 0) != ERROR_SUCCESS) \
  67. { \
  68. this->SetErrorToken( TOK ); \
  69. throw AdlStatement::ERROR_INVALID_DOMAIN; \
  70. }
  71. #define VALIDATE_PERMISSION(TOK) \
  72. { \
  73. for(DWORD i = 0;; i++) \
  74. { \
  75. if( (_pControl->pPermissions)[i].str == NULL ) \
  76. { \
  77. this->SetErrorToken( TOK ); \
  78. throw AdlStatement::ERROR_UNKNOWN_PERMISSION; \
  79. } \
  80. if(!_wcsicmp(TOK->GetValue(), \
  81. (_pControl->pPermissions)[i].str)) \
  82. { \
  83. break; \
  84. } \
  85. } \
  86. }
  87. //
  88. // YACC value type
  89. //
  90. #define YYSTYPE AdlToken *
  91. //
  92. // YACC error handler: raise an exception
  93. //
  94. void yyerror(char *szErr)
  95. {
  96. throw AdlStatement::ERROR_NOT_IN_LANGUAGE;
  97. }
  98. %}
  99. %token TK_ERROR
  100. %token TK_IDENT
  101. %token TK_AT
  102. %token TK_SLASH
  103. %token TK_PERIOD
  104. %token TK_COMMA
  105. %token TK_OPENPAREN
  106. %token TK_CLOSEPAREN
  107. %token TK_SEMICOLON
  108. %token TK_EXCEPT
  109. %token TK_ON
  110. %token TK_ALLOWED
  111. %token TK_AND
  112. %token TK_AS
  113. %token TK_THIS_OBJECT
  114. %token TK_CONTAINERS
  115. %token TK_OBJECTS
  116. %token TK_CONTAINERS_OBJECTS
  117. %token TK_NO_PROPAGATE
  118. %token TK_LANG_ENGLISH
  119. %token TK_LANG_REVERSE
  120. %start ADL
  121. %%
  122. ADL:
  123. TK_LANG_ENGLISH ACRULE_LIST_ENGLISH
  124. {
  125. //
  126. // At the end of all ADL_STATEMENT's
  127. // pop the extra AdlTree that was pushed
  128. // on when the last ADL_STATEMENT
  129. // was completed
  130. //
  131. this->PopEmpty();
  132. }
  133. |
  134. TK_LANG_REVERSE ACRULE_LIST_REVERSE
  135. {
  136. //
  137. // At the end of all ADL_STATEMENT's
  138. // pop the extra AdlTree that was pushed
  139. // on when the last ADL_STATEMENT
  140. // was completed
  141. //
  142. this->PopEmpty();
  143. }
  144. ;
  145. ACRULE_LIST_ENGLISH:
  146. ACRULE_ENGLISH
  147. |
  148. ACRULE_LIST_ENGLISH ACRULE_ENGLISH
  149. ;
  150. ACRULE_ENGLISH:
  151. SEC_PRINCIPAL_LIST TK_OPENPAREN TK_EXCEPT EX_SEC_PRINCIPAL_LIST
  152. TK_CLOSEPAREN TK_ALLOWED PERMISSION_LIST
  153. TK_ON OBJECT_SPEC TK_SEMICOLON
  154. {
  155. this->Next();
  156. }
  157. |
  158. SEC_PRINCIPAL_LIST TK_ALLOWED PERMISSION_LIST
  159. TK_ON OBJECT_SPEC TK_SEMICOLON
  160. {
  161. this->Next();
  162. }
  163. ;
  164. ACRULE_LIST_REVERSE:
  165. ACRULE_REVERSE
  166. |
  167. ACRULE_LIST_REVERSE ACRULE_REVERSE
  168. ;
  169. ACRULE_REVERSE:
  170. TK_OPENPAREN TK_EXCEPT EX_SEC_PRINCIPAL_LIST
  171. TK_CLOSEPAREN SEC_PRINCIPAL_LIST TK_ALLOWED PERMISSION_LIST
  172. TK_ON OBJECT_SPEC TK_SEMICOLON
  173. {
  174. this->Next();
  175. }
  176. |
  177. SEC_PRINCIPAL_LIST TK_ALLOWED PERMISSION_LIST
  178. TK_ON OBJECT_SPEC TK_SEMICOLON
  179. {
  180. this->Next();
  181. }
  182. ;
  183. SEC_PRINCIPAL_LIST:
  184. SEC_PRINCIPAL
  185. {
  186. this->Cur()->AddPrincipal( $1 );
  187. }
  188. |
  189. SEC_PRINCIPAL_LIST TK_COMMA SEC_PRINCIPAL
  190. {
  191. this->Cur()->AddPrincipal( $3 );
  192. }
  193. |
  194. SEC_PRINCIPAL_LIST TK_AND SEC_PRINCIPAL
  195. {
  196. this->Cur()->AddPrincipal( $3 );
  197. }
  198. ;
  199. EX_SEC_PRINCIPAL_LIST:
  200. SEC_PRINCIPAL
  201. {
  202. this->Cur()->AddExPrincipal( $1 );
  203. }
  204. |
  205. EX_SEC_PRINCIPAL_LIST TK_COMMA SEC_PRINCIPAL
  206. {
  207. this->Cur()->AddExPrincipal( $3 );
  208. }
  209. |
  210. EX_SEC_PRINCIPAL_LIST TK_AND SEC_PRINCIPAL
  211. {
  212. this->Cur()->AddExPrincipal( $3 );
  213. }
  214. ;
  215. PERMISSION_LIST:
  216. PERMISSION
  217. {
  218. this->Cur()->AddPermission( $1 );
  219. }
  220. |
  221. PERMISSION_LIST TK_AND PERMISSION
  222. {
  223. this->Cur()->AddPermission( $3 );
  224. }
  225. |
  226. PERMISSION_LIST TK_COMMA PERMISSION
  227. {
  228. this->Cur()->AddPermission( $3 );
  229. }
  230. ;
  231. PERMISSION:
  232. IDENTIFIER
  233. {
  234. VALIDATE_PERMISSION($1);
  235. }
  236. ;
  237. OBJECT_SPEC:
  238. OBJECT
  239. |
  240. OBJECT_SPEC TK_AND OBJECT
  241. |
  242. OBJECT_SPEC TK_COMMA OBJECT
  243. ;
  244. SEC_PRINCIPAL:
  245. SUB_PRINCIPAL
  246. |
  247. SUB_PRINCIPAL TK_AS SUB_PRINCIPAL
  248. {
  249. //
  250. // For now, impersonation is not supported
  251. //
  252. throw AdlStatement::ERROR_IMPERSONATION_UNSUPPORTED;
  253. }
  254. ;
  255. SUB_PRINCIPAL:
  256. IDENTIFIER TK_AT DOMAIN
  257. {
  258. VALIDATE_USERNAME($1);
  259. VALIDATE_DOMAIN($3);
  260. AdlToken *newTok = new AdlToken($1->GetValue(),
  261. $3->GetValue(),
  262. $1->GetStart(),
  263. $3->GetEnd());
  264. this->AddToken(newTok);
  265. $$ = newTok;
  266. }
  267. |
  268. DOMAIN TK_SLASH IDENTIFIER
  269. {
  270. VALIDATE_USERNAME($3);
  271. VALIDATE_DOMAIN($1);
  272. AdlToken *newTok = new AdlToken($3->GetValue(),
  273. $1->GetValue(),
  274. $1->GetStart(),
  275. $3->GetEnd());
  276. this->AddToken(newTok);
  277. $$ = newTok;
  278. }
  279. |
  280. IDENTIFIER
  281. {
  282. VALIDATE_USERNAME($1);
  283. $$ = $1;
  284. }
  285. ;
  286. DOMAIN:
  287. IDENTIFIER
  288. |
  289. DOMAIN TK_PERIOD IDENTIFIER
  290. {
  291. //
  292. // Concatenate into single domain string
  293. //
  294. wstring newStr;
  295. newStr.append($1->GetValue());
  296. newStr.append($2->GetValue());
  297. newStr.append($3->GetValue());
  298. AdlToken *newTok = new AdlToken(newStr.c_str(),
  299. $1->GetStart(),
  300. $1->GetEnd());
  301. this->AddToken(newTok);
  302. $$ = newTok;
  303. }
  304. ;
  305. OBJECT:
  306. TK_THIS_OBJECT
  307. {
  308. this->Cur()->UnsetFlags(INHERIT_ONLY_ACE);
  309. }
  310. |
  311. TK_CONTAINERS
  312. {
  313. this->Cur()->SetFlags(CONTAINER_INHERIT_ACE);
  314. }
  315. |
  316. TK_OBJECTS
  317. {
  318. this->Cur()->SetFlags(OBJECT_INHERIT_ACE);
  319. }
  320. |
  321. TK_CONTAINERS_OBJECTS
  322. {
  323. this->Cur()->SetFlags(CONTAINER_INHERIT_ACE);
  324. this->Cur()->SetFlags(OBJECT_INHERIT_ACE);
  325. }
  326. |
  327. TK_NO_PROPAGATE
  328. {
  329. this->Cur()->SetFlags(NO_PROPAGATE_INHERIT_ACE);
  330. }
  331. ;
  332. IDENTIFIER:
  333. TK_IDENT
  334. |
  335. TK_ALLOWED
  336. |
  337. TK_AND
  338. |
  339. TK_AS
  340. |
  341. TK_EXCEPT
  342. |
  343. TK_ON
  344. |
  345. TK_ERROR
  346. {
  347. //
  348. // This should never happen
  349. //
  350. throw AdlStatement::ERROR_FATAL_LEXER_ERROR;
  351. }
  352. ;
  353. %%