#
# <20230902.1640.27>
#
# This code is called by the passwordLocker when it is asked to deal with 'cifs'
# entries (i.e. user/password entries for windows accessing shares on other systems).
#
# Cifs user/password info pertains only the the system, i.e.
# all cifs entries for a given system must (by windows convention) use the same
# user/password (in fact after the first share is opened, windows defaults the
# user/password to the one used to get the first share.  At the same time a
# given windows system may have more than one user so we allow more than one.

# This code is an extension of the 'passwordLocker' function to handle special
# cases around shares. Below are individual bits that get called by the
# 'passwordLocker' code. We indicate when such calls are made below.

# All this code is in the 'pwLocker' name space and so can be called directly
# and we have access to variables in that name space...

namespace eval pwLocker {

  # this routine is called when ever the 'cifs:' is found, either on inital
  # window build or when detected by the 'trace' of '(fullid)'

    variable cifsPw "\nFor \"cifs\" shares the \"Drive\"  and \"Flag\" controls how the\
	     \nshare is connected \"Drive\" must be 'letter:' or '*:' or not given\
             \nWhere 'letter:' maps the share to that drive letter,\
             \nno drive letter sets the share up as a 'UNC' (//SYSTEM/SHARE).\
             \n\"Display Names\" may be generated for connected shares.\
             \nA flag to control the connection and Display Name has the following meaning.
	     \nNo    do not generate a Display Name.\
	     \nOnly  generate a Display Name (It will appear in the \"volume\" list).\
	     \nHot   generate a Display Name and put the display name in the HotList.\
	     \nDon't do not ever set up this share."
   proc checkForCifs {buttonNum } {
     variable {}
     variable cifsPw
     set isCifs [string match "cifs://*" $(fullid)]
    
    if {![info exists (-cifs-)] || $(-cifs-) != $(-uni-)} {
      set (-cifs-) $(-uni-)
      # First call populate the 'drive' and 'flag' lines and add the
      # info to the text window. Keep track of this so we can remove it
      # if needed.
      if {$isCifs} {
	# if 'display' was not coded, use default
	if {$(-display-) == {}} {
	  set (-display-) [list Drive {} Flags {}]
	}
	# Add cifs flag info to the text area
	
	foreach {val op} $(-display-) {
	  set (${val}) $op
	  .password_entry_dialog$(-uni-).[incr buttonNum] config\
	      -textvariable [namespace current]::(${val})
	  .password_entry_dialog$(-uni-).label$buttonNum config -text "$val:"
	}
      }      
    }
    if {$isCifs} {
      catch {.password_entry_dialog$(-uni-).text insert insert $cifsPw mytag}
    } else {
      catch {.password_entry_dialog$(-uni-).text delete mytag.first mytag.last}
    }
    .password_entry_dialog$(-uni-).text see end
    add2L $(-cifsOps-) $isCifs      
  }

  
}
