linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bluez-devel] PIN helper
@ 2006-03-08 21:19 Radek
  2006-03-08 21:40 ` Dave Mielke
  0 siblings, 1 reply; 25+ messages in thread
From: Radek @ 2006-03-08 21:19 UTC (permalink / raw)
  To: bluez-devel

Hello,
from whot I had read in the net there had been some controversies about
the pinhelpers. The d-bus one need d-bus, and the python one need some
extra libs as well as X..
Maybe it was thougt before.. but I would suggest using a different
method. A list of devices with coresponding pins. This gives the
possibilities to have a different pin for different devices (important
especially if you have some that have a fixed pin:0000, not a very
secure idea for a default pin) and possibly a default pin as an option.
A very simple script that does that:

#!/bin/sh
echo "PIN:"$(grep $2 /etc/bluetooth/pins|sed s/.*PIN\://)

Not a very clean solusion (sorry I'm no programer, and my knowledge of
bash/sh is limited) but portable (bysybox suports all that is needed).
The obviously in format:

anything countaining the HWaddress of the device PIN: and the pin

this gives the possibility to have something like this:

00:0E:05:05:04:02; My cat; PIN:0000
00:0E:05:05:04:01; The dog; PIN:1111432334

It would be better if the script checked the files permisions, gave an
option to use a default pin and maybe some logging... But for that my
current sh knowledge is not enough.. sorry :-(

Still I think this is a beeter solusion, a more universal one, then the
ones shiped with bluez now.. which doesn't meen that the current
helpers are not helpful :)

My regards.

-- 
Radoslaw Rurarz
Warsaw Poland


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-08 21:19 [Bluez-devel] PIN helper Radek
@ 2006-03-08 21:40 ` Dave Mielke
  2006-03-08 22:01   ` Radek Rurarz
  0 siblings, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-08 21:40 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]

[quoted lines by Radek on 2006/03/08 at 22:19 +0100]

>from whot I had read in the net there had been some controversies about
>the pinhelpers. The d-bus one need d-bus, and the python one need some
>extra libs as well as X..

May I use this opportunity to "readvertise" a script I tried to bring to your
collective attention some months ago. It's attached to this post as "bluepin". 
It works in text mode, supports a file containing address/pin mappings, and
uses the dialog utility to bring up a text-mode prompt on a spare virtual
terminal for devices not listed in the file. Please give it some consideration.
I'll be glad to enhance it as necessary regarding whatever features it's
missing or could use in addition to what it already does. See the comments at
the top of the script for more detail. 

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/

[-- Attachment #2: bluepin --]
[-- Type: text/plain, Size: 1956 bytes --]

#!/bin/sh
# This script has been written by Dave Mielke <dave@mielke.cc>. It's a light 
# weight, text mode, Bluetooth PIN helper script. Its dependencies are:
# *  /bin/sh  The standard system command shell.
# *  open     A command which opens a free virtual terminal.
# *  dialog   A command which presents a text-mode dialog.
#
# The file /etc/bluetooth/pins is searched for a line corresponding to the 
# Bluetooth address of the device. Each line of this file should contain the
# address of a device and its PIN, in that order, separated by space. If the
# address is found then the corresponding PIN is automatically supplied. If
# it's not found then the user is prompted via a text-mode dialog in a free 
# virtual terminal. The console automatically returns to the original virtual
# terminal as soon as the PIN is entered.

pinsFile="/etc/bluetooth/pins"
pinLimit=16

[ "${#}" -gt 0 ] && {
   direction="${1}"
   shift

   [ "${#}" -gt 0 ] && {
      address="${1}"
      shift

      if [ "${#}" -gt 0 ]
      then
         name="${1}"
         shift
      else
         name=""
      fi

      [ -f "${pinsFile}" -a -r "${pinsFile}" ] && exec <"${pinsFile}" && {
         while read a p x
         do
            [ "${a}" = "${address}" ] && {
               echo "PIN:${p}"
               exit 0
            }
         done
      }

      if [ "${direction}" = "out" ]
      then
         adjective="outgoing"
         preposition="to"
      else
         adjective="incoming"
         preposition="from"
      fi

      title="Bluetooth PIN Prompt"
      time="`date '+%Y-%m-%d@%H:%M:%S'`"
      prompt="Enter PIN for ${adjective} Bluetooth connection ${preposition} ${name}[${address}]"
      pin="`open 3>&1 -s -w -- dialog --output-fd 3 --clear --title "${title}" --cr-wrap --max-input "${pinLimit}" --inputbox "${time}\n\n${prompt}" 0 0 ""`"
      [ -n "${pin}" ] && {
         echo "PIN:${pin}"
	 exit 0
      }
   }
}

echo ERR
exit 0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-08 21:40 ` Dave Mielke
@ 2006-03-08 22:01   ` Radek Rurarz
  2006-03-08 22:16     ` Dave Mielke
  0 siblings, 1 reply; 25+ messages in thread
From: Radek Rurarz @ 2006-03-08 22:01 UTC (permalink / raw)
  To: bluez-devel

On Wed, 8 Mar 2006 16:40:32 -0500
Dave Mielke <dave@mielke.cc> wrote:


> May I use this opportunity to "readvertise" a script I tried to bring
> to your collective attention some months ago. It's attached to this
> post as "bluepin". It works in text mode, supports a file containing
> address/pin mappings, and uses the dialog utility to bring up a
> text-mode prompt on a spare virtual terminal for devices not listed
> in the file. Please give it some consideration. I'll be glad to
> enhance it as necessary regarding whatever features it's missing or
> could use in addition to what it already does. See the comments at
> the top of the script for more detail.=20

Some things I would like to have:
1. checking the permissions of the file

2. an option to chose wheather a promp should be used even if there is
no pin in the file, possibly to chose another pinhelper if there is no
pin (for instance the one for X, if that fails to create a promp).

3. In the pins file another 'slot' for the name of the device
(not nessesary the one advertised by it, rather to have an idea whot is
it)

No more ideas for now.

My regards.

--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-08 22:01   ` Radek Rurarz
@ 2006-03-08 22:16     ` Dave Mielke
  2006-03-09  5:44       ` Radek Rurarz
  0 siblings, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-08 22:16 UTC (permalink / raw)
  To: bluez-devel

[quoted lines by Radek Rurarz on 2006/03/08 at 23:01 +0100]

>Some things I would like to have:
>1. checking the permissions of the file

Do you mean that you'd like it to log via syslog if the permissions are unsafe?

>2. an option to chose wheather a promp should be used even if there is
>no pin in the file, possibly to chose another pinhelper if there is no
>pin (for instance the one for X, if that fails to create a promp).
>
>3. In the pins file another 'slot' for the name of the device
>(not nessesary the one advertised by it, rather to have an idea whot is
>it)

These are good ideas. Thanks. I'll do them.

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-08 22:16     ` Dave Mielke
@ 2006-03-09  5:44       ` Radek Rurarz
  2006-03-09  5:55         ` Dave Mielke
  0 siblings, 1 reply; 25+ messages in thread
From: Radek Rurarz @ 2006-03-09  5:44 UTC (permalink / raw)
  To: bluez-devel

On Wed, 8 Mar 2006 17:16:44 -0500
Dave Mielke <dave@mielke.cc> wrote:

> [quoted lines by Radek Rurarz on 2006/03/08 at 23:01 +0100]
>=20
> >Some things I would like to have:
> >1. checking the permissions of the file
>=20
> Do you mean that you'd like it to log via syslog if the permissions
> are unsafe?

That would be nice. But first of all, if the permissions are wrong (the
propper ones set in a config file, or in the script itself) the script
should not use the file and either refuse the connection =3D ERR (and
syslog the error) or fallback to other methods of geting the PIN (if
allowed).

> >2. an option to chose wheather a promp should be used even if there
> >is no pin in the file, possibly to chose another pinhelper if there
> >is no pin (for instance the one for X, if that fails to create a
> >promp).
> >
> >3. In the pins file another 'slot' for the name of the device
> >(not nessesary the one advertised by it, rather to have an idea whot
> >is it)
>=20
> These are good ideas. Thanks. I'll do them.

I'll be greatful :)

My regards.

--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-09  5:44       ` Radek Rurarz
@ 2006-03-09  5:55         ` Dave Mielke
  2006-03-09  6:06           ` Radek Rurarz
  0 siblings, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-09  5:55 UTC (permalink / raw)
  To: bluez-devel

[quoted lines by Radek Rurarz on 2006/03/09 at 06:44 +0100]

>if the permissions are wrong (the
>propper ones set in a config file, or in the script itself) the script
>should not use the file and either refuse the connection = ERR (and
>syslog the error) or fallback to other methods of geting the PIN (if
>allowed).

Done. I won't let the permissions be more than 600 (although I'll perhaps add
an option to override that). The logging is done too.

>> >2. an option to chose wheather a promp should be used even if there
>> >is no pin in the file, 

This one (-n for no prompt) has now been done.

>> >possibly to chose another pinhelper if there
>> >is no pin (for instance the one for X, if that fails to create a
>> >promp).

This one will take some thought. It could check to see if X is running, and
then run the X one if so and do the text-mode thing otherwise. If that's okay,
the option would be something like: -x /etc/bluetooth/xbluepin

>> >3. In the pins file another 'slot' for the name of the device
>> >(not nessesary the one advertised by it, rather to have an idea whot
>> >is it)

The script actually already did that, i.e. it ignores data after the PIN. Now
it's documented, though, and even with an example.

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-09  5:55         ` Dave Mielke
@ 2006-03-09  6:06           ` Radek Rurarz
  2006-03-09  6:12             ` Dave Mielke
  0 siblings, 1 reply; 25+ messages in thread
From: Radek Rurarz @ 2006-03-09  6:06 UTC (permalink / raw)
  To: bluez-devel

On Thu, 9 Mar 2006 00:55:52 -0500
Dave Mielke <dave@mielke.cc> wrote:


> >> >possibly to chose another pinhelper if there
> >> >is no pin (for instance the one for X, if that fails to create a
> >> >promp).
>=20
> This one will take some thought. It could check to see if X is
> running, and then run the X one if so and do the text-mode thing
> otherwise. If that's okay, the option would be something like:
> -x /etc/bluetooth/xbluepin

A simpler method would be to relly on another pinhelper (for
instance one from the bluez-utlis) set in a config file.. juts pass the
arguments to it.. and see if it returns a propper pin.. if not fall
back to the internal methods (promp if allowed, the pin file shoud be
checked first).

Then it could be a standard pinhelper.. even with kde/gnome/opie/gpe
(last two on handhelds) on top.

> >> >3. In the pins file another 'slot' for the name of the device
> >> >(not nessesary the one advertised by it, rather to have an idea
> >> >whot is it)
>=20
> The script actually already did that, i.e. it ignores data after the
> PIN. Now it's documented, though, and even with an example.

Sorry, didn't noticed that... I need to work on my sh skills ;)

My regards.


--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-09  6:06           ` Radek Rurarz
@ 2006-03-09  6:12             ` Dave Mielke
  2006-03-09 18:29               ` Radek Rurarz
  0 siblings, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-09  6:12 UTC (permalink / raw)
  To: bluez-devel

[quoted lines by Radek Rurarz on 2006/03/09 at 07:06 +0100]

>A simpler method would be to relly on another pinhelper (for
>instance one from the bluez-utlis) set in a config file.. juts pass the
>arguments to it.. and see if it returns a propper pin.. if not fall
>back to the internal methods (promp if allowed, the pin file shoud be
>checked first).

Do you think it should be just one, or should multiple specifications of the
option accumulate a set of helpers to try?

>Sorry, didn't noticed that... I need to work on my sh skills ;)

I'm grateful that you didn't as that gave me the idea to document the
"feature".

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-09  6:12             ` Dave Mielke
@ 2006-03-09 18:29               ` Radek Rurarz
  2006-03-09 19:34                 ` Dave Mielke
  0 siblings, 1 reply; 25+ messages in thread
From: Radek Rurarz @ 2006-03-09 18:29 UTC (permalink / raw)
  To: bluez-devel

On Thu, 9 Mar 2006 01:12:55 -0500
Dave Mielke <dave@mielke.cc> wrote:

> [quoted lines by Radek Rurarz on 2006/03/09 at 07:06 +0100]
>=20
> >A simpler method would be to relly on another pinhelper (for
> >instance one from the bluez-utlis) set in a config file.. juts pass
> >the arguments to it.. and see if it returns a propper pin.. if not
> >fall back to the internal methods (promp if allowed, the pin file
> >shoud be checked first).
>=20
> Do you think it should be just one, or should multiple specifications
> of the option accumulate a set of helpers to try?

Good question..
For security reasons an simplicyty...  one is a good idea.
But having an option to try more then one is more universal (but not
nessesary).
If it's not a big problem (both for you to implement and for the system
to compute..) it would be a nice feature.
=20
> >Sorry, didn't noticed that... I need to work on my sh skills ;)
>=20
> I'm grateful that you didn't as that gave me the idea to document the
> "feature".

It would be nice ;) still the bluz is poorly documented as whole.. an
you're prepering the helper... The documentation is usually prepered
after something is ready ;)

Ps.
I prefer a working program, then a problematic one with documentation ;)

My regards.

Ps.
Sorry for any spelling mistakes...

--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-09 18:29               ` Radek Rurarz
@ 2006-03-09 19:34                 ` Dave Mielke
  2006-03-09 21:55                   ` Radek Rurarz
  0 siblings, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-09 19:34 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 993 bytes --]

[quoted lines by Radek Rurarz on 2006/03/09 at 19:29 +0100]

>For security reasons an simplicyty...  one is a good idea.
>But having an option to try more then one is more universal (but not
>nessesary).
>If it's not a big problem (both for you to implement and for the system
>to compute..) it would be a nice feature.

The latest version of the script is attached to this post. Please have a look
at it and/or give it a try. I've went with making this option (-c) be
non-cumulative for the time being, but it'd be very easy to change that. Please
let me know what else you think needs to be done.

>I prefer a working program, then a problematic one with documentation ;)

I tend to agree. 

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/

[-- Attachment #2: bluepin --]
[-- Type: text/plain, Size: 6933 bytes --]

#!/bin/bash
# This script has been written by Dave Mielke <dave@mielke.cc>. It's a light 
# weight, text mode, Bluetooth PIN helper script. Its dependencies are:
# *  /bin/bash  The interpreter for this script.
# *  open     A command which opens a free virtual terminal.
# *  dialog   A command which presents a text-mode dialog.
# *  logger   A command which writes to the system log.
#
# Step 1: The PINs file, /etc/bluetooth/pins (can be changed with the -f
# option), is searched for a line which corresponds to the Bluetooth address of
# the device. Each line in this file should contain the address of a device and
# its PIN, in that order, separated by space. Any additional data on the line
# is ignored and can be used as a comment to help identify the device. For
# example, if the address of your cell phone is 01:23:45:67:89:AB, and if its
# PIN is 12345, then its line would look like this:
#
#    01:23:45:67:89:AB 12345 my cell phone
#
# If the address is found within the PINs file then the corresponding PIN is
# returned.
#
# Step 2: If the -c option has been specified then its operand is interpreted
# as the command which is to be used to prompt the user for the PIN. If it is
# appropriately quoted so that it can contain space then options may be
# specified after the command name. It must interpret its positional parameters
# and return its response as if it were being directly invoked as a Bluetooth
# PIN helper. If it returns a PIN then that PIN is returned.
#
# Step 3: If the -n option has not been specified then the user is prompted for
# the PIN via a text-mode dialog in a free virtual terminal. The console
# automatically returns to the original virtual terminal as soon as the user
# responds to the dialog. If the response contains at least one character then
# the entire response is returned as the PIN.
#
# Step 4: Return the fact that the PIN could not be determined.
#
# Error messages are written to the system log (syslog) if "logger" is in the
# command search path ($PATH) and if standard output is not a terminal (tty or
# pty). If any of these conditions is not satisfied then errors are written to
# standard error.
#
# Invoke this script with the -h option to see its usage summary.

programName="${0##*/}"
programMessage() {
   typeset message="${1}"
   typeset level="${2}"

   echo >&2 "${programName}: ${message}"
}

programError() {
   typeset status="${1}"
   typeset message="${2}"

   programMessage "${message}" error
   exit "${status}"
}

syntaxError() {
   typeset message="${1}"

   programError 2 "${message}"
}

findCommand() {
   typeset variable="${1}"
   typeset command="${2}"

   typeset path="$(type -p "${command}")"
   [ -n "${path}" ] && {
      eval "${variable}"'="${path}"'
      return 0
   }

   programMessage "command not found: ${command}"
   return 1
}

respondWithPin() {
   typeset pin="${1}"

   echo "PIN:${pin}"
   exit 0
}

[ ! -t 1 ] && {
   findCommand loggerPath logger && {
      programMessage() {
         typeset message="${1}"
         typeset level="${2}"

         "${loggerPath}" -t "${programName}[${$}]" -p "daemon.${level:-warning}" -- "${message}"
      }
   }
}

defaultPinCommand=""
defaultPinsFile="/etc/bluetooth/pins"
defaultAcceptableModes="0600"

showUsage=false
pinCommand="${defaultPinCommand}"
pinsFile="${defaultPinsFile}"
acceptableModes="${defaultAcceptableModes}"
promptUser=true
pinLimit=16

while getopts ":c:f:hm:n" option
do
   case "${option}"
   in
      c) pinCommand="${OPTARG}";;
      f) pinsFile="${OPTARG}";;
      h) showUsage=true;;
      m) acceptableModes="${OPTARG}";;
      n) promptUser=false;;
     \?) syntaxError "invalid option: -${OPTARG}";;
      :) syntaxError "missing operand: -${OPTARG}";;
      *) syntaxError "unimplemented option: -${option}";;
   esac
done
shift $((OPTIND - 1))

"${showUsage}" && {
   cat <<END_USAGE
Usage: ${programName} [-option ...] direction address [name]
Parameters:
   direction  The direction of the connection request (in|out).
   address    The Bluetooth device address (xx:xx:xx:xx:xx:xx).
   name       The name of the device (optional).
Options:
   -c command  The command to prompt for a PIN not in the PINs file.${defaultPinCommand:+ [${defaultPinCommand}]}
   -f file     The PINs file. [${defaultPinsFile}]
   -h          This command usage summary.
   -m modes    The modes (in octal) that the PINs file may have. [${defaultAcceptableModes}]
   -n          Do not prompt for the PIN.
END_USAGE
   exit 0
}

[ "${#}" -eq 0 ] && syntaxError "connection direction not supplied"
direction="${1}"
shift

[ "${#}" -eq 0 ] && syntaxError "device address not supplied"
address="${1}"
shift

if [ "${#}" -gt 0 ]
then
   name="${1}"
   shift
else
   name=""
fi

shopt -s extglob
[ -z "${acceptableModes##+([0-7])}" ] || syntaxError "invalid file permission modes: ${acceptableModes}"
[ "${acceptableModes#0}" = "${acceptableModes}" ] && acceptableModes="0${acceptableModes}"

[ -e "${pinsFile}" ] && {
   if [ ! -f "${pinsFile}" ]
   then
      programMessage "not a file: ${pinsFile}"
   elif [ ! -r "${pinsFile}" ]
   then
      programMessage "file not readable: ${pinsFile}"
   else
      safeModes=false
      if findCommand statPath stat
      then
         actualModes="$("${statPath}" -c '%a' -- "${pinsFile}")"
         [ "${actualModes#0}" = "${actualModes}" ] && actualModes="0${actualModes}"
         if ((actualModes & ~acceptableModes))
         then
            programMessage "unsafe file permission modes: ${pinsFile}: ${actualModes} > ${acceptableModes}"
         else
            safeModes=true
         fi
      else
         programMessage "file permission modes not verifiable: ${pinsFile}"
      fi

      "${safeModes}" && {
         exec 3<"${pinsFile}"
         while read -u 3 -r a p x
         do
            [ "${a}" = "${address}" ] && respondWithPin "${p}"
         done
         exec 3<&-
      }
   fi
}

[ -n "${pinCommand}" ] && {
   set -- ${pinCommand} "${direction}" "${address}"
   [ -n "${name}" ] && set -- "${@}" "${name}"
   response="$("${@}" | head -1)"
   pin="${response#PIN:}"
   [ "${pin}" != "${response}" ] && respondWithPin "${pin}"
}

"${promptUser}" && {
   if [ "${direction}" = "out" ]
   then
      adjective="outgoing"
      preposition="to"
   else
      [ "${direction}" = "in" ] || programMessage "unexpected connection direction: ${direction}"
      adjective="incoming"
      preposition="from"
   fi

   title="Bluetooth PIN Prompt"
   time="$(date '+%Y-%m-%d@%H:%M:%S')"
   prompt="Enter PIN for ${adjective} Bluetooth connection ${preposition} ${name}[${address}]"

   findCommand openPath open && findCommand dialogPath dialog && {
      pin="$("${openPath}" 3>&1 -s -w -- "${dialogPath}" --output-fd 3 --clear --title "${title}" --cr-wrap --max-input "${pinLimit}" --inputbox "${time}\n\n${prompt}" 0 0 "")"
      [ -n "${pin}" ] && respondWithPin "${pin}"
   }
}

echo "ERR"
exit 0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-09 19:34                 ` Dave Mielke
@ 2006-03-09 21:55                   ` Radek Rurarz
  2006-03-09 22:04                     ` Radek Rurarz
  0 siblings, 1 reply; 25+ messages in thread
From: Radek Rurarz @ 2006-03-09 21:55 UTC (permalink / raw)
  To: bluez-devel

On Thu, 9 Mar 2006 14:34:23 -0500
Dave Mielke <dave@mielke.cc> wrote:

> The latest version of the script is attached to this post. Please
> have a look at it and/or give it a try. I've went with making this
> option (-c) be non-cumulative for the time being, but it'd be very
> easy to change that. Please let me know what else you think needs to
> be done.

Ok, in place.. and working, at least with sending the pin form the
list :) (which is the part that I need).
Thank you...

For others ideas.. a config file, lets say /etc/bluetooth/pins.conf for
puting options like -n and -c ;) (disabling promp and seting
alternative helpers).

Still, as much as I'm concerned... I'm for changing the default
pinhelper to yours and adding the python X helper as one colled from it.

My regards.

Ps.
In a moment I'll put the script on iPAQ, if it works there.. I have
nothing more to ask for.


--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-09 21:55                   ` Radek Rurarz
@ 2006-03-09 22:04                     ` Radek Rurarz
  2006-03-10  1:33                       ` Dave Mielke
  0 siblings, 1 reply; 25+ messages in thread
From: Radek Rurarz @ 2006-03-09 22:04 UTC (permalink / raw)
  To: bluez-devel

On Thu, 9 Mar 2006 22:55:21 +0100
Radek Rurarz <fotopiper@o2.pl> wrote:


> Ps.
> In a moment I'll put the script on iPAQ, if it works there.. I have
> nothing more to ask for.

:( Unfortunatelly it doesn't.. BusyBox.. it seams to be mising some
things..

I get:
/usr/bin/bluepin: 158: shopt: not found
/usr/bin/bluepin: 159: typeset: not found
/usr/bin/bluepin: 159: typeset: not found
/usr/bin/bluepin: 159: typeset: not found
/usr/bin/bluepin: 159: typeset: not found
/usr/bin/bluepin: 159: typeset: not found
bluepin:=20
exit: 159: Illegal number:

My regards.

Any ideas for making the script more portable?

--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-09 22:04                     ` Radek Rurarz
@ 2006-03-10  1:33                       ` Dave Mielke
  2006-03-10  7:28                         ` Radek Rurarz
  0 siblings, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-10  1:33 UTC (permalink / raw)
  To: bluez-devel

[quoted lines by Radek Rurarz on 2006/03/09 at 23:04 +0100]

>:( Unfortunatelly it doesn't.. BusyBox.. it seams to be mising some
>things..
>
>I get:
>/usr/bin/bluepin: 158: shopt: not found

shopt is a bash built-in command.

>/usr/bin/bluepin: 159: typeset: not found

typeset is a bash built-in command.

d>bluepin: 
>exit: 159: Illegal number:

Does your ipaq have /bin/bash, or did you try changing the first line of the
script so that it points to /bin/sh. It looks like it isn't running bash. If
bash isn't available on these platforms, or if a less functional version of
bash is being used, then we'll just have to change the code to not use some of
bash's cooler features.

>Any ideas for making the script more portable?

I usually have ideas, but we need to first figure out what the problem is. If
the system does have bash, can you figure out which version of bash it is?

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10  1:33                       ` Dave Mielke
@ 2006-03-10  7:28                         ` Radek Rurarz
  2006-03-10 13:35                           ` Dave Mielke
  2006-03-10 17:25                           ` Dave Mielke
  0 siblings, 2 replies; 25+ messages in thread
From: Radek Rurarz @ 2006-03-10  7:28 UTC (permalink / raw)
  To: bluez-devel

On Thu, 9 Mar 2006 20:33:08 -0500
Dave Mielke <dave@mielke.cc> wrote:

> Does your ipaq have /bin/bash, or did you try changing the first line
> of the script so that it points to /bin/sh. It looks like it isn't
> running bash. If bash isn't available on these platforms, or if a
> less functional version of bash is being used, then we'll just have
> to change the code to not use some of bash's cooler features.

Sorry, my foult (a bissy day and a late haur did have some evects :( )
iPAQs or rather Familiar in general have a BusyBox all in one
executable, at least for the basic comands.
Bash is not present, it could be instaled, but at great expense of free
space (or even not passible, doto lack of space).
The executable has only sh, and I'm not sure is it a 100% full
implementation.

Ps.
I did change the first line.

I'm sorry for rather poor information. I was trying to provide a fast
feedbak.. and in the proces dorgot to add much of the needed
information.

--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10  7:28                         ` Radek Rurarz
@ 2006-03-10 13:35                           ` Dave Mielke
  2006-03-10 18:10                             ` Radek Rurarz
  2006-03-10 17:25                           ` Dave Mielke
  1 sibling, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-10 13:35 UTC (permalink / raw)
  To: bluez-devel

[quoted lines by Radek Rurarz on 2006/03/10 at 08:28 +0100]

>iPAQs or rather Familiar in general have a BusyBox all in one
>executable, at least for the basic comands.
>Bash is not present, it could be instaled, but at great expense of free
>space (or even not passible, doto lack of space).
>The executable has only sh, and I'm not sure is it a 100% full
>implementation.

No problewm. I'll take out all of the bash-specific stuff and make it work in
plain old sh. Is there a man page for that version of sh which you could send
me for reference?

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10  7:28                         ` Radek Rurarz
  2006-03-10 13:35                           ` Dave Mielke
@ 2006-03-10 17:25                           ` Dave Mielke
  2006-03-10 18:13                             ` Radek Rurarz
  1 sibling, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-10 17:25 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 837 bytes --]

[quoted lines by Radek Rurarz on 2006/03/10 at 08:28 +0100]

>iPAQs or rather Familiar in general have a BusyBox all in one
>executable, at least for the basic comands.
>Bash is not present, it could be instaled, but at great expense of free
>space (or even not passible, doto lack of space).
>The executable has only sh, and I'm not sure is it a 100% full
>implementation.

Please try the attached updated script. I think I've removed all the bashisms. 
My /bin/sh, however, supports more than it should so it's hard for me to be
sure.

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/

[-- Attachment #2: bluepin --]
[-- Type: text/plain, Size: 6731 bytes --]

#!/bin/sh
# This script has been written by Dave Mielke <dave@mielke.cc>. It's a light 
# weight, text mode, Bluetooth PIN helper script.
#
# Step 1: The PINs file, /etc/bluetooth/pins (can be changed with the -f
# option), is searched for a line which corresponds to the Bluetooth address of
# the device. Each line in this file should contain the address of a device and
# its PIN, in that order, separated by space. Any additional data on the line
# is ignored and can be used as a comment to help identify the device. For
# example, if the address of your cell phone is 01:23:45:67:89:AB, and if its
# PIN is 12345, then its line would look like this:
#
#    01:23:45:67:89:AB 12345 my cell phone
#
# If the address is found within the PINs file then the corresponding PIN is
# returned.
#
# Step 2: If the -c option has been specified then its operand is interpreted
# as the command which is to be used to prompt the user for the PIN. If it is
# appropriately quoted so that it can contain space then options may be
# specified after the command name. It must interpret its positional parameters
# and return its response as if it were being directly invoked as a Bluetooth
# PIN helper. If it returns a PIN then that PIN is returned.
#
# Step 3: If the -n option has not been specified then the user is prompted for
# the PIN via a text-mode dialog in a free virtual terminal. The console
# automatically returns to the original virtual terminal as soon as the user
# responds to the dialog. If the response contains at least one character then
# the entire response is returned as the PIN.
#
# Step 4: Return the fact that the PIN could not be determined.
#
# Error messages are written to the system log (syslog) if "logger" is in the
# command search path ($PATH) and if standard output is not a terminal (tty or
# pty). If any of these conditions is not satisfied then errors are written to
# standard error.
#
# Invoke this script with the -h option to see its usage summary.

configurationDirectory="/etc/bluetooth"
defaultPinCommand=""
defaultPinsFile="${configurationDirectory}/pins"
defaultAcceptableModes="600"

programName="${0##*/}"
programMessage() {
   echo >&2 "${programName}: ${1}"
}

programError() {
   programMessage "${2}" error
   exit "${1}"
}

syntaxError() {
   programError 2 "${1}"
}

findCommand() {
   variable="${1}"
   shift
   command="${1}"

   while [ "${#}" -gt 0 ]
   do
      path="`which "${1}" 2>/dev/null`"
      [ -n "${path}" ] && {
         eval "${variable}"'="${path}"'
         return 0
      }
      shift
   done

   programMessage "command not found: ${command}"
   return 1
}

respondWithPin() {
   echo "PIN:${1}"
   exit 0
}

[ ! -t 1 ] && {
   findCommand loggerPath logger && {
      programMessage() {
         "${loggerPath}" -t "${programName}[${$}]" -p "daemon.${2:-warning}" -- "${1}"
      }
   }
}

showUsage=false
pinCommand="${defaultPinCommand}"
pinsFile="${defaultPinsFile}"
acceptableModes="${defaultAcceptableModes}"
promptUser=true
pinLimit=16

while getopts ":c:f:hm:n" option
do
   case "${option}"
   in
      c) pinCommand="${OPTARG}";;
      f) pinsFile="${OPTARG}";;
      h) showUsage=true;;
      m) acceptableModes="${OPTARG}";;
      n) promptUser=false;;
     \?) syntaxError "invalid option: -${OPTARG}";;
      :) syntaxError "missing operand: -${OPTARG}";;
      *) syntaxError "unimplemented option: -${option}";;
   esac
done
shift `expr "${OPTIND}" - 1`

"${showUsage}" && {
   cat <<END_USAGE
Usage: ${programName} [-option ...] connection-direction device-address [device-name]
-c command  The command to prompt for a PIN not in the PINs file.${defaultPinCommand:+ [${defaultPinCommand}]}
-f file     The PINs file.${defaultPinsFile:+ [${defaultPinsFile}]}
-h          This command usage summary.
-m modes    The modes (in octal) that the PINs file may have.${defaultAcceptableModes:+ [${defaultAcceptableModes}]}
-n          Do not prompt for the PIN.
END_USAGE
   exit 0
}

[ "${#}" -eq 0 ] && syntaxError "connection direction not supplied"
connectionDirection="${1}"
shift

if [ "${connectionDirection}" = "out" ]
then
   connectionAdjective="outgoing"
   connectionPreposition="to"
else
   [ "${connectionDirection}" = "in" ] || programMessage "unexpected connection direction: ${connectionDirection}"
   connectionAdjective="incoming"
   connectionPreposition="from"
fi

[ "${#}" -eq 0 ] && syntaxError "device address not supplied"
deviceAddress="${1}"
shift

if [ "${#}" -eq 0 ]
then
   deviceName=""
else
   deviceName="${1}"
   shift
fi

[ `expr " ${acceptableModes}" : ' [0-7]*$'` -eq 4 ] || syntaxError "invalid file permission modes: ${acceptableModes}"
[ "${acceptableModes#0}" = "${acceptableModes}" ] && acceptableModes="0${acceptableModes}"

[ -n "${pinsFile}" -a -f "${pinsFile}" ] && {
   if [ ! -r "${pinsFile}" ]
   then
      programMessage "file not readable: ${pinsFile}"
   else
      if [ -z "${acceptableModes}" ]
      then
         safeModes=true
      else
         safeModes=false
         if findCommand statPath stat
         then
            actualModes="`"${statPath}" -c '%a' -- "${pinsFile}"`"
            [ "${actualModes#0}" = "${actualModes}" ] && actualModes="0${actualModes}"
          # if ((actualModes & ~acceptableModes))
            if false
            then
               programMessage "unsafe file permission modes: ${pinsFile}: ${actualModes} > ${acceptableModes}"
            else
               safeModes=true
            fi
         else
            programMessage "file permission modes not verifiable: ${pinsFile}"
         fi
      fi

      "${safeModes}" && {
         exec <"${pinsFile}"
         while read address pin comment
         do
            [ "${address}" = "${deviceAddress}" ] && respondWithPin "${pin}"
         done
         exec <&-
      }
   fi
}

[ `expr " ${pinCommand}" : ' *[^ ]'` -gt 0 ] && {
   set -- ${pinCommand} "${connectionDirection}" "${deviceAddress}"
   [ -n "${deviceName}" ] && set -- "${@}" "${deviceName}"
   response="`"${@}" | head -1`"
   pin="${response#PIN:}"
   [ "${pin}" != "${response}" ] && respondWithPin "${pin}"
}

"${promptUser}" && {
   findCommand openPath open openvt && {
      dialogTitle="Bluetooth PIN Prompt"
      dialogTime="`date '+%Y-%m-%d@%H:%M:%S'`"
      dialogPrompt="Enter PIN for ${connectionAdjective} Bluetooth connection ${connectionPreposition} ${deviceName}[${deviceAddress}]"

      findCommand dialogPath dialog && {
         pin="`"${openPath}" 3>&1 -s -w -- "${dialogPath}" --output-fd 3 --clear --title "${dialogTitle}" --cr-wrap --max-input "${pinLimit}" --inputbox "${dialogTime}\n\n${dialogPrompt}" 0 0 ""`"
         [ -n "${pin}" ] && respondWithPin "${pin}"
      }
   }
}

echo "ERR"
exit 0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10 13:35                           ` Dave Mielke
@ 2006-03-10 18:10                             ` Radek Rurarz
  0 siblings, 0 replies; 25+ messages in thread
From: Radek Rurarz @ 2006-03-10 18:10 UTC (permalink / raw)
  To: bluez-devel

On Fri, 10 Mar 2006 08:35:37 -0500
Dave Mielke <dave@mielke.cc> wrote:


> No problewm. I'll take out all of the bash-specific stuff and make it
> work in plain old sh. Is there a man page for that version of sh
> which you could send me for reference?

No, there is no man or info at all ror the basic instal of Familiar
0.8.3 ( http://www.handhelds.org/moin/moin.cgi/FamiliarDistribution )

The sh is from:
BusyBox v1.00 (2006.02.18-15:37+0000) multi-call binary
( http://www.busybox.net/ I think).

--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10 17:25                           ` Dave Mielke
@ 2006-03-10 18:13                             ` Radek Rurarz
  2006-03-10 18:39                               ` Dave Mielke
  0 siblings, 1 reply; 25+ messages in thread
From: Radek Rurarz @ 2006-03-10 18:13 UTC (permalink / raw)
  To: bluez-devel

On Fri, 10 Mar 2006 12:25:25 -0500
Dave Mielke <dave@mielke.cc> wrote:


> Please try the attached updated script. I think I've removed all the
> bashisms. My /bin/sh, however, supports more than it should so it's
> hard for me to be sure.

bluepin -n gives (there is no poin in launching the promp on the iPAQ
enyway.. no keyboard):
=20
bluepin: command not found: stat
bluepin: file permission modes not verifiable: /etc/bluetooth/pins
ERR

--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10 18:13                             ` Radek Rurarz
@ 2006-03-10 18:39                               ` Dave Mielke
  2006-03-10 19:22                                 ` Radek Rurarz
  0 siblings, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-10 18:39 UTC (permalink / raw)
  To: bluez-devel

[quoted lines by Radek Rurarz on 2006/03/10 at 19:13 +0100]

>bluepin -n gives (there is no poin in launching the promp on the iPAQ
>enyway.. no keyboard):
> 
>bluepin: command not found: stat
>bluepin: file permission modes not verifiable: /etc/bluetooth/pins
>ERR

Try disabling that check by specifying a null mode, i.e.: -m ''

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10 18:39                               ` Dave Mielke
@ 2006-03-10 19:22                                 ` Radek Rurarz
  2006-03-10 20:55                                   ` Dave Mielke
  2006-03-10 20:56                                   ` Dave Mielke
  0 siblings, 2 replies; 25+ messages in thread
From: Radek Rurarz @ 2006-03-10 19:22 UTC (permalink / raw)
  To: bluez-devel

On Fri, 10 Mar 2006 13:39:33 -0500
Dave Mielke <dave@mielke.cc> wrote:

> [quoted lines by Radek Rurarz on 2006/03/10 at 19:13 +0100]
>=20
> >bluepin -n gives (there is no poin in launching the promp on the iPAQ
> >enyway.. no keyboard):
> >=20
> >bluepin: command not found: stat
> >bluepin: file permission modes not verifiable: /etc/bluetooth/pins
> >ERR
>=20
> Try disabling that check by specifying a null mode, i.e.: -m ''

bluepin: invalid file permission modes:

But I must admit, this script works better on my PC.

My regards.

--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10 19:22                                 ` Radek Rurarz
@ 2006-03-10 20:55                                   ` Dave Mielke
  2006-03-10 22:24                                     ` Radek Rurarz
  2006-03-10 20:56                                   ` Dave Mielke
  1 sibling, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-10 20:55 UTC (permalink / raw)
  To: bluez-devel

[quoted lines by Radek Rurarz on 2006/03/10 at 20:22 +0100]

>bluepin: invalid file permission modes:

Fixed. Thanks. Here's a newer version which implements 
/etc/bluetooth/bluepin.conf.  Try putting the following lines in it (indent not 
required):

   prompt no
   modes off

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10 19:22                                 ` Radek Rurarz
  2006-03-10 20:55                                   ` Dave Mielke
@ 2006-03-10 20:56                                   ` Dave Mielke
  1 sibling, 0 replies; 25+ messages in thread
From: Dave Mielke @ 2006-03-10 20:56 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

Oops! I was too hasty with the send button and forgot to attach the script. 
Here it is.

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/

[-- Attachment #2: bluepin --]
[-- Type: text/plain, Size: 8762 bytes --]

#!/bin/sh
# This script has been written by Dave Mielke <dave@mielke.cc>. It's a light 
# weight, text mode, Bluetooth PIN helper script.
#
# Step 1: The PINs file, /etc/bluetooth/pins (can be changed with the -f
# option), is searched for a line which corresponds to the Bluetooth address of
# the device. Each line in this file should contain the address of a device and
# its PIN, in that order, separated by space. Any additional data on the line
# is ignored and can be used as a comment to help identify the device. For
# example, if the address of your cell phone is 01:23:45:67:89:AB, and if its
# PIN is 12345, then its line would look like this:
#
#    01:23:45:67:89:AB 12345 my cell phone
#
# If the address is found within the PINs file then the corresponding PIN is
# returned.
#
# Step 2: If the -c option has been specified then its operand is interpreted
# as the command which is to be used to prompt the user for the PIN. If it is
# appropriately quoted so that it can contain space then options may be
# specified after the command name. It must interpret its positional parameters
# and return its response as if it were being directly invoked as a Bluetooth
# PIN helper. If it returns a PIN then that PIN is returned.
#
# Step 3: If the -n option has not been specified then the user is prompted for
# the PIN via a text-mode dialog in a free virtual terminal. The console
# automatically returns to the original virtual terminal as soon as the user
# responds to the dialog. If the response contains at least one character then
# the entire response is returned as the PIN.
#
# Step 4: Return the fact that the PIN could not be determined.
#
# Error messages are written to the system log (syslog) if "logger" is in the
# command search path ($PATH) and if standard output is not a terminal (tty or
# pty). If any of these conditions is not satisfied then errors are written to
# standard error.
#
# Invoke this script with the -h option to see its usage summary.

programName="${0##*/}"
configurationDirectory="/etc/bluetooth"
configurationFile="${configurationDirectory}/${programName}.conf"
defaultPinCommand=""
defaultPinsFile="${configurationDirectory}/pins"
defaultAcceptableModes="600"

programMessage() {
   echo >&2 "${programName}: ${1}"
}

programError() {
   programMessage "${2}" error
   exit "${1}"
}

syntaxError() {
   programError 2 "${1}"
}

setVariable() {
   eval "${1}"'="${2}"'
}

findCommand() {
   variable="${1}"
   shift
   command="${1}"

   while [ "${#}" -gt 0 ]
   do
      path="`which "${1}" 2>/dev/null`"
      [ -n "${path}" ] && {
         setVariable "${variable}" "${path}"
         return 0
      }
      shift
   done

   programMessage "command not found: ${command}"
   return 1
}

isReadableFile() {
   [ -f "${1}" ] && {
      if [ ! -r "${1}" ]
      then
         programMessage "file not readable: ${1}"
      else
         return 0
      fi
   }
   return 1
}

respondWithPin() {
   echo "PIN:${1}"
   exit 0
}

[ ! -t 1 ] && {
   findCommand loggerPath logger && {
      programMessage() {
         "${loggerPath}" -t "${programName}[${$}]" -p "daemon.${2:-warning}" -- "${1}"
      }
   }
}

showUsage=false
pinCommand="${defaultPinCommand}"
pinsFile="${defaultPinsFile}"
acceptableModes="${defaultAcceptableModes}"
promptUser=true
pinLimit=16

[ -n "${configurationFile}" ] && isReadableFile "${configurationFile}" && {
   exec <"${configurationFile}"
   lineNumber=0
   while read attribute setting
   do
      lineNumber=`expr "${lineNumber}" + 1`

      case "${attribute}"
      in
         '') continue;;
         \#*) continue;;

         command)
            variable=pinCommand
            type=string
            ;;

         file)
            variable=pinsFile
            type=word
            ;;

         modes)
            variable=acceptableModes
            type=word
            ;;

         prompt)
            variable=promptUser
            type=flag
            ;;

         *) type=invalid;;
      esac

      problem=""
      if [ "${type}" = "invalid" ]
      then
         problem="invalid attribute: ${attribute}"
      elif [ "${type}" != "string" ]
      then
         if [ "${setting}" = "" ]
         then
            problem="missing attribute setting: ${attribute}"
         else
            excess="${setting#* }"
            if [ "${excess}" != "${setting}" ]
            then
               problem="excess data: ${excess}"
            elif [ "${type}" = "flag" ]
            then
               case "${setting}"
               in
                  yes|ye|y|true|tru|tr|t) setting=true;;
                  no|n|false|fals|fal|fa|f) setting=false;;
                  *) problem="invalid flag setting: ${setting}";;
               esac
            elif [ "${type}" = "word" ]
            then
               [ "${setting}" = "off" ] && setting=""
            else
               problem="unimplemented attribute type: ${type}"
            fi
         fi
      fi

      if [ -n "${problem}" ]
      then
         programMessage "error at ${configurationFile}[${lineNumber}]: ${problem}"
      else
         setVariable "${variable}" "${setting}"
      fi
   done
   exec <&-
}

while getopts ":c:f:hm:n" option
do
   case "${option}"
   in
      c) pinCommand="${OPTARG}";;
      f) pinsFile="${OPTARG}";;
      h) showUsage=true;;
      m) acceptableModes="${OPTARG}";;
      n) promptUser=false;;
     \?) syntaxError "invalid option: -${OPTARG}";;
      :) syntaxError "missing operand: -${OPTARG}";;
      *) syntaxError "unimplemented option: -${option}";;
   esac
done
shift `expr "${OPTIND}" - 1`

"${showUsage}" && {
   cat <<END_USAGE
Usage: ${programName} [-option ...] connection-direction device-address [device-name]
-c command  The command to prompt for a PIN not in the PINs file.${defaultPinCommand:+ [${defaultPinCommand}]}
-f file     The PINs file.${defaultPinsFile:+ [${defaultPinsFile}]}
-h          This command usage summary.
-m modes    The modes (in octal) that the PINs file may have.${defaultAcceptableModes:+ [${defaultAcceptableModes}]}
-n          Do not prompt for the PIN.
END_USAGE
   exit 0
}

[ "${#}" -eq 0 ] && syntaxError "connection direction not supplied"
connectionDirection="${1}"
shift

if [ "${connectionDirection}" = "out" ]
then
   connectionAdjective="outgoing"
   connectionPreposition="to"
else
   [ "${connectionDirection}" = "in" ] || programMessage "unexpected connection direction: ${connectionDirection}"
   connectionAdjective="incoming"
   connectionPreposition="from"
fi

[ "${#}" -eq 0 ] && syntaxError "device address not supplied"
deviceAddress="${1}"
shift

if [ "${#}" -eq 0 ]
then
   deviceName=""
else
   deviceName="${1}"
   shift
fi

[ -n "${acceptableModes}" ] && {
   [ `expr " ${acceptableModes}" : ' [0-7]*$'` -eq 4 ] || syntaxError "invalid file permission modes: ${acceptableModes}"
   [ "${acceptableModes#0}" = "${acceptableModes}" ] && acceptableModes="0${acceptableModes}"
}

[ -n "${pinsFile}" ] && isReadableFile "${pinsFile}" && {
   if [ -z "${acceptableModes}" ]
   then
      safeModes=true
   else
      safeModes=false
      if findCommand statPath stat
      then
         actualModes="`"${statPath}" -c '%a' -- "${pinsFile}"`"
         [ "${actualModes#0}" = "${actualModes}" ] && actualModes="0${actualModes}"
#fix     if ((actualModes & ~acceptableModes))
         if false
         then
            programMessage "unsafe file permission modes: ${pinsFile}: ${actualModes} > ${acceptableModes}"
         else
            safeModes=true
         fi
      else
         programMessage "file permission modes not verifiable: ${pinsFile}"
      fi
   fi

   "${safeModes}" && {
      exec <"${pinsFile}"
      while read address pin comment
      do
         [ "${address}" = "${deviceAddress}" ] && respondWithPin "${pin}"
      done
      exec <&-
   }
}

[ `expr " ${pinCommand}" : ' *[^ ]'` -gt 0 ] && {
   set -- ${pinCommand} "${connectionDirection}" "${deviceAddress}"
   [ -n "${deviceName}" ] && set -- "${@}" "${deviceName}"
   response="`"${@}" | head -1`"
   pin="${response#PIN:}"
   [ "${pin}" != "${response}" ] && respondWithPin "${pin}"
}

"${promptUser}" && {
   findCommand openPath open openvt && {
      dialogTitle="Bluetooth PIN Prompt"
      dialogTime="`date '+%Y-%m-%d@%H:%M:%S'`"
      dialogPrompt="Enter PIN for ${connectionAdjective} Bluetooth connection ${connectionPreposition} ${deviceName}[${deviceAddress}]"

      findCommand dialogPath dialog && {
         pin="`"${openPath}" 3>&1 -s -w -- "${dialogPath}" --output-fd 3 --clear --title "${dialogTitle}" --cr-wrap --max-input "${pinLimit}" --inputbox "${dialogTime}\n\n${dialogPrompt}" 0 0 ""`"
         [ -n "${pin}" ] && respondWithPin "${pin}"
      }
   }
}

echo "ERR"
exit 0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10 20:55                                   ` Dave Mielke
@ 2006-03-10 22:24                                     ` Radek Rurarz
  2006-03-10 23:04                                       ` Dave Mielke
  0 siblings, 1 reply; 25+ messages in thread
From: Radek Rurarz @ 2006-03-10 22:24 UTC (permalink / raw)
  To: bluez-devel

On Fri, 10 Mar 2006 15:55:04 -0500
Dave Mielke <dave@mielke.cc> wrote:

> [quoted lines by Radek Rurarz on 2006/03/10 at 20:22 +0100]
>=20
> >bluepin: invalid file permission modes:
>=20
> Fixed. Thanks. Here's a newer version which implements=20
> /etc/bluetooth/bluepin.conf.  Try putting the following lines in it
> (indent not required):
>=20
>    prompt no
>    modes off

Works.. both on PC and the iPAQ..

Thank you :)

--=20
Rados=B3aw Rurarz
Warsaw Poland
GG: 7249330


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10 22:24                                     ` Radek Rurarz
@ 2006-03-10 23:04                                       ` Dave Mielke
  2006-03-13  4:08                                         ` KrAnTi KaMbHaMpAtI
  0 siblings, 1 reply; 25+ messages in thread
From: Dave Mielke @ 2006-03-10 23:04 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 1133 bytes --]

[quoted lines by Radek Rurarz on 2006/03/10 at 23:24 +0100]

>Works.. both on PC and the iPAQ..

Excellent! Here's a slightly newer copy wherein the -h output shows what can go
into the configuration file as well as what should go into the pins file. 

There's just one line I need to fix as it still uses a bashism which I have yet
to figure out how to do in Bourne Shell syntax. It's commented out for the time
being (look for #fix). The effect of this is that the file mode check isn't
being enforced.

Assuming that I'm not being too presumptuous, what's the right way to now go
about requesting that this script become the new PIN helper? My suggestion is
to rename the current helper to xbluepin, and to place at least "command
xbluepin" into the configuration file for this script.

Can anyone think of any more enhancements?

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave@mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://FamilyRadio.com/                   | http://Mielke.cc/bible/

[-- Attachment #2: bluepin --]
[-- Type: text/plain, Size: 9153 bytes --]

#!/bin/sh
# This script has been written by Dave Mielke <dave@mielke.cc>. It's a light 
# weight, text mode, Bluetooth PIN helper script.
#
# Step 1: The PINs file, /etc/bluetooth/pins (can be changed with the -f
# option), is searched for a line which corresponds to the Bluetooth address of
# the device. Each line in this file should contain the address of a device and
# its PIN, in that order, separated by space. Any additional data on the line
# is ignored and can be used as a comment to help identify the device. For
# example, if the address of your cell phone is 01:23:45:67:89:AB, and if its
# PIN is 12345, then its line would look like this:
#
#    01:23:45:67:89:AB 12345 my cell phone
#
# If the address is found within the PINs file then the corresponding PIN is
# returned.
#
# Step 2: If the -c option has been specified then its operand is interpreted
# as the command which is to be used to prompt the user for the PIN. If it is
# appropriately quoted so that it can contain space then options may be
# specified after the command name. It must interpret its positional parameters
# and return its response as if it were being directly invoked as a Bluetooth
# PIN helper. If it returns a PIN then that PIN is returned.
#
# Step 3: If the -n option has not been specified then the user is prompted for
# the PIN via a text-mode dialog in a free virtual terminal. The console
# automatically returns to the original virtual terminal as soon as the user
# responds to the dialog. If the response contains at least one character then
# the entire response is returned as the PIN.
#
# Step 4: Return the fact that the PIN could not be determined.
#
# Error messages are written to the system log (syslog) if "logger" is in the
# command search path ($PATH) and if standard output is not a terminal (tty or
# pty). If any of these conditions is not satisfied then errors are written to
# standard error.
#
# Invoke this script with the -h option to see a summary of its options,
# parameters, and configuration file syntax.

programName="${0##*/}"
configurationDirectory="/etc/bluetooth"
configurationFile="${configurationDirectory}/${programName}.conf"
defaultPinCommand=""
defaultPinsFile="${configurationDirectory}/pins"
defaultAcceptableModes="600"

programMessage() {
   echo >&2 "${programName}: ${1}"
}

programError() {
   programMessage "${2}" error
   exit "${1}"
}

syntaxError() {
   programError 2 "${1}"
}

setVariable() {
   eval "${1}"'="${2}"'
}

findCommand() {
   variable="${1}"
   shift
   command="${1}"

   while [ "${#}" -gt 0 ]
   do
      path="`which "${1}" 2>/dev/null`"
      [ -n "${path}" ] && {
         setVariable "${variable}" "${path}"
         return 0
      }
      shift
   done

   programMessage "command not found: ${command}"
   return 1
}

isReadableFile() {
   [ -f "${1}" ] && {
      if [ ! -r "${1}" ]
      then
         programMessage "file not readable: ${1}"
      else
         return 0
      fi
   }
   return 1
}

respondWithPin() {
   echo "PIN:${1}"
   exit 0
}

[ ! -t 1 ] && {
   findCommand loggerPath logger && {
      programMessage() {
         "${loggerPath}" -t "${programName}[${$}]" -p "daemon.${2:-warning}" -- "${1}"
      }
   }
}

showUsage=false
pinCommand="${defaultPinCommand}"
pinsFile="${defaultPinsFile}"
acceptableModes="${defaultAcceptableModes}"
promptUser=true
pinLimit=16

[ -n "${configurationFile}" ] && isReadableFile "${configurationFile}" && {
   exec <"${configurationFile}"
   lineNumber=0
   while read attribute setting
   do
      lineNumber=`expr "${lineNumber}" + 1`

      case "${attribute}"
      in
         '') continue;;
         \#*) continue;;

         command)
            variable=pinCommand
            type=string
            ;;

         file)
            variable=pinsFile
            type=word
            ;;

         modes)
            variable=acceptableModes
            type=word
            ;;

         prompt)
            variable=promptUser
            type=flag
            ;;

         *) type=invalid;;
      esac

      problem=""
      if [ "${type}" = "invalid" ]
      then
         problem="invalid attribute: ${attribute}"
      elif [ "${type}" != "string" ]
      then
         if [ "${setting}" = "" ]
         then
            problem="missing attribute setting: ${attribute}"
         else
            excess="${setting#* }"
            if [ "${excess}" != "${setting}" ]
            then
               problem="excess data: ${excess}"
            elif [ "${type}" = "flag" ]
            then
               case "${setting}"
               in
                  yes|ye|y|true|tru|tr|t|on) setting=true;;
                  no|n|false|fals|fal|fa|f|off|of) setting=false;;
                  *) problem="invalid flag setting: ${setting}";;
               esac
            elif [ "${type}" = "word" ]
            then
               [ "${setting}" = "off" ] && setting=""
            else
               problem="unimplemented attribute type: ${type}"
            fi
         fi
      fi

      if [ -n "${problem}" ]
      then
         programMessage "error at ${configurationFile}[${lineNumber}]: ${problem}"
      else
         setVariable "${variable}" "${setting}"
      fi
   done
   exec <&-
}

while getopts ":c:f:hm:n" option
do
   case "${option}"
   in
      c) pinCommand="${OPTARG}";;
      f) pinsFile="${OPTARG}";;
      h) showUsage=true;;
      m) acceptableModes="${OPTARG}";;
      n) promptUser=false;;
     \?) syntaxError "invalid option: -${OPTARG}";;
      :) syntaxError "missing operand: -${OPTARG}";;
      *) syntaxError "unimplemented option: -${option}";;
   esac
done
shift `expr "${OPTIND}" - 1`

"${showUsage}" && {
   cat <<END_USAGE
Usage: ${programName} [-option ...] connection-direction device-address [device-name]
Options:
   -c command  The command to prompt for a PIN not in the PINs file.${defaultPinCommand:+ [${defaultPinCommand}]}
   -f file     The PINs file.${defaultPinsFile:+ [${defaultPinsFile}]}
   -h          This command usage summary.
   -m modes    The modes (3 octal digits) that the PINs file may have.${defaultAcceptableModes:+ [${defaultAcceptableModes}]}
   -n          Do not prompt for the PIN.

Configuration File Syntax: [${configurationFile}]
   # comment (blank lines are ignored too)
   file {/path/to/pins-file | off}
   modes {three-digit-octal-number | off}
   command [name [argument ...]]
   prompt {yes | no}

PINs File Syntax: [${defaultPinsFile}]
   device-address PIN comment ...
END_USAGE
   exit 0
}

[ "${#}" -eq 0 ] && syntaxError "connection direction not supplied"
connectionDirection="${1}"
shift

if [ "${connectionDirection}" = "out" ]
then
   connectionAdjective="outgoing"
   connectionPreposition="to"
else
   [ "${connectionDirection}" = "in" ] || programMessage "unexpected connection direction: ${connectionDirection}"
   connectionAdjective="incoming"
   connectionPreposition="from"
fi

[ "${#}" -eq 0 ] && syntaxError "device address not supplied"
deviceAddress="${1}"
shift

if [ "${#}" -eq 0 ]
then
   deviceName=""
else
   deviceName="${1}"
   shift
fi

[ -n "${acceptableModes}" ] && {
   [ `expr " ${acceptableModes}" : ' [0-7]*$'` -eq 4 ] || syntaxError "invalid file permission modes: ${acceptableModes}"
   [ "${acceptableModes#0}" = "${acceptableModes}" ] && acceptableModes="0${acceptableModes}"
}

[ -n "${pinsFile}" ] && isReadableFile "${pinsFile}" && {
   if [ -z "${acceptableModes}" ]
   then
      safeModes=true
   else
      safeModes=false
      if findCommand statPath stat
      then
         actualModes="`"${statPath}" -c '%a' -- "${pinsFile}"`"
         [ "${actualModes#0}" = "${actualModes}" ] && actualModes="0${actualModes}"
#fix     if ((actualModes & ~acceptableModes))
         if false
         then
            programMessage "unsafe file permission modes: ${pinsFile}: ${actualModes} > ${acceptableModes}"
         else
            safeModes=true
         fi
      else
         programMessage "file permission modes not verifiable: ${pinsFile}"
      fi
   fi

   "${safeModes}" && {
      exec <"${pinsFile}"
      while read address pin comment
      do
         [ "${address}" = "${deviceAddress}" ] && respondWithPin "${pin}"
      done
      exec <&-
   }
}

[ `expr " ${pinCommand}" : ' *[^ ]'` -gt 0 ] && {
   set -- ${pinCommand} "${connectionDirection}" "${deviceAddress}"
   [ -n "${deviceName}" ] && set -- "${@}" "${deviceName}"
   response="`"${@}" | head -1`"
   pin="${response#PIN:}"
   [ "${pin}" != "${response}" ] && respondWithPin "${pin}"
}

"${promptUser}" && {
   findCommand openPath open openvt && {
      dialogTitle="Bluetooth PIN Prompt"
      dialogTime="`date '+%Y-%m-%d@%H:%M:%S'`"
      dialogPrompt="Enter PIN for ${connectionAdjective} Bluetooth connection ${connectionPreposition} ${deviceName}[${deviceAddress}]"

      findCommand dialogPath dialog && {
         pin="`"${openPath}" 3>&1 -s -w -- "${dialogPath}" --output-fd 3 --clear --title "${dialogTitle}" --cr-wrap --max-input "${pinLimit}" --inputbox "${dialogTime}\n\n${dialogPrompt}" 0 0 ""`"
         [ -n "${pin}" ] && respondWithPin "${pin}"
      }
   }
}

echo "ERR"
exit 0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Bluez-devel] PIN helper
  2006-03-10 23:04                                       ` Dave Mielke
@ 2006-03-13  4:08                                         ` KrAnTi KaMbHaMpAtI
  0 siblings, 0 replies; 25+ messages in thread
From: KrAnTi KaMbHaMpAtI @ 2006-03-13  4:08 UTC (permalink / raw)
  To: bluez-devel

a side question related to this....

Is it possible to support multiple fixed passkeys like
"0000", "1234" etc.,

Rgds,
-K


--- Dave Mielke <dave@mielke.cc> wrote:

> [quoted lines by Radek Rurarz on 2006/03/10 at 23:24
> +0100]
> 
> >Works.. both on PC and the iPAQ..
> 
> Excellent! Here's a slightly newer copy wherein the
> -h output shows what can go
> into the configuration file as well as what should
> go into the pins file. 
> 
> There's just one line I need to fix as it still uses
> a bashism which I have yet
> to figure out how to do in Bourne Shell syntax. It's
> commented out for the time
> being (look for #fix). The effect of this is that
> the file mode check isn't
> being enforced.
> 
> Assuming that I'm not being too presumptuous, what's
> the right way to now go
> about requesting that this script become the new PIN
> helper? My suggestion is
> to rename the current helper to xbluepin, and to
> place at least "command
> xbluepin" into the configuration file for this
> script.
> 
> Can anyone think of any more enhancements?
> 
> -- 
> Dave Mielke           | 2213 Fox Crescent | I
> believe that the Bible is the
> Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of
> God. Please contact me
> EMail: dave@mielke.cc | Canada  K2A 1H7   | if
> you're concerned about Hell.
> http://FamilyRadio.com/                   |
> http://Mielke.cc/bible/
> > #!/bin/sh
> # This script has been written by Dave Mielke
> <dave@mielke.cc>. It's a light 
> # weight, text mode, Bluetooth PIN helper script.
> #
> # Step 1: The PINs file, /etc/bluetooth/pins (can be
> changed with the -f
> # option), is searched for a line which corresponds
> to the Bluetooth address of
> # the device. Each line in this file should contain
> the address of a device and
> # its PIN, in that order, separated by space. Any
> additional data on the line
> # is ignored and can be used as a comment to help
> identify the device. For
> # example, if the address of your cell phone is
> 01:23:45:67:89:AB, and if its
> # PIN is 12345, then its line would look like this:
> #
> #    01:23:45:67:89:AB 12345 my cell phone
> #
> # If the address is found within the PINs file then
> the corresponding PIN is
> # returned.
> #
> # Step 2: If the -c option has been specified then
> its operand is interpreted
> # as the command which is to be used to prompt the
> user for the PIN. If it is
> # appropriately quoted so that it can contain space
> then options may be
> # specified after the command name. It must
> interpret its positional parameters
> # and return its response as if it were being
> directly invoked as a Bluetooth
> # PIN helper. If it returns a PIN then that PIN is
> returned.
> #
> # Step 3: If the -n option has not been specified
> then the user is prompted for
> # the PIN via a text-mode dialog in a free virtual
> terminal. The console
> # automatically returns to the original virtual
> terminal as soon as the user
> # responds to the dialog. If the response contains
> at least one character then
> # the entire response is returned as the PIN.
> #
> # Step 4: Return the fact that the PIN could not be
> determined.
> #
> # Error messages are written to the system log
> (syslog) if "logger" is in the
> # command search path ($PATH) and if standard output
> is not a terminal (tty or
> # pty). If any of these conditions is not satisfied
> then errors are written to
> # standard error.
> #
> # Invoke this script with the -h option to see a
> summary of its options,
> # parameters, and configuration file syntax.
> 
> programName="${0##*/}"
> configurationDirectory="/etc/bluetooth"
>
configurationFile="${configurationDirectory}/${programName}.conf"
> defaultPinCommand=""
> defaultPinsFile="${configurationDirectory}/pins"
> defaultAcceptableModes="600"
> 
> programMessage() {
>    echo >&2 "${programName}: ${1}"
> }
> 
> programError() {
>    programMessage "${2}" error
>    exit "${1}"
> }
> 
> syntaxError() {
>    programError 2 "${1}"
> }
> 
> setVariable() {
>    eval "${1}"'="${2}"'
> }
> 
> findCommand() {
>    variable="${1}"
>    shift
>    command="${1}"
> 
>    while [ "${#}" -gt 0 ]
>    do
>       path="`which "${1}" 2>/dev/null`"
>       [ -n "${path}" ] && {
>          setVariable "${variable}" "${path}"
>          return 0
>       }
>       shift
>    done
> 
>    programMessage "command not found: ${command}"
>    return 1
> }
> 
> isReadableFile() {
>    [ -f "${1}" ] && {
>       if [ ! -r "${1}" ]
>       then
>          programMessage "file not readable: ${1}"
>       else
>          return 0
>       fi
>    }
>    return 1
> }
> 
> respondWithPin() {
>    echo "PIN:${1}"
>    exit 0
> }
> 
> [ ! -t 1 ] && {
>    findCommand loggerPath logger && {
>       programMessage() {
>          "${loggerPath}" -t "${programName}[${$}]"
> -p "daemon.${2:-warning}" -- "${1}"
>       }
>    }
> }
> 
> showUsage=false
> pinCommand="${defaultPinCommand}"
> pinsFile="${defaultPinsFile}"
> acceptableModes="${defaultAcceptableModes}"
> promptUser=true
> pinLimit=16
> 
> [ -n "${configurationFile}" ] && isReadableFile
> "${configurationFile}" && {
>    exec <"${configurationFile}"
>    lineNumber=0
>    while read attribute setting
>    do
>       lineNumber=`expr "${lineNumber}" + 1`
> 
>       case "${attribute}"
>       in
>          '') continue;;
>          \#*) continue;;
> 
>          command)
>             variable=pinCommand
>             type=string
>             ;;
> 
>          file)
>             variable=pinsFile
>             type=word
>             ;;
> 
>          modes)
>             variable=acceptableModes
>             type=word
>             ;;
> 
>          prompt)
>             variable=promptUser
>             type=flag
>             ;;
> 
>          *) type=invalid;;
>       esac
> 
>       problem=""
>       if [ "${type}" = "invalid" ]
>       then
>          problem="invalid attribute: ${attribute}"
>       elif [ "${type}" != "string" ]
>       then
>          if [ "${setting}" = "" ]
>          then
>             problem="missing attribute setting:
> ${attribute}"
>          else
>             excess="${setting#* }"
>             if [ "${excess}" != "${setting}" ]
>             then
>                problem="excess data: ${excess}"
>             elif [ "${type}" = "flag" ]
>             then
>                case "${setting}"
>                in
>                   yes|ye|y|true|tru|tr|t|on)
> setting=true;;
>                   no|n|false|fals|fal|fa|f|off|of)
> setting=false;;
>                   *) problem="invalid flag setting:
> ${setting}";;
>                esac
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2006-03-13  4:08 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-08 21:19 [Bluez-devel] PIN helper Radek
2006-03-08 21:40 ` Dave Mielke
2006-03-08 22:01   ` Radek Rurarz
2006-03-08 22:16     ` Dave Mielke
2006-03-09  5:44       ` Radek Rurarz
2006-03-09  5:55         ` Dave Mielke
2006-03-09  6:06           ` Radek Rurarz
2006-03-09  6:12             ` Dave Mielke
2006-03-09 18:29               ` Radek Rurarz
2006-03-09 19:34                 ` Dave Mielke
2006-03-09 21:55                   ` Radek Rurarz
2006-03-09 22:04                     ` Radek Rurarz
2006-03-10  1:33                       ` Dave Mielke
2006-03-10  7:28                         ` Radek Rurarz
2006-03-10 13:35                           ` Dave Mielke
2006-03-10 18:10                             ` Radek Rurarz
2006-03-10 17:25                           ` Dave Mielke
2006-03-10 18:13                             ` Radek Rurarz
2006-03-10 18:39                               ` Dave Mielke
2006-03-10 19:22                                 ` Radek Rurarz
2006-03-10 20:55                                   ` Dave Mielke
2006-03-10 22:24                                     ` Radek Rurarz
2006-03-10 23:04                                       ` Dave Mielke
2006-03-13  4:08                                         ` KrAnTi KaMbHaMpAtI
2006-03-10 20:56                                   ` Dave Mielke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).