[pubcookie-dev] CVS update: willey;pbc_config.h,1.99,1.100

Stephen Willey willey at cac.washington.edu
Wed Oct 6 14:26:42 PDT 2004


Update of /usr/local/cvsroot/webiso/pubcookie/src
 In directory webiso-cvs.cac.washington.edu:/var/tmp/cvs-serv26031
 
 Modified Files:
 	flavor_basic.c ntmpl.c pbc_config.h 
 Log Message:
 add custom login messages
 



Index: webiso/pubcookie/src/flavor_basic.c
diff -c webiso/pubcookie/src/flavor_basic.c:1.64 webiso/pubcookie/src/flavor_basic.c:1.65
*** webiso/pubcookie/src/flavor_basic.c:1.64	Wed Sep  1 14:13:36 2004
--- webiso/pubcookie/src/flavor_basic.c	Wed Oct  6 14:26:39 2004
***************
*** 13,19 ****
   *   will pass l->realm to the verifier and append it to the username when
   *   'append_realm' is set
   *
!  * $Id: flavor_basic.c,v 1.64 2004/09/01 21:13:36 fox Exp $
   */
  
  
--- 13,19 ----
   *   will pass l->realm to the verifier and append it to the username when
   *   'append_realm' is set
   *
!  * $Id: flavor_basic.c,v 1.65 2004/10/06 21:26:39 willey Exp $
   */
  
  
***************
*** 208,253 ****
  
  }
  
! static int print_login_page(pool *p, login_rec *l, login_rec *c, int reason)
  {
!     /* currently, we never clear the login cookie
!        we always clear the greq cookie */
!     int need_clear_login = 0;
!     int need_clear_greq = 1;
!     const char * reasonpage = NULL;
  
!     char *hidden_fields = NULL;
!     int hidden_len = 0;
!     int hidden_needed_len = INIT_HIDDEN_SIZE;
!     char *getcred_hidden = NULL;
  
!     char *reason_html = NULL;
!     char *user_field = NULL;
!     char *hidden_user = NULL;
!     char now[64];
!     int ldur, ldurp;
!     char ldurtxt[64], *ldurtyp;
      char *tag = NULL;
      char *subst = NULL;
!     char func[] = "print_login_page";
      int ret = PBC_FAIL;
!     
      pbc_log_activity(p, PBC_LOG_DEBUG_VERBOSE, "%s: hello reason: %d", 						func, reason);
  
      /* set the cookies */
-     if (need_clear_login) {
-         print_header(p, "Set-Cookie: %s=%s; domain=%s; path=%s; expires=%s; secure\n",
-                      PBC_L_COOKIENAME, 
-                      PBC_CLEAR_COOKIE,
-                      PBC_LOGIN_HOST,
-                      LOGIN_DIR, 
-                      EARLIEST_EVER);
-     }
- 
-     if (need_clear_greq) {
-         add_app_cookie(PBC_G_REQ_COOKIENAME, PBC_CLEAR_COOKIE, NULL);
-     }
- 
      switch (reason) {
          case FLB_BAD_AUTH:
              /* username will be static and prefilled use a different bad
--- 208,279 ----
  
  }
  
! 
! /**
!  * get_custom_login_msg get custom login message if there is such
!  * @param p apache memory pool
!  * @param appid application id
!  * @param appsrvid application server id
!  * @param mout output string
!  * @return PBC_OK if ok or PBC_FAIL if a problem
!  */
! int get_custom_login_msg(pool *p, const char *appid, const char *appsrvid, 
! 		char **mout)
  {
!     char        *new, *ptr, *filename;
!     const char  *s;
!     int         len;
!     const char *template_dir = libpbc_config_getstring(p,
! 	"custom_login_message_dir", TMPL_FNAME);
!     const char *cust_login_prefix = libpbc_config_getstring(p,
! 	"custom_login_file_prefix", CUSTOM_LOGIN_MSG);
!     const char func[] = "get_custom_login_msg";
! 
!     pbc_log_activity(p, PBC_LOG_DEBUG_VERBOSE, 
! 		"%s: hello appid: %s appsrvid: %s", func, appid, appsrvid); 
! 
!     len = strlen(appid) + strlen(appsrvid) + strlen(cust_login_prefix) + 3;
!     filename=calloc(len, sizeof(char));
!     snprintf(filename, len, "%s%c%s%c%s", cust_login_prefix, 
! 		APP_LOGOUT_STR_SEP, (appsrvid == NULL ? "" : appsrvid), 
! 		APP_LOGOUT_STR_SEP, (appid == NULL ? "" : appid));
! 
!     /* clean non compliant chars from string */
!     ptr = new = filename;
!     while(*ptr) {
!         if (isalnum((int) *ptr) || *ptr == '-' || *ptr == '_' || *ptr == '.') {
!             *new++ = *ptr;
!         }
!         ptr++;
!     }
!     *new = '\0';
  
!     if ( ntmpl_tmpl_exist(p, template_dir, filename) )
!        *mout = ntmpl_sub_template(p, template_dir, filename, NULL);
  
! 
!     if ( filename != NULL )
!         free(filename);
! 
!     pbc_log_activity(p, PBC_LOG_DEBUG_VERBOSE, "%s: bye message mout: %s ", 
! 		func, *mout); 
! 
!     return(PBC_OK);
! 
! }
! 
! int get_reason_html(pool *p, int reason, login_rec *l, login_rec *c, 
! 	char **out)
! {
      char *tag = NULL;
      char *subst = NULL;
!     const char * reasonpage = NULL;
      int ret = PBC_FAIL;
!     char func[] = "get_reason_html";
! 
      pbc_log_activity(p, PBC_LOG_DEBUG_VERBOSE, "%s: hello reason: %d", 						func, reason);
  
      /* set the cookies */
      switch (reason) {
          case FLB_BAD_AUTH:
              /* username will be static and prefilled use a different bad
***************
*** 297,314 ****
      }
      
      /* Get the HTML for the error reason */
!     
!     reason_html = ntmpl_sub_template(p, TMPL_FNAME, reasonpage, tag, subst, NULL);
!     if ( reason_html == NULL ) {
          ret = PBC_FAIL;
!         goto done;
!     }
  
      if(tag != NULL)
         pbc_free(p, tag);
      if(subst != NULL)
         pbc_free(p, subst);
  
      while (hidden_needed_len > hidden_len) {
  
          /* Just in case there's a bad implementation of realloc() .. */
--- 323,400 ----
      }
      
      /* Get the HTML for the error reason */
!     *out = ntmpl_sub_template(p, TMPL_FNAME, reasonpage, tag, subst, NULL);
!     if ( *out == NULL )
          ret = PBC_FAIL;
!     else
!         ret = PBC_OK;
  
      if(tag != NULL)
         pbc_free(p, tag);
      if(subst != NULL)
         pbc_free(p, subst);
  
+     pbc_log_activity(p, PBC_LOG_DEBUG_VERBOSE, "%s: bye return: %d", 
+ 		func, reason); 
+ 
+     return(ret);
+ 
+ }
+ 
+ static int print_login_page(pool *p, login_rec *l, login_rec *c, int reason)
+ {
+     /* currently, we never clear the login cookie
+        we always clear the greq cookie */
+     int need_clear_login = 0;
+     int need_clear_greq = 1;
+ 
+     char *hidden_fields = NULL;
+     int hidden_len = 0;
+     int hidden_needed_len = INIT_HIDDEN_SIZE;
+     char *getcred_hidden = NULL;
+ 
+     char *user_field = NULL;
+     char *hidden_user = NULL;
+     char now[64];
+     int ldur, ldurp;
+     char ldurtxt[64], *ldurtyp;
+     char func[] = "print_login_page";
+     int ret = PBC_FAIL;
+     char *login_msg = NULL;
+     
+     pbc_log_activity(p, PBC_LOG_DEBUG_VERBOSE, "%s: hello reason: %d", 						func, reason);
+ 
+     /* set the cookies */
+     if (need_clear_login) {
+         print_header(p, "Set-Cookie: %s=%s; domain=%s; path=%s; expires=%s; secure\n",
+                      PBC_L_COOKIENAME, 
+                      PBC_CLEAR_COOKIE,
+                      PBC_LOGIN_HOST,
+                      LOGIN_DIR, 
+                      EARLIEST_EVER);
+     }
+ 
+     if (need_clear_greq) {
+         add_app_cookie(PBC_G_REQ_COOKIENAME, PBC_CLEAR_COOKIE, NULL);
+     }
+ 
+     /* if there is a custom login message AND the reason for logging-in is:
+            reauth, wrong creds (flavours), expired login cookie, or
+            login cookie error.  The later case is the catch-all and included
+ 	   inital visits when the user doesn't hav a login cookie 
+        else
+            use the traditional reason text    
+      */
+     if (reason == FLB_REAUTH || reason == FLB_CACHE_CREDS_WRONG || 
+                 reason == FLB_LCOOKIE_EXPIRED || reason == FLB_LCOOKIE_ERROR)
+         if( (ret = get_custom_login_msg(p, l->appid, 
+ 		l->appsrvid, &login_msg)) == PBC_FAIL )
+             goto done;
+ 
+     if ( login_msg == NULL )
+         if( (ret = get_reason_html(p, reason, l, c, &login_msg)) == PBC_FAIL )
+             goto done;
+ 
      while (hidden_needed_len > hidden_len) {
  
          /* Just in case there's a bad implementation of realloc() .. */
***************
*** 429,435 ****
      ntmpl_print_html(p, TMPL_FNAME,
                       libpbc_config_getstring(p, "tmpl_login", "login"),
                      "loginuri", PBC_LOGIN_URI,
!                     "message", reason_html != NULL ? reason_html : "",
                      "curtime", now, 
                      "hiddenuser", hidden_user != NULL ? hidden_user : "",
                      "hiddenfields", hidden_fields,
--- 515,521 ----
      ntmpl_print_html(p, TMPL_FNAME,
                       libpbc_config_getstring(p, "tmpl_login", "login"),
                      "loginuri", PBC_LOGIN_URI,
!                     "message", login_msg != NULL ? login_msg : "",
                      "curtime", now, 
                      "hiddenuser", hidden_user != NULL ? hidden_user : "",
                      "hiddenfields", hidden_fields,
***************
*** 451,458 ****
      if (user_field != NULL)
          free( user_field );
  
!     if (reason_html != NULL)
!         free( reason_html );
  
      if (hidden_user != NULL)
          free( hidden_user );
--- 537,544 ----
      if (user_field != NULL)
          free( user_field );
  
!     if (login_msg != NULL)
!         free( login_msg );
  
      if (hidden_user != NULL)
          free( hidden_user );


Index: webiso/pubcookie/src/ntmpl.c
diff -c webiso/pubcookie/src/ntmpl.c:1.16 webiso/pubcookie/src/ntmpl.c:1.17
*** webiso/pubcookie/src/ntmpl.c:1.16	Thu Aug 19 12:21:32 2004
--- webiso/pubcookie/src/ntmpl.c	Wed Oct  6 14:26:39 2004
***************
*** 6,12 ****
  /** @file ntmpl.c
   * Template library
   *
!  * $Id: ntmpl.c,v 1.16 2004/08/19 19:21:32 willey Exp $
   */
  
  #ifdef WITH_FCGI
--- 6,12 ----
  /** @file ntmpl.c
   * Template library
   *
!  * $Id: ntmpl.c,v 1.17 2004/10/06 21:26:39 willey Exp $
   */
  
  #ifdef WITH_FCGI
***************
*** 48,53 ****
--- 48,57 ----
  # include <stdlib.h>
  #endif
  
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <unistd.h>
+ 
  #include "pbc_logging.h"
  #include "pbc_config.h"
  #include "pubcookie.h"
***************
*** 229,234 ****
--- 233,276 ----
      pbc_free(p, template);
  
      pbc_log_activity(p, PBC_LOG_DEBUG_VERBOSE, "%s: goodbye", func);
+ 
+ }
+ 
+ /* returns PBC_OK if template exists, PBC_FAIL if template doesn't exist      */
+ int ntmpl_tmpl_exist(pool *p, const char *fpath, const char *fname)
+ {
+     struct stat *buf;
+     int len, ret;
+     char *templatefile = NULL;
+ 
+     /* +2 for the "/" between and the trailing null */
+     len = strlen(fpath) + strlen(fname) + 2;
+     templatefile = (char *) malloc(len * sizeof(char));
+     if (templatefile == NULL) {
+        pbc_log_activity(p, PBC_LOG_ERROR,
+            "unable to malloc %d bytes for template filename %s", len, fname);
+        return(PBC_FAIL);
+     }
+     if ( snprintf(templatefile, len, "%s%s%s", fpath,
+                   fpath[strlen(fpath) - 1 ] == '/' ? "" : "/", fname) > len)  {
+        pbc_log_activity(p, PBC_LOG_ERROR,
+                        "template filename overflow");
+        return(PBC_FAIL);
+     }
+ 
+     pbc_log_activity(p, PBC_LOG_DEBUG_VERBOSE, 
+ 		"ntmpl_tmpl_exist: looking for: %s", templatefile);
+ 
+     buf = malloc(sizeof(struct stat));
+     if( stat(templatefile, buf) )
+         ret = PBC_FAIL;
+     else
+         ret = PBC_OK;
+ 
+     if( buf != NULL )
+         free(buf);
+ 
+     return(ret);
  
  }
  


Index: webiso/pubcookie/src/pbc_config.h
diff -c webiso/pubcookie/src/pbc_config.h:1.99 webiso/pubcookie/src/pbc_config.h:1.100
*** webiso/pubcookie/src/pbc_config.h:1.99	Thu Jul 29 11:56:41 2004
--- webiso/pubcookie/src/pbc_config.h	Wed Oct  6 14:26:39 2004
***************
*** 4,10 ****
   */
  
  /*
!      $Id: pbc_config.h,v 1.99 2004/07/29 18:56:41 dors Exp $
   */
  
  #ifndef PUBCOOKIE_CONFIG
--- 4,10 ----
   */
  
  /*
!      $Id: pbc_config.h,v 1.100 2004/10/06 21:26:39 willey Exp $
   */
  
  #ifndef PUBCOOKIE_CONFIG
***************
*** 37,42 ****
--- 37,43 ----
  #define PBC_ENTRPRS_DOMAIN (libpbc_config_getstring(p,"enterprise_domain", ".washington.edu"))
  #define PBC_TEMPLATES_PATH libpbc_config_getstring(p, "relay_template_path", "")
  #define PBC_RELAY_URI libpbc_config_getstring(p, "relay_uri", "https://relay.example.url/relay/index.cgi")
+ #define CUSTOM_LOGIN_MSG "custom_login_msg"
  
  #if defined (WIN32)
  	#define PBC_PUBLIC_NAME (libpbc_config_getstring(p, "PUBLIC_dir_name", "PUBLIC")) 



end of message


More information about the pubcookie-dev mailing list