shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Re: chave USB para login


From: Keppler Alecrim
Subject: Re: [shell-script] Re: chave USB para login
Date: Sat, 12 Aug 2006 17:02:01 -0400

Olá ,
   Pow maurício, valeu mesmo. Obrigado pelos comentários acho que depois
dessa vai diminuir bem o meu código.
Valeu.

On 8/12/06, Mauricio <address@hidden> wrote:
>
> Oi Keppler... meus comentários abaixo e boa sorte!
>
>
> Keppler Alecrim wrote:
> > Olá ,
> >         Como recomendado pelo Julio,estou colocando meu script novamente
> > para pegar porrada :). Fiquem a vontade para comentar.
> >
> > lenin /usr/local/usbkeys # cat bin/usbkeys_check
> > #!/bin/bash
> > #Created by Francisco Alecrim (address@hidden)
> > #address@hidden
> >
> > WHOAMI=`echo $USER`
>
> WHOAMI=$USER       # a nova variável é a própria variável $USER
>
>
> > if [ `/bin/cat /etc/usbkeys | grep  $WHOAMI | wc -l` -lt 1 ];
>
> if [[ $(grep -c $WHOAMI /etc/usbkeys) -lt 1 ]]             # com [[ ]] vc
> usa uma função interna do bash, com grep -c vc elimina mais um pipe
>
>
>
> >         then
> >                 echo 'Logando...';
> >                 exit 0
> >         else
> >                 if [ -e /proc/bus/usb/devices ];
>               if [[ -e /proc/bus/usb/devices ]]  # o ";" é desnecessário
>
> >                         then
> >                                 for registered in `cat /etc/usbkeys |
> grep $WHOAMI | cut -f2 -d_`
> >                                         do
> >                                                 echo $registered
>
>                                     # em vez dos laços não poderia ser
> algo como:
>
>                                     if egrep -qs
> "SerialNumber.*$registered" /proc/bus/usb/devices
>                                     then
>                                           echo 'Logando...'
>                                           exit 0
>                                     fi
>
>
>
>
> >                                                 for present in `cat
> /proc/bus/usb/devices | grep "SerialNumber" | cut -c 18-`
> >                                                         do
> >                                                                 if [
> $registered = $present ];
> >
> then
>                                                               echo
> "Logando..."
>                                                                 exit 0
> >                                                                 fi
> >                                                         done
> >                                         done
> >                         fi
> > fi
> > echo  "Erro : Put USB "
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > lenin /usr/local/usbkeys # cat README
> > Author
> >         Created by Francisco Alecrim (address@hidden)
> > Objective
> >         The objective of this work is to obtain a grade in activities
> > related with TSSO(Topicos Selecionados em Sistemas Operacioans) lectured
> by
> > Ilias Biris at UFAM(Universidade Federal do Amazonas).
> > License
> >         GPL
> > Description
> >         The program controls user's login.It just allows the login of
> some
> > users with a certain USB device plugged.Users that are with username on
> file
> > /etc/usbkeys needs to plug the USB device related with your login,if not
> the
> > login will be canceled.For those not listed on /etc/usbkeys,the login
> will
> > be normal.
> > Installing
> >    Getting a USB serial number
> >         # cat /proc/bus/usb/devices | grep "SerialNumber" | cut -c 18- >
> > /tmp/usb_before
>
> # bom, em geral por que fazer cat arquivo | grep padrão | cut , etc, etc
> em vez de grep padrao arquivo | cut etc, etc... Outra coisa
> # a forma cut -c 18- nesse caso talvez ficasse melhor como cut -d'=' -f2
>
>
>
>
> >         Plug you USB device
> >         # cat /proc/bus/usb/devices | grep "SerialNumber" | cut -c 18- >
> > /tmp/usb_after
> >         # diff /tmp/usb_before  /tmp/usb_after | grep '>' | cut -f2 -d'
> ' |
> > head -1
> >         The number resulted of this operations is your USB serial key.
> >
> >    Creating a list of keys
> >         Create a file
> >         # touch /etc/usbkeys
> >         The format of a entry is username_usbserialkey ,one entry per
> > line,for example :
> >         teste_07912C401201B8A3
> >         alecrim_06A06640F2E2A88F
> >
> >    Copy bin/usbkeys_check for /usr/local/bin.
> >
> >         # cp bin/usbkeys_check /usr/local/bin
> >
> >    Add to the end of /etc/bash.bashrc and /etc/gdm/PostLogin/Default
> lines :
> >         if [ `/usr/local/usbkeys/bin/usbkeys_check | grep "Logando" | wc
> > -l`  -ne 1 ];
> >                 then
> >                         logout
> >         fi
> >
> >
> >    This file(/etc/bash.bashrc) is executed during login on shell.It's
> going
> > to check if login is available on SHELL.
> >    This file(/etc/gdm/PostLogin/Default) during desktop environment
> start
> > using GDM.It's going to check if login is available on desktop
> environment.
> >
> >
> > Comments
> >          Francisco Alecrim ( address@hidden )
> >
> > lenin /usr/local/usbkeys #
> >
> >
> >
> >
> >
> >
> > On 8/9/06, Julio C. Neves <address@hidden> wrote:
> >> Fala Keppler,
> >> <OT>
> >> antes de mais nada gostaria de dizer que durante o II Encontro de
> Software
> >> Livre do Amazonas, muitíssimo bem organizado pela Comunidade Sol,
> travei
> >> conhecimento com que o Instituto Nokia de Tecnologia (INdT) está
> >> produzindo
> >> e fiquei impressionado. Parabéns!
> >> </OT>
> >>
> >> Bem voltando ao tema da lista: diversas vezes vc usou grep e em seguida
> um
> >> wc -l. Isso não é necessário, já que a opção -c do grep te devolve a
> qtd
> >> de
> >> linhas que possuem a cadeia que vc está pesquisando.
> >>
> >> O cmd for tem um monte de sintaxes (para conhecer estas sintaxes veja
> em
> >> www.julioneves.com o Papo de Botequim V e o VI) mas, na mais elementar,
> >> ele
> >> assume cada um dos valores de uma lista. Então onde vc fez:
> >>
> >>
> >> for(( i=1 ; i<= numLinhas ; i++))
> >> do
> >>         Linha=`cat /proc/bus/usb/devices | grep "SerialNumber" | cut -c
> >> 18-
> >> | sort | head -$i | tail -1`
> >>
> >> poderia ter feito:
> >>
> >> for Linha in `cat /proc/bus/usb/devices | grep "SerialNumber" | cut -c
> 18-
> >> |
> >> sort`
> >> do
> >>        ...
> >>
> >> O programa é muito longo e não tenho tempo de entender toda a sua
> lógica,
> >> porém aplicando estas dicas que dei ele já encolherá bastante. Depois
> das
> >> alterações que serão sugeridas pelos colegas, coloque-o novamente na
> lista
> >> para nova rodada de comentários.
> >>
> >> --
> >> Abraços,
> >> Julio
> >> http://www.julioneves.com - Um livro sobre Bash completo e on-line
> >> :wq
> >>
> >> 2006/8/9, Keppler Alecrim <address@hidden>:
> >>
> >>> Pow nao sabia que nao ia anexo.
> >>>
> >>>
> >>> lenin /usr/local/usbkeys # cat bin/usbkeys_check
> >>> #!/bin/bash
> >>> #Create by Michel Cunha and Karane Vieira
> >>> #Modified by Francisco Alecrim (address@hidden)
> >>> #WHOAMI=`/usr/bin/whoami`
> >>> WHOAMI=`echo $USER`
> >>> echo $USER
> >>>
> >>> #Checking if user needs USB KEY
> >>> NUM_OCCURRENCE=`/bin/cat /etc/usbkeys | grep $WHOAMI | wc -l`
> >>> if [ $NUM_OCCURRENCE -lt 1 ];
> >>>         then
> >>>                 echo 'Do not need USB KEY! Logando ';
> >>>                 #exec /bin/bash
> >>>                 exit 0
> >>>         else
> >>>                 echo 'Needs USB KEY';
> >>> fi
> >>>
> >>>
> >>> #Getting USB KEYS registered
> >>> if [ -e /proc/bus/usb/devices ];
> >>>         then
> >>>                 echo 'CAN find : /proc/bus/usb/devices';
> >>>                 DEVICES=`cat /proc/bus/usb/devices | grep
> "SerialNumber"
> >> |
> >>> cut -c 18-`
> >>>                 numLinhas=`cat /proc/bus/usb/devices | grep
> >> "SerialNumber"
> >>> |
> >>> cut -c 18- | wc -l`
> >>>         else
> >>>                 echo 'Cannot find : /proc/bus/usb/devices';
> >>>                 exit 0;
> >>> fi
> >>>
> >>>
> >>> echo -ne "Numeros de Serie no Sistema = $numLinhas\n"
> >>>
> >>> for(( i=1 ; i<= numLinhas ; i++))
> >>> do
> >>>         Linha=`cat /proc/bus/usb/devices | grep "SerialNumber" | cut
> -c
> >>> 18-
> >>> | sort | head -$i | tail -1`
> >>>         numLinhasArquivo=`/bin/cat /etc/usbkeys | wc -l`
> >>>         for((j=1 ; j<= numLinhasArquivo ; j++))
> >>>         do
> >>>                 LinhaArquivo=`/bin/cat /etc/usbkeys | grep $WHOAMI |
> cut
> >>> -f2
> >>> -d'_'| sort | head -$j | tail -1`
> >>>                 echo -ne "Verificando ... $Linha = $LinhaArquivo\n"
> >>>                 if [ $Linha = $LinhaArquivo ];
> >>>                         then
> >>>                         echo -ne "Numero de Serie Encontrado. Logando
> no
> >>> Sistema ... \n"
> >>>                         #exec /bin/bash
> >>>                         exit
> >>>                 fi
> >>>         done
> >>>         echo -ne "Linha$i - $Linha\n"
> >>> done
> >>>
> >>> echo -ne "\n Voce não foi autorizado a Entrar no Sistema. Saindo...\n"
> >>> logout
> >>> lenin /usr/local/usbkeys # cat README
> >>> Author
> >>>         Created by Francisco Alecrim (address@hidden)
> >>> Objective
> >>>         The objective of this work is to obtain a grade in activities
> >>> related with TSSO(Topicos Selecionados em Sistemas Operacioans)
> lectured
> >>> by
> >>> Ilias Biris at UFAM(Universidade Federal do Amazonas).
> >>> License
> >>>         GPL
> >>> Description
> >>>         The program controls user's login.It just allows the login of
> >> some
> >>> users with a certain USB device plugged.Users that are with username
> on
> >>> file
> >>> /etc/usbkeys needs to plug the USB device related with your login,if
> not
> >>> the
> >>> login will be canceled.For those not listed on /etc/usbkeys,the login
> >> will
> >>> be normal.
> >>>
> >>> Installing
> >>>    Getting a USB serial number
> >>>         # cat /proc/bus/usb/devices | grep "SerialNumber" | cut -c 18-
> >
> >>> /tmp/usb_before
> >>>         Plug you USB device
> >>>         # cat /proc/bus/usb/devices | grep "SerialNumber" | cut -c 18-
> >
> >>> /tmp/usb_after
> >>>         # diff /tmp/usb_before  /tmp/usb_after | grep '>' | cut -f2
> -d'
> >> '
> >>> |
> >>> head -1
> >>>         The number resulted of this operations is your USB serial key.
> >>>
> >>>    Creating a list of keys
> >>>         Create a file
> >>>         # touch /etc/usbkeys
> >>>         The format of a entry is username_usbserialkey ,one entry per
> >>> line,for example :
> >>>         teste_07912C401201B8A3
> >>>         alecrim_06A06640F2E2A88F
> >>>
> >>>    Copy bin/usbkeys_check for /usr/local/bin.
> >>>
> >>>         # cp bin/usbkeys_check /usr/local/bin
> >>>
> >>>    Add to the end of /etc/bash.bashrc lines :
> >>>
> >>>         RES=`/usr/local/bin/usbkeys_check | grep "Logando" | wc -l`
> >>>         if [ $RES -ne 1 ];
> >>>                 then
> >>>                         logout
> >>>         fi
> >>>
> >>>    This file(/etc/bash.bashrc) is executed during login on shell.It's
> >>> going
> >>> to check if login is available on SHELL.
> >>>
> >>>    Copy /etc/gdm/PostLogin/Default.sample /etc/gdm/PostLogin/Default
> >>>    Add to the end of /etc/gdm/PostLogin/Default line :
> >>>
> >>>         /usr/local/bin/usbkeys_check > /tmp/log_usbkey
> >>>
> >>>    This file(/etc/gdm/PostLogin/Default) during desktop environment
> >> start
> >>> using GDM.It's going to check if login is available on desktop
> >>> environment.
> >>>
> >>>
> >>> Comments
> >>>          Francisco Alecrim ( address@hidden )
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> lenin /usr/local/usbkeys #
> >>>
> >>>
> >>> On 8/9/06, Fernando Zank <address@hidden> wrote:
> >>>> não vai anexo para a lista:
> >>>>
> >>>> Me mando o seu script para eu ver se possível, obrigado
> >>>> On 8/9/06, Keppler Alecrim < address@hidden> wrote:
> >>>>
> >>>>> Olá ,
> >>>>> Esta é a primeira vez que participo em uma lista de
> >> discursão.Esperonão
> >>>>> apanhar muito.
> >>>>> Fiz um script simples que verfica se o usuário que está logando
> >> possui
> >>>>> uma
> >>>>> dispositivo USB plugado,senão ele não autoriza o login. Já vi um
> >> cara
> >>>>> fazendo algo com gdm e smartcard.
> >>>>>
> >>>>> O script vai em anexo com um README sobre a como deve ser o formato
> >> da
> >>>>> lista
> >>>>> de usuários.
> >>>>>
> >>>>> Aguardo comentários(bons ou ruins).
> >>>>>
> >>>>> PS: Estou desenvolvendo uma versão(não tem haver com esta lista,pois
> >>>>> estou
> >>>>> fazendo em C) para travar o boot do kernel.
> >>>>>
> >>>>> --
> >>>>> Francisco Keppler Silva Alecrim
> >>>>> Instituto Nokia de Tecnologia (INdT) - OSMRC
> >>>>>
> >>>>>
> >>>>> [As partes desta mensagem que não continham texto foram removidas]
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>> --
> >>>> "Somos o que repetidamente fazemos, portanto a
> >>>> excelência não é um feito é um hábito" - Aristóteles
> >>>
> >>> [As partes desta mensagem que não continham texto foram removidas]
> >>>
> >>>
> >>>
> >>
> >> [As partes desta mensagem que não continham texto foram removidas]
> >>
> >>
> >>
> >
> >
> >
>
> 
>



-- 
-- 
Francisco Keppler Silva Alecrim
Instituto Nokia de Tecnologia (INdT) - OSMRC


[As partes desta mensagem que não continham texto foram removidas]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]