ipso 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/rc
  2. if(! ~ $service terminal){
  3. echo >[1=2] ipso should be run only on the terminal
  4. exit terminal
  5. }
  6. path=(/bin)
  7. home=(/tmp)
  8. editor = (acme -c1)
  9. name = secstore
  10. get = secstoreget
  11. put = secstoreput
  12. fn secstoreget{
  13. auth/secstore -i -g $1 <_password
  14. }
  15. fn secstoreput{
  16. auth/secstore -i -p $1 <_password
  17. }
  18. fn aesget{
  19. if(! ~ $1 /*){
  20. echo >[1=2] ipso: aescbc requires fully qualified pathname
  21. exit usage
  22. }
  23. auth/aescbc -i -d < $1 > `{basename $1} <[3] _password
  24. }
  25. fn aesput{
  26. auth/aescbc -i -e > $1 < `{basename $1} <[3] _password
  27. }
  28. fn editedfiles{
  29. if(~ $get aesget){
  30. for(i in $files)
  31. if(ls -tr | sed '1,/^_timestamp$/d' | grep -s '^'^`{basename $i}^'$')
  32. echo $i
  33. }
  34. if not
  35. ls -tr | sed '1,/^_timestamp$/d'
  36. }
  37. while(~ $1 -*){
  38. switch($1){
  39. case -s
  40. editor = sam
  41. case -a
  42. name = aescbc
  43. get = aesget
  44. put = aesput
  45. case *
  46. echo >[2=1] 'usage: ipso [-s] [file ...]'
  47. exit usage
  48. }
  49. shift
  50. }
  51. if(~ $get aesget && ~ $#* 0){
  52. echo >[2=1] ipso: must specify a fully qualified file name for aescbc '(-a)'
  53. exit usage
  54. }
  55. rfork ne
  56. ramfs -p >[2] /dev/null # silence 'i/o on hungup channel' message at exit
  57. unmount /mnt/plumb
  58. bind -c /tmp /srv
  59. cd /tmp
  60. echo '
  61. Warning: The editor will display the secret contents of
  62. your '$name' files in the clear.
  63. '
  64. # get password and remember it
  65. {
  66. echo rawon
  67. echo -n $name password: >/dev/cons
  68. read > _password
  69. echo > /dev/cons
  70. }</dev/cons > /dev/consctl
  71. # get list of files
  72. if(~ $#* 0){
  73. if(! auth/secstore -G . -i < _password > _listing){
  74. echo 'secstore read failed - bad password?'
  75. sleep 2
  76. exit password
  77. }
  78. files=`{sed 's/[ ]+.*//' _listing}
  79. }
  80. if not
  81. files = $*
  82. # copy the files to local ramfs
  83. for(i in $files){
  84. if(! $get $i){
  85. echo $name ' read failed - bad password?'
  86. sleep 2
  87. exit password
  88. }
  89. }
  90. sleep 2; date > _timestamp # so we can find which files have been edited.
  91. # edit the files
  92. $editor `{for(i in $files) basename $i}
  93. # copy the files back
  94. for(i in `{editedfiles}){
  95. echo -n copy ''''`{basename $i}^'''' back?' [y/n/x]'
  96. switch(`{read}){
  97. case [yY]*
  98. if(! $put $i){
  99. echo $name ' read failed - bad password?'
  100. sleep 2
  101. exit password
  102. }
  103. echo ''''$i'''' copied to $name
  104. if(~ $i factotum)
  105. read -m < $i > /mnt/factotum/ctl
  106. case [xXqQ]*
  107. exit
  108. case [nN]* *
  109. echo ''''$i'''' skipped
  110. }
  111. }
  112. exit ''