rstyx 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # Copyright (C) 2005-2007 Rafael Sevilla
4
+ # This file is part of RStyx
5
+ #
6
+ # RStyx is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as
8
+ # published by the Free Software Foundation; either version 2.1
9
+ # of the License, or (at your option) any later version.
10
+ #
11
+ # RStyx is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with RStyx; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St., Fifth Floor, Boston, MA
19
+ # 02110-1301 USA.
20
+ #
21
+ # Authentication modules
22
+ #
23
+ # Author:: Rafael R. Sevilla (mailto:dido@imperium.ph)
24
+ # Copyright:: Copyright (c) 2005,2006 Rafael R. Sevilla
25
+ # License:: GNU Lesser General Public License
26
+ #
27
+ # $Id: authmodules.rb 190 2007-06-04 06:53:54Z dido $
28
+ #
29
+
30
+ module RStyx
31
+
32
+ module ClientAuth
33
+
34
+ class AuthModule
35
+ ##
36
+ # Given a pre-authenticated Styx server connection, execute
37
+ # an authentication protocol on it, and return a working
38
+ # authenticated rfid.
39
+ #
40
+ def authenticate(conn)
41
+ end
42
+ end
43
+
44
+ ##
45
+ # Clear password authenticated connection. Frankly, this is a whole
46
+ # load of bunkum. I have nothing substantial to test this
47
+ # authentication code against but apparently it is what JStyx does
48
+ # and so perhaps it should work with a JStyx-based server and thus
49
+ # presumably some version of Plan 9, but apparently it's an
50
+ # authentication procedure not supported by any real version of
51
+ # Inferno I have. :-/ Oh, and it ought to work just fine with the
52
+ # server code, right?
53
+ #
54
+ class ClearPasswordAuth < AuthModule
55
+ def initialize(u, p)
56
+ @username = u
57
+ @password = p
58
+ end
59
+
60
+ def authenticate(conn)
61
+ afid = conn.get_free_fid
62
+ rauth = send_message(Message::Tauth.new(:uname => @username,
63
+ :afid => afid,
64
+ :aname => ""))
65
+ # We now have the fid to an authentication file. We write the
66
+ # password into this file.
67
+ authfile = Client::File.new(conn, "/auth")
68
+ authfile.fid = afid
69
+ authfile.qid = rauth.aqid
70
+ # suitable iounit
71
+ authfile.iounit = 8216
72
+ # If this write succeeds, the server accepted our password,
73
+ # otherwise, this call will throw an exception and
74
+ # authentication fails. XXX -- this ought to throw a properly
75
+ # formatted error rather than the normal write errors. It
76
+ # should be tested.
77
+ authfile._syswrite(@password, 0)
78
+ # If we get here without any errors we should be able to
79
+ # attach using the afid we got.
80
+ rfid = get_free_fid
81
+ rattach = send_message(Message::Tattach.new(:fid => rfid,
82
+ :afid => afid,
83
+ :uname => @username))
84
+ return(rfid)
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ end