1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
|
%{
/* ----------------------------------------------------------------------- *
*
* master_tok.l - master map tokenizer.
*
* Copyright 2006 Ian Kent <raven@themaw.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
* USA; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ----------------------------------------------------------------------- */
#ifdef ECHO
# undef ECHO
#endif /* ECHO */
static void master_echo(void); /* forward definition */
#define ECHO master_echo()
static void master_error(char *s);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "master_parse.tab.h"
/*
* There are some things that need to be defined only if useing GNU flex.
* These must not be defined if using standard lex
*/
#ifdef FLEX_SCANNER
int master_lineno;
#endif
int master_lex(void);
int master_wrap(void);
/* no need for yywrap() */
#define YY_SKIP_YYWRAP
#ifndef YY_STACK_USED
#define YY_STACK_USED 0
#endif
#ifndef YY_ALWAYS_INTERACTIVE
#define YY_ALWAYS_INTERACTIVE 0
#endif
#ifndef YY_NEVER_INTERACTIVE
#define YY_NEVER_INTERACTIVE 0
#endif
#ifndef YY_MAIN
#define YY_MAIN 0
#endif
void master_set_scan_buffer(const char *);
const char *line = NULL;
#ifdef FLEX_SCANNER
const char *line_pos = NULL;
const char *line_lim = NULL;
int my_yyinput(char *, int);
#undef YY_INPUT
#define YY_INPUT(b, r, ms) (r = my_yyinput(b, ms))
#else
#undef input
#undef unput
#define input() (*(char *) line++)
#define unput(c) (*(char *) --line = c)
#endif
#define BUFF_LEN 1024
char buff[BUFF_LEN];
char *bptr;
char *optr = buff;
unsigned int tlen;
#define STRTYPE_LEN 2048
%}
%option nounput
%x PATHSTR MAPSTR DNSTR OPTSTR OCTAL
WS [[:blank:]]+
OPTWS [[:blank:]]*
NL \r?\n
CONT \\\n{OPTWS}
OPTIONSTR ([\-]?([[:alpha:]_]([[:alnum:]_\-])*(=(\"?([[:alnum:]_\-\:\.])+\"?))?)+)
MACROSTR (-D{OPTWS}([[:alpha:]_]([[:alnum:]_\-\.])*)=([[:alnum:]_\-\.])+)
SLASHIFYSTR (--(no-)?slashify-colons)
NUMBER [0-9]+
OCTALNUMBER [0-7]+
DNSERVSTR1 ([[:alpha:]][[:alnum:]\-.]*(:[0-9]+)?:)
DNSERVSTR2 (\[([[:xdigit:]]:.)+\](:[0-9]+)?:)
DNSERVSTR3 (\/\/[[:alpha:]][[:alnum:]\-.]*(:[0-9]+)?\/)
DNSERVSTR4 (\/\/\[([[:xdigit:]]:.)+\](:[0-9]+)?\/)
DNSERVSTR5 (([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}(:[0-9]+)?:)
DNSERVSTR6 (\/\/([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}(:[0-9]+)?\/)
DNSERVERSTR ({DNSERVSTR1}|{DNSERVSTR2}|{DNSERVSTR3}|{DNSERVSTR4}|{DNSERVSTR5}|{DNSERVSTR6})
AT_CN ([cC][[nN])
AT_NMN ([nN][iI][sS][Mm][aA][pP][Nn][aA][mM][eE])
AT_AMN ([aA][uU][tT][oO][mM][oO][uU][nN][tT][Mm][aA][pP][Nn][aA][mM][eE])
AT_OU ([oO][[uU])
AT_DC ([dD][[cC])
AT_O ([oO])
AT_C ([cC])
AT_L ([lL])
DNATTRSTR ({AT_CN}|{AT_NMN}|{AT_AMN}|{AT_OU}|{AT_DC}|{AT_O}|{AT_C}|{AT_L})
DNNAMESTR1 ([[:alnum:]_.\- ]+)
DNNAMESTR2 ([[:alnum:]_.\-]+)
INTMAP (-hosts|-null)
MULTI ((multi)(,(sun|hesiod))?(:{OPTWS}|{WS}))
MULTISEP ([\-]{2}[[:blank:]]+)
MTYPE ((file|program|exec|sss|yp|nis|nisplus|ldap|ldaps|hesiod|userdir)(,(sun|hesiod|amd))?(:{OPTWS}|{WS}))
OPTTOUT (-t{OPTWS}|-t{OPTWS}={OPTWS}|--timeout{OPTWS}|--timeout{OPTWS}={OPTWS})
OPTNTOUT (-n{OPTWS}|-n{OPTWS}={OPTWS}|--negative-timeout{OPTWS}|--negative-timeout{OPTWS}={OPTWS})
MODE (--mode{OPTWS}|--mode{OPTWS}={OPTWS})
%%
<INITIAL>{
{NL} |
\x00 {
if (optr != buff) {
*optr = '\0';
strcpy(master_lval.strtype, buff);
return NILL;
}
}
#.* { return COMMENT; }
"/" {
if (optr != buff) {
*optr = '\0';
strcpy(master_lval.strtype, buff);
return NILL;
}
BEGIN(PATHSTR);
bptr = buff;
yyless(0);
}
. { *optr++ = *master_text; }
}
<PATHSTR>{
\x00 {
BEGIN(INITIAL);
*bptr++ = *master_text;
strcpy(master_lval.strtype, buff);
return NILL;
}
\\. { *bptr++ = *(master_text + 1); }
\" {
BEGIN(INITIAL);
*bptr++ = *master_text;
*bptr = '\0';
strcpy(master_lval.strtype, buff);
return QUOTE;
}
{WS} {
BEGIN(MAPSTR);
*bptr = '\0';
strcpy(master_lval.strtype, buff);
bptr = buff;
memset(buff, 0, BUFF_LEN);
return(PATH);
}
<<EOF>> {
BEGIN(INITIAL);
*bptr = '\0';
strcpy(master_lval.strtype, buff);
return(PATH);
}
{NL} {
BEGIN(INITIAL);
*bptr = '\0';
strcpy(master_lval.strtype, buff);
return PATH;
}
. { *bptr++ = *master_text; }
}
<MAPSTR>{
{OPTWS}\\\n{OPTWS} {}
{MULTI} {
tlen = master_leng - 1;
if (bptr != buff && isblank(master_text[tlen])) {
/*
* We can't handle unescaped white space in map names
* so just eat the white space. We always have the
* "multi" at the beginning of the string so the while
* will not fall off the end.
*/
while (isblank(master_text[tlen - 1]))
tlen--;
strncat(buff, master_text, tlen);
bptr += tlen;
yyless(tlen);
} else {
if (tlen <= STRTYPE_LEN)
strcpy(master_lval.strtype, master_text);
else {
master_error("MULTITYPE: value too large, truncated");
strncpy(master_lval.strtype, master_text, STRTYPE_LEN - 2);
master_lval.strtype[STRTYPE_LEN - 1] = 0;
}
return(MULTITYPE);
}
}
{MTYPE} |
{MTYPE}/{DNSERVERSTR}{DNATTRSTR}= |
{MTYPE}/{DNATTRSTR}= {
tlen = master_leng - 1;
if (bptr != buff && isblank(master_text[tlen])) {
/*
* We can't handle unescaped white space in map names
* so just eat the white space. We always have the
* maptype keyword at the beginning of the string so
* the while will not fall off the end.
*/
while (isblank(master_text[tlen - 1]))
tlen--;
strncat(buff, master_text, tlen);
bptr += tlen;
yyless(tlen);
} else {
if (tlen <= STRTYPE_LEN)
strcpy(master_lval.strtype, master_text);
else {
master_error("MAPTYPE: value too large, truncated");
strncpy(master_lval.strtype, master_text, STRTYPE_LEN - 2);
master_lval.strtype[STRTYPE_LEN - 1] = 0;
}
return(MAPTYPE);
}
}
{MULTISEP} { return(DDASH); }
":" { return(COLON); }
"-hosts" {
BEGIN(OPTSTR);
strcpy(master_lval.strtype, master_text);
return MAPHOSTS;
}
"-null" {
BEGIN(OPTSTR);
strcpy(master_lval.strtype, master_text);
return MAPNULL;
}
"-xfn" {
/*
* The X/Open Federated Naming service isn't supported
* and the parser will call YYABORT() when it sees the
* MAPXFN token so we must set the start state to the
* INITIAL state here for the next yylex() call.
*/
BEGIN(INITIAL);
strcpy(master_lval.strtype, master_text);
return MAPXFN;
}
"//" {
BEGIN(DNSTR);
yyless(0);
}
{DNSERVERSTR}{DNATTRSTR}= {
BEGIN(DNSTR);
yyless(0);
}
{DNATTRSTR}= {
BEGIN(DNSTR);
yyless(0);
}
{OPTWS}/{NL} {
BEGIN(INITIAL);
*bptr = '\0';
strcpy(master_lval.strtype, buff);
bptr = buff;
return(MAPNAME);
}
\\. { *bptr++ = *(master_text + 1); }
{WS} {
BEGIN(OPTSTR);
*bptr = '\0';
strcpy(master_lval.strtype, buff);
bptr = buff;
return(MAPNAME);
}
{NL} |
\x00 {
BEGIN(INITIAL);
*bptr = '\0';
strcpy(master_lval.strtype, buff);
return(MAPNAME);
}
<<EOF>> {
BEGIN(INITIAL);
*bptr = '\0';
strcpy(master_lval.strtype, buff);
return(MAPNAME);
}
. { *bptr++ = *master_text; }
}
<DNSTR>{
{OPTWS}\\\n{OPTWS} {}
{DNSERVERSTR} {
if (master_leng < STRTYPE_LEN)
strcpy(master_lval.strtype, master_text);
else {
master_error("DNSERVER: value too large, truncated");
strncpy(master_lval.strtype, master_text, STRTYPE_LEN - 2);
master_lval.strtype[STRTYPE_LEN - 1] = 0;
}
return DNSERVER;
}
{DNATTRSTR}/"=" {
if (master_leng < STRTYPE_LEN)
strcpy(master_lval.strtype, master_text);
else {
master_error("DNATTR: value too large, truncated");
strncpy(master_lval.strtype, master_text, STRTYPE_LEN - 2);
master_lval.strtype[STRTYPE_LEN - 1] = 0;
}
return DNATTR;
}
"=" {
return EQUAL;
}
{DNNAMESTR1}/","{DNATTRSTR}"=" {
if (master_leng < STRTYPE_LEN)
strcpy(master_lval.strtype, master_text);
else {
master_error("DNNAME: value too large, truncated");
strncpy(master_lval.strtype, master_text, STRTYPE_LEN - 2);
master_lval.strtype[STRTYPE_LEN - 1] = 0;
}
return DNNAME;
}
{DNNAMESTR2} {
if (master_leng < STRTYPE_LEN)
strcpy(master_lval.strtype, master_text);
else {
master_error("DNNAME: value too large, truncated");
strncpy(master_lval.strtype, master_text, STRTYPE_LEN - 2);
master_lval.strtype[STRTYPE_LEN - 1] = 0;
}
return DNNAME;
}
{OPTWS}","{OPTWS} {
return COMMA;
}
{WS}"=" |
"="{WS} {
BEGIN(INITIAL);
if (master_leng < STRTYPE_LEN)
strcpy(master_lval.strtype, master_text);
else {
master_error("SPACE: value too large, truncated");
strncpy(master_lval.strtype, master_text, STRTYPE_LEN - 2);
master_lval.strtype[STRTYPE_LEN - 1] = 0;
}
return SPACE;
}
{WS} { BEGIN(OPTSTR); }
{NL} |
\x00 { BEGIN(INITIAL); }
<<EOF>> { BEGIN(INITIAL); }
}
<OPTSTR>{
{OPTWS}\\\n{OPTWS} {}
{MULTISEP} {
BEGIN(MAPSTR);
return(DDASH);
}
{OPTTOUT}/{NUMBER} { return(OPT_TIMEOUT); }
{OPTNTOUT}/{NUMBER} { return(OPT_NTIMEOUT); }
{NUMBER} {
master_lval.longtype = atol(master_text);
return(NUMBER);
}
-?symlink { return(OPT_SYMLINK); }
-?nobind { return(OPT_NOBIND); }
-?nobrowse { return(OPT_NOGHOST); }
-?shared { return(OPT_SHARED); }
-?slave { return(OPT_SLAVE); }
-?private { return(OPT_PRIVATE); }
-?strictexpire { return(OPT_STRICTEXPIRE); }
-g|--ghost|-?browse { return(OPT_GHOST); }
-v|--verbose { return(OPT_VERBOSE); }
-d|--debug { return(OPT_DEBUG); }
-w|--use-weight-only { return(OPT_USE_WEIGHT); }
-r|--random-multimount-selection { return(OPT_RANDOM); }
{MODE}/{OCTALNUMBER} {
BEGIN(OCTAL);
return(OPT_MODE);
}
{OPTWS}","{OPTWS} { return(COMMA); }
{OPTWS} {}
{SLASHIFYSTR} {
strcpy(master_lval.strtype, master_text);
return(OPTION);
}
{MACROSTR} {
strcpy(master_lval.strtype, master_text);
return(OPTION);
}
{OPTIONSTR} {
if (master_leng < STRTYPE_LEN)
strcpy(master_lval.strtype, master_text);
else {
master_error("OPTION: value too large, truncated");
strncpy(master_lval.strtype, master_text, STRTYPE_LEN - 2);
master_lval.strtype[STRTYPE_LEN - 1] = 0;
}
return(OPTION);
}
"=" {
strcpy(master_lval.strtype, master_text);
return(EQUAL);
}
{WS} {}
{NL} |
\x00 { BEGIN(INITIAL); }
<<EOF>> { BEGIN(INITIAL); }
}
<OCTAL>{
{OCTALNUMBER} {
master_lval.longtype = strtoul(master_text, NULL, 8);
return(OCTALNUMBER);
}
. { BEGIN(OPTSTR); yyless(0); }
}
%%
#include "automount.h"
int master_wrap(void)
{
return 1;
}
static void master_echo(void)
{
logmsg("%s", master_text);
return;
}
static void master_error(char *s)
{
logmsg("%s");
return;
}
#ifdef FLEX_SCANNER
void master_set_scan_buffer(const char *buffer)
{
memset(buff, 0, sizeof(buff));
optr = buff;
YY_FLUSH_BUFFER;
line = buffer;
line_pos = &line[0];
/*
* Ensure buffer is 1 greater than string and is zeroed before
* the parse so we can fit the extra NULL which allows us to
* explicitly match an end of line within the buffer (ie. the
* need for 2 NULLS when parsing in memeory buffers).
*/
line_lim = line + strlen(buffer) + 1;
}
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
int my_yyinput(char *buffer, int max_size)
{
int n = min(max_size, line_lim - line_pos);
if (n > 0) {
memcpy(buffer, line_pos, n);
line_pos += n;
}
return n;
}
#else
void master_set_scan_buffer(const char *buffer)
{
line = buffer;
}
#endif
|