-2

I'm trying to fix a bug in my code. Some parts I've already fixed. Now I get this error ...

    TypeError in Ldap#getAccount

Showing /home/stadler/tool/app/views/layouts/_stylesheets.html.erb where line #5 raised:

wrong argument type #<Class:0xb996604> (expected Data)

Extracted source (around line #5):

2: <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
3: <![endif]-->
4: <%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
5: <!--<%= stylesheet_link_tag 'blueprint/print',  :media => 'print' %>-->
6: <!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->
7: <%= stylesheet_link_tag 'custom', :media => 'screen' %>

Trace of template inclusion: app/views/layouts/application.html.erb

Rails.root: /home/stadler/tool
Application Trace | Framework Trace | Full Trace

app/views/layouts/_stylesheets.html.erb:5:in `_app_views_layouts__stylesheets_html_erb__369773416_97305840'
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___101889169_97634680'

Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"kaADQKjwVLpyTx36sZjq+ZYgdrrlWIWLFdlbCDHgDIQ=",
 "id"=>"666667",
 "commit"=>"Gibs mir ja!"}

The bugs started as I implemented this method in one of my controllers.

    def getGridNumber(group)
     base = "ou=Groups, dc=-, dc=-, dc=-"
     filter = 'cn='+group
     puts filter
     attrs = ['gidNumber']
     puts group
     conn = LDAP::Conn.new($HOST, $PORT)
     conn.bind('cn=admin, dc=-, dc=-, dc=-','-')

     conn.perror("bind")

     begin
       conn.search(base, $scope, filter, attrs) { |entry|
       @gridNumber=entry.vals('gidNumber').first
       puts entry.vals('gidNumber')
       }
     rescue LDAP::ResultError
       conn.perror("search")
       exit
     end
     conn.perror("search")
     conn.unbind
     end

I use this method in this part:

      def addAccount
   conn = LDAP::Conn.new($HOST, $PORT)
   conn.bind('cn=admin, dc=-, dc=-, dc=de','-')

   conn.perror("bind")
   pw=params[:userpassword]
   genPasswd(pw)
   getGridNumber(params[:group])
   for i in 2000 ... 7000 do
   filter = 'uidNumber='+i.to_s
   array=conn.search2($base, $scope, filter, ['*'])
     if array.size == 0 then 
       @uidnumber=i
       break
     end
   end   

   entry = [
   LDAP.mod(LDAP::LDAP_MOD_ADD,'objectClass',["account","posixAccount","top","shadowAccount","sambaSamAccount","eClara"]),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'uid',params[:uid].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'uidNumber',[@uidnumber.to_s]),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'gidNumber',[@gridNumber]),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'homeDirectory',['/home/stadler/tool/test/'+params[:uid]]),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'gecos',params[:gecos].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'shadowLastChange',params[:shadowlastchange].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'sambaLogoffTime',params[:sambalogofftime].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'displayName',params[:displayname].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'cn',params[:uid].split()),
   #LDAP.mod(LDAP::LDAP_MOD_ADD,'loginShell',params[:loginshell].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'loginShell',['/bin/bash']),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'sambaLMPassword',params[:sambalmpassword].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'sambaNTPassword',params[:sambantpassword].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'sambaLogonTime',params[:sambalogontime].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'userPassword',[@slappedpwd]),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'lernStatus1',params[:lernstatus1].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'sambaPwdMustChange',params[:sambapwdmustchange].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'sambaKickoffTime',params[:sambakickofftime].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'sambaPwdCanChange',params[:sambapwdcanchange].split()),
   LDAP.mod(LDAP::LDAP_MOD_ADD,'sambaSID',params[:sambasid].split()),
]

    begin
      address= 'uid='+params[:uid]+', ou=Users, dc=cippool-mb, dc=rwth-aachen, dc=de'
      conn.add(address, entry)
      FileUtils.mkdir '/home/stadler/tool/test/'+params[:uid], :mode => 0700
      FileUtils.chown 'stadler', 'stadler', '/home/stadler/tool/test/'+params[:uid] 
      FileUtils.remove_dir('tmp') 
      flash[:success] = "Account added!"

    rescue LDAP::ResultError
      conn.perror("add")
      flash[:error] = "WTF!!!!! Already there! " 
      #exit
    end
      conn.perror("add")
      conn.unbind
    redirect_to :action => "getAllAccounts"
  end

I try to get more information, but first of all, could someone tell me what wrong argument type #<Class:0xb996604> (expected Data) means?

Terry Gardner
  • 10,957
  • 2
  • 28
  • 38
gadreel
  • 207
  • 1
  • 2
  • 13
  • First part: This is the error message with the links to css stylesheets, which I first used from a tutorial. This error occurs, if I use my addAccount function, which works and switch back to another page. i.e. a overiew about clients in the network or a simple "home" page. – gadreel Jul 25 '12 at 18:41
  • Second Part: I implemented this part and after that, the first errors occured. In this code I use a simple LDAP search where I get the id for a certain group. – gadreel Jul 25 '12 at 18:43
  • Third part: There I store a password in a special format, which never produced errors. Then I search for a free uid in a certain range in the database. With this number, I use the normal LDAP add methods. In the last part is self understanding. – gadreel Jul 25 '12 at 18:47
  • The things which maybe the errors produce are getGridNumber(params[:group]) and then LDAP.mod(LDAP::LDAP_MOD_ADD,'gidNumber',[@gridNumber]) where I use the number. – gadreel Jul 25 '12 at 18:48
  • I use Rails 3.2.6 and Ruby/LDAP. I have no idea, which informations could help, because everything works except this error when I switch to another page after I used the addAccount method. – gadreel Jul 25 '12 at 18:51
  • Suppose you tell us which is line 5? – user207421 Jul 26 '12 at 02:02
  • You can see it in the first part. I also commented it out. 5: . It links to a normal css file which worked all the time. – gadreel Jul 26 '12 at 09:07

1 Answers1

0

I did a recoding of my base frame and now the error is gone. I just got an error, one time when i switched a page. The methods I used are the same, I only switched to bootstrap, less and Rails 3.2.6. Maybe it's an stylesheet problem, but I don't know, because the error occured only one time yet and it was suddenly.

    Started GET "/assets/bootstrap-modal.js?body=1" for 127.0.0.1 at 2012-07-27 15:00:11 +0200
Served asset /bootstrap-modal.js - 304 Not Modified (1ms)
[2012-07-27 15:00:12] ERROR TypeError: wrong argument type #<Class:0xbd41740> (expected Data)
    /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/rack/log_tailer.rb:29:in `write'
    /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/rack/log_tailer.rb:29:in `print'
    /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/rack/log_tailer.rb:29:in `tail!'
    /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/rack/log_tailer.rb:18:in `call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
    /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
    /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
    /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

-

module Rails
  module Rack
    class LogTailer
          def initialize(app, log = nil)
            @app = app

            path = Pathname.new(log || "#{::File.expand_path(Rails.root)}/log/#{Rails.env}.log").cleanpath

            @cursor = @file = nil
            if ::File.exists?(path)
              @cursor = ::File.size(path)
              @file = ::File.open(path, 'r')
            end
          end

          def call(env)
            response = @app.call(env)
            tail!
            response
          end

          def tail!
            return unless @cursor
            @file.seek @cursor

            unless @file.eof?
              contents = @file.read
              @cursor = @file.tell
              $stdout.print contents
            end
          end
        end
      end
    end
gadreel
  • 207
  • 1
  • 2
  • 13