-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CA-329845 - Remove usage of credentials file for CIF
Signed-off-by: ben sims <ben.sims@citrix.com>
- Loading branch information
1 parent
3b0c035
commit 618db56
Showing
11 changed files
with
511 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/python | ||
# | ||
# Copyright (C) Citrix Systems Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation; version 2.1 only. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
# | ||
# ISOSR: remote iso storage repository | ||
|
||
import util | ||
import xs_errors | ||
|
||
|
||
class CIFSException(Exception): | ||
def __init__(self, errstr): | ||
self.errstr = errstr | ||
|
||
def getDconfPasswordKey(smbsr=False): | ||
key_password = 'cifspassword' | ||
key_secret = 'cifspassword_secret' | ||
|
||
if smbsr: | ||
key_password = 'password' | ||
key_secret = 'password_secret' | ||
return key_password, key_secret | ||
|
||
def containsPassword(dconf, smbsr=False): | ||
key_password, key_secret = getDconfPasswordKey(smbsr) | ||
return ((key_password in dconf) or (key_secret in dconf)) | ||
|
||
|
||
def containsCredentials(dconf, smbsr=False): | ||
return ((('username' in dconf)) and (containsPassword(dconf, smbsr))) | ||
|
||
|
||
def splitDomainAndUsername(uname): | ||
|
||
username = None | ||
domain = None | ||
dom_username = uname.split('\\') | ||
|
||
if len(dom_username) == 1: | ||
domain = None | ||
username = dom_username[0] | ||
elif len(dom_username) == 2: | ||
domain = dom_username[0] | ||
username = dom_username[1] | ||
else: | ||
raise CIFSException("A maximum of 2 tokens are expected " | ||
"(<domain>\<username>). {} were given." | ||
.format(len(dom_username))) | ||
return username, domain | ||
|
||
|
||
def getCIFCredentials(dconf, session, smbsr=False): | ||
credentials = {} | ||
domain = None | ||
if (containsCredentials(dconf, smbsr)): | ||
|
||
username, domain = splitDomainAndUsername(dconf['username']) | ||
|
||
credentials["USER"] = util.to_plain_string(username) | ||
|
||
key_password, key_secret = getDconfPasswordKey(smbsr) | ||
if key_secret in dconf: | ||
password = util.get_secret(session, dconf[key_secret]) | ||
else: | ||
password = dconf[key_password] | ||
|
||
credentials["PASSWD"] = util.to_plain_string(password) | ||
|
||
domain = util.to_plain_string(domain) | ||
|
||
return credentials, domain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.