[rancid] #' in my login banner

Jan Dahl jan at spacepope.dk
Tue Dec 24 21:46:13 UTC 2013


I’ll try it out after the holidays and the ensuing fires that need to put out. Thanks! :)

Kind regards,
Jan 

> Date: Tue, 24 Dec 2013 06:59:47 +0000
> From: heasley <heas at shrubbery.net>
> To: Alan McKinnon <alan.mckinnon at gmail.com>
> Cc: rancid-discuss at shrubbery.net
> Subject: Re: [rancid] #' in my login banner
> Message-ID: <20131224065947.GC12140 at shrubbery.net>
> Content-Type: text/plain; charset=iso-8859-1
> 
> Thu, Dec 19, 2013 at 11:48:57AM +0200, Alan McKinnon:
>> One possibility is to ignore any line with 2 or more #, and assume that
>> it's a banner. This is the command case.
>> 
>> Login and command prompts contain ">" or "#", but always only one.
>> 
>> This way, code can discard lines that are known to NOT be the prompt.
>> It's not 100% failproof but it is an improvement over the blind match we
>> currently have.
>> 
>> 
>> On 19/12/2013 10:26, Jan Dahl wrote:
>>> Maybe if we could somehow define an "ignored" string? I have a couple
>>> of thousand switches with this in the login banner, which I won't be
>>> allowed to change any time soon:
>>> 
>>>                  ######    ######   #     #
>>>                  #     #   #        #     #
>>>                  #     #   ######    #   #
>>>                  #     #        #     # #
>>>                  ######    ######      #
>>> 
>>> Is it un-clever? Indeed! But it has been rolled out world wide before
>>> I started here and now I can't use rancid.
>>> 
>>> The really weird thing for me is that somehow, terminal length and
>>> width are set at the right time, but none of my commands are pushed
>>> after that.
>>> 
>>> Kind regards,
>>> 
>>> Jan
>>> 
>>> On Wed Dec 11 18:24:32 UTC 2013, Allan McKinnon wrote:
>>> 
>>> On 11/12/2013 20:14, Per-Olof Olsson wrote:
>>>> Hello
>>>> 
>>>> 
>>>> 
>>>> 
>>>> On 12/11/2013 06:51 PM, Alan McKinnon wrote:
>>>>> I see no-one has responded with an answer to your question.
>>>>> 
>>>>> I think the reason is that code cannot deal with ">" and "#" characters
>>>>> in a banner in any sane way that gives consistent results. For rancid to
>>>>> function properly, it has to know what the shell prompt is exactly for a
>>>>> given device, and to do that it has to parse the entire text output.
>>>>> 
>>>>> The only tool available to detect the prompt is pattern matching which
>>>>> inevitably means a regex. As a perl regex this is
>>>>> 
>>>>> ^[-a-zA-Z0-9]*[>#]
>>>>> 
>>>>> and that's assuming the prompt is the hostname.
>>>> 
>>>> In hlogin I added
>>>> 
>>>> -re "\[#>]+.*\[\n\r]+" {
>>>> exp_continue
>>>> }
>>>> 
>>>> to just pass over none prompter # and >.
>>>> Banner "#" and ">" is followed by CR or NL!
>>> 
>>> 
>>> 
>>> Only if the banner has a surrounding box made of > or #
>>> 
>>> One can always come up with a scheme that just happens to work for
>>> oneself because local rules specify some exact format where you can get
>>> a regex to work for you.
>>> 
>>> That's a lot of work though. I find it easier to just change the banner.
>>> 
>>> 
>>> 
>>> 
>>>> 
>>>> Works for HPs
>>>> 
>>>> /Peo
>>>> ----------------------------------------------------------
>>>> Per-Olof Olsson               Email: peo at chalmers.se
>>>> Chalmers tekniska h?gskola    IT-service
>>>> H?rsalsv?gen 5                412 96 G?teborg
>>>> Tel: 031/772 6738  Fax: 031/772 8660
>>>> ----------------------------------------------------------
>>>> _______________________________________________
>>>> Rancid-discuss mailing list
>>>> Rancid-discuss at shrubbery.net
>>>> http://www.shrubbery.net/mailman/listinfo/rancid-discuss
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
>> -- 
>> Alan McKinnon
>> alan.mckinnon at gmail.com
>> 
>> _______________________________________________
>> Rancid-discuss mailing list
>> Rancid-discuss at shrubbery.net
>> http://www.shrubbery.net/mailman/listinfo/rancid-discuss
> 
> This adds a 'prompt', or i suppose "initial prompt", directive to cloginrc,
> so something like this could be added to cloginrc:
> 
> 	add prompt hostglob	{^[^\n\r#]+#}
> 
> it still has an odor from my pov, but it would work for the case at hand.
> 
> Index: bin/clogin.in
> ===================================================================
> --- bin/clogin.in	(revision 2761)
> +++ bin/clogin.in	(working copy)
> @@ -581,6 +581,7 @@
> 				  send_user "\nError: Invalid login: $router\n";
> 				  catch {close}; catch {wait}; return 1
> 				}
> +	-re "\[^\r\n]*\[\r\n]+"	{ exp_continue; }
>      }
>     }
> 
> @@ -763,7 +764,10 @@
>     }
> 
>     # Default prompt.
> -    set prompt "(>|#| \\(enable\\))"
> +    set prompt [join [find prompt $router] ""]
> +    if { [llength $prompt] == 0 } {
> +	set prompt "(>|#| \\(enable\\))"
> +    }
> 
>     # look for noenable option in .cloginrc
>     if { [find noenable $router] == "1" } {
> @@ -902,9 +906,10 @@
>     }
>     # we are logged in, now figure out the full prompt
>     send "\r"
> +    regsub -all {^(\^*)(.*)} $prompt {\2} reprompt
>     expect {
> 	-re "\[\r\n]+"		{ exp_continue; }
> -	-re "^(.+\[:.])1 ($prompt)" { # stoopid extreme cmd-line numbers and
> +	-re "^(.+\[:.])1 ($reprompt)" { # stoopid extreme cmd-line numbers and
> 				  # prompt based on state of config changes,
> 				  # which may have an * at the beginning.
> 				  set junk $expect_out(1,string)
> @@ -913,7 +918,7 @@
> 				  set prompt ".? ?$junk\[0-9]+ $expect_out(2,string)";
> 				  set platform "extreme"
> 				}
> -	-re "^.+$prompt"	{ set junk $expect_out(0,string);
> +	-re "^.+$reprompt"	{ set junk $expect_out(0,string);
> 				  regsub -all "\[\]\[\(\)]" $junk {\\&} prompt;
> 				}
>     }
> 
> 
> 
> ------------------------------



More information about the Rancid-discuss mailing list