11 Replies Latest reply: Feb 29, 2012 2:31 AM by Sudheendra-Oracle RSS

    OCIAttrGet function

    902884
      Hi

      How do i make a call to OCIAttrGet function
      ub4           *sizep;
      OraText      *banner;
      retval = OCIAttrGet(srvhp, OCI_HTYPE_SERVER, (dvoid *)&banner,(ub4 *)&sizep,OCI_ATTR_AUDIT_BANNER, errhp);
      
      if (retval != OCI_SUCCESS) {
        printf("FAILED: OCIAttrGet(), RC = %d\n", retval);
        return OCI_ERROR;
      }
      
      
      printf ("%s/n", banner);
      When i try this in code i get a failure
      FAILED: OCIAttrGet(), RC = -1 any ideas ?
      I want to retrieve the banner text SEC_USER_UNAUTHORIZED_ACCESS_BANNER which is specified in the sqlnet.ora

      And a little more error checking is telling me
      Error - ORA-24315: illegal attribute type

      FAILED: OCIAttrGet(), RC = 43

      Edited by: 899881 on Feb 27, 2012 8:41 PM
        • 1. Re: OCIAttrGet function
          Sudheendra-Oracle
          This works only for client/server which is beyond 11.1
          You will have to call OCIAttrGet on the server handle(srvhp in your code snippet) or the Session Handle for the attribute OCI_ATTR_ACCESS_BANNER.
          This works only if SEC_USER_UNAUTHORIZED_ACCESS_BANNER is set in sqlnet.ora to a file containing the banner text.
          • 2. Re: OCIAttrGet function
            902884
            Hi Sudheendra

            Yes i am on 11.2 and i am using 11.2 client to connect to database.
            The error seems to be in this call

            ub4             *sizep;
            OraText         *banner;
            
            retval = OCIAttrGet(srvhp, OCI_HTYPE_SERVER, banner,(ub4 *)&sizep,OCI_ATTR_AUDIT_BANNER, errhp);
            I have made a connection to the database but the error i get is
            Error - ORA-24315: illegal attribute type

            FAILED: OCIAttrGet(), RC = -1

            Any ideas

            regards
            • 3. Re: OCIAttrGet function
              Sudheendra-Oracle
              The attribute is OCI_ATTR_ACCESS_BANNER and not OCI_ATTR_AUDIT_BANNER.
              • 4. Re: OCIAttrGet function
                902884
                Hi Sudheendra

                Thanks now the call completes but surprisingly it doesnt print the banner
                ub4           *sizep;
                OraText      *banner;
                retval = OCIAttrGet(srvhp, OCI_HTYPE_SERVER, banner,(ub4 *)&sizep,OCI_ATTR_ACCESS_BANNER, errhp);
                if (retval != OCI_SUCCESS) {
                  checkerr(errhp, retval);
                  printf("FAILED: OCIAttrGet(), RC = %d\n", retval);
                  return OCI_ERROR;
                }
                
                 
                 
                printf ("%s/n", banner);
                Any idea what i am doing wrong
                • 5. Re: OCIAttrGet function
                  Sudheendra-Oracle
                  This works only if SEC_USER_UNAUTHORIZED_ACCESS_BANNER is set in sqlnet.ora to a file containing the banner text.
                  Is this set ?
                  • 6. Re: OCIAttrGet function
                    902884
                    Hi

                    Yes it is set.
                    This is from the oracle docs.
                    SEC_USER_AUDIT_ACTION_BANNER = file_path2
                    where file_path2 is the path of a text file.
                    To retrieve the banner, get the value of the attribute OCI_ATTR_AUDIT_BANNER from the session handle
                    after calls to either OCISessionBegin(), OCISessionGet(), OCILogon(), or OCILogon2().
                    ub4           *sizep;
                    OraText      *banner;
                    
                    
                    retval = OCIAttrGet(srvhp, OCI_HTYPE_SERVER, banner,(ub4 *)&sizep,OCI_ATTR_AUDIT_BANNER, errhp);
                    if (retval != OCI_SUCCESS) {
                      checkerr(errhp, retval);
                      printf("FAILED: OCIAttrGet(), RC = %d\n", retval);
                      return OCI_ERROR;
                    }
                    So the above code should also have worked as i am calling it after OCILogon2() .
                    But i get the error
                    Error - ORA-24315: illegal attribute type

                    FAILED: OCIAttrGet(), RC = -1


                    If i connect from sqlplus
                    SQL> conn scott/tiger@orcl
                    This property belongs to MyCompany

                    Connected.
                    • 7. Re: OCIAttrGet function
                      Sudheendra-Oracle
                      banner variable in your program is just a pointer.
                      Since the content being returned is a string (array of characters) you need to pass address of the pointer (&banner)
                      • 8. Re: OCIAttrGet function
                        902884
                        Hi
                        ub4             sizep;
                        OraText         *accessbanner;
                        
                        retval = OCIAttrGet(srvhp, OCI_HTYPE_SERVER, (dvoid *)&accessbanner,(ub4 *)&sizep,OCI_ATTR_ACCESS_BANNER, errhp);
                        
                        if (retval != OCI_SUCCESS) {
                          checkerr(errhp, retval);
                          printf("FAILED Access Banner: OCIAttrGet(), RC = %d\n", retval);
                          return OCI_ERROR;
                        }
                        
                        printf("Access Banner %s \n",accessbanner);
                        I get this output
                        Access Banner (null)
                        • 9. Re: OCIAttrGet function
                          902884
                          Hi

                          I had to restart the database after which this worked.

                          regards
                          • 10. Re: OCIAttrGet function
                            Sudheendra-Oracle
                            Is the Oracle server using the correct sqlnet.ora or Is this parameter set in sqlnet.ora after the instance has been started.
                            sqlnet.ora is not read immediately if the file is modified. You will have to bounce the db to have the changes take effect.
                            • 11. Re: OCIAttrGet function
                              Sudheendra-Oracle
                              I did not notice that you got it worked and posted my previous response.
                              Good that it worked for you.