Changeset 16564


Ignore:
Timestamp:
Aug 23, 2016, 6:01:49 PM (3 years ago)
Author:
dcorreia
Message:

Added data filter based on admin permissions.
Added support for enable/disable configurations.
Changed remove login feature to enable/disable or delete.

Location:
internals/2016/linuxloginsmartcardwizard/trunk/proto1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • internals/2016/linuxloginsmartcardwizard/trunk/proto1/config.py

    r16563 r16564  
    11#!/usr/bin/python3
    2 import os
     2import os, grp
    33import cardHelper, fileHelper
    44
     
    315315
    316316
     317def hasAdminPermissions(currentUser):
     318    return currentUser in grp.getgrnam("adm").gr_mem
     319
     320
     321def filterAdminUsers(userList):
     322    currentUser = os.getlogin()
     323    if not hasAdminPermissions(currentUser):
     324        userList = [user for user in userList if user == currentUser]
     325    return userList
     326
     327
    317328def listLocalUsers():
    318329    """
     
    324335    awkCmd = "awk -F':' -v '" + minUID + "' -v '" + maxUID + "' '{ if ( $3 >= min && $3 <= max) print $1 }' /etc/passwd"
    325336    fileHelper.executeCommand(awkCmd, open(TEMP_LOCALUSERS, mode="w"))
    326     return [s.strip() for s in fileHelper.readFileToList(TEMP_LOCALUSERS)]
     337    localUsers = [s.strip() for s in fileHelper.readFileToList(TEMP_LOCALUSERS)]
     338    return filterAdminUsers(localUsers)
     339
     340
     341def filterAdminCombos(combosList):
     342    currentUser = os.getlogin()
     343    if not hasAdminPermissions(currentUser):
     344        combosList = [combo for combo in combosList if currentUser in combo]
     345    return combosList
    327346
    328347
     
    333352        for combo in combosList:
    334353            localCombos.append(getComboInfo(combo))
    335         return localCombos
     354        return filterAdminCombos(localCombos)
     355    except FileNotFoundError as error:
     356        fileHelper.printDebugInfo(error)
     357    except TypeError as error:
     358        fileHelper.printDebugInfo(error)
     359        return None
     360
     361
     362def listDisabledCombos():
     363    try:
     364        combosList = [line for line in fileHelper.readFileToList(PAMPKCS11_MAPPING) if "#x" in line]
     365        disabledCombos = []
     366        for combo in combosList:
     367            disabledCombos.append(getComboInfo(combo))
     368        return filterAdminCombos(disabledCombos)
    336369    except FileNotFoundError as error:
    337370        fileHelper.printDebugInfo(error)
     
    358391
    359392
     393def disableLocalCombo(cardNumber, username):
     394    mappingsData = fileHelper.readFileToList(PAMPKCS11_MAPPING)
     395    for index in range(0, len(mappingsData)):
     396        if cardNumber in mappingsData[index] and username in mappingsData[index]:
     397            mappingsData[index] = "#x" + mappingsData[index]
     398            fileHelper.writeListToFile(PAMPKCS11_MAPPING, mappingsData)
     399            return True
     400    return False
     401
     402
     403def disableSelectedCombos(indexList):
     404    combos = listLocalCombos()
     405    for index in indexList:
     406        number, username = combos[index][0], combos[index][2]
     407        disableLocalCombo(number, username)
     408
     409
     410def enableLocalCombo(cardNumber, username):
     411    mappingsData = fileHelper.readFileToList(PAMPKCS11_MAPPING)
     412    for index in range(0, len(mappingsData)):
     413        if cardNumber in mappingsData[index] and username in mappingsData[index]:
     414            mappingsData[index] = mappingsData[index][2:]
     415            fileHelper.writeListToFile(PAMPKCS11_MAPPING, mappingsData)
     416            return True
     417    return False
     418
     419
     420def enableSelectedLocalCombos(indexList):
     421    combos = listDisabledCombos()
     422    for index in indexList:
     423        number, username = combos[index][0], combos[index][2]
     424        enableLocalCombo(number, username)
     425
     426
    360427def getCardAttribute(attribute, cardData):
    361428    index = getIndexOfToken(attribute, cardData)
  • internals/2016/linuxloginsmartcardwizard/trunk/proto1/mainwin.py

    r16563 r16564  
    8787        self.listConfigButton.setText("    List Login Configurations")
    8888        self.resetConfigButton.setText("    Remove Login Configurations")
     89        if config.isPkcs11LoginActive():
     90            self.statusbarLabel.setText("Smartcard Login Enabled")
     91        else:
     92            self.statusbarLabel.setText("Smartcard Login Disabled")
    8993
    9094        self.addUserButton.clicked.connect(self.openAddUserWizard)
     
    155159
    156160    def checkLoginStatus(self):
    157         if config.isPkcs11Installed():
     161        if config.isPkcs11Installed() and config.hasAdminPermissions(os.getlogin()):
    158162            self.statusbarSlider.show()
    159163            if config.isPkcs11LoginActive():
     
    201205        self.centerOnScreen()
    202206
    203         self.firstRow = QtWidgets.QLabel(self)
    204         self.firstRow.setStyleSheet("font: bold;")
    205         self.firstRow.setGeometry(QtCore.QRect(40, 30, 400, 30))
    206         self.comboslist = QtWidgets.QListWidget(self)
    207         self.comboslist.setGeometry(QtCore.QRect(40, 60, 400, 250))
     207        self.messageBox = QtWidgets.QMessageBox(self)
     208
     209        self.tabwidget = QtWidgets.QTabWidget(self)
     210        self.tabwidget.setGeometry(QtCore.QRect(40, 30, 400, 290))
     211
     212        #self.firstRow = QtWidgets.QLabel(self)
     213        #self.firstRow.setStyleSheet("font: bold;")
     214        #self.firstRow.setGeometry(QtCore.QRect(40, 30, 400, 30))
     215        # self.firstRow.setText("\n      BI Number".ljust(25)+"     Full Name".ljust(25)+"  Username".ljust(25) + "\n")
     216
     217        self.enabledCombosList = QtWidgets.QListWidget(self)
    208218        self.buildLocalCombos()
     219        self.tabwidget.insertTab(0, self.enabledCombosList, "Enabled Logins")
     220
     221        self.disabledCombosList = QtWidgets.QListWidget(self)
     222        self.buildDisabledCombos()
     223        self.tabwidget.insertTab(1, self.disabledCombosList, "Disabled Logins")
    209224
    210225        self.selectAllButton = QtWidgets.QPushButton(self)
    211         self.selectAllButton.setGeometry(QtCore.QRect(210, 330, 100, 30))
     226        self.selectAllButton.setGeometry(QtCore.QRect(40, 330, 100, 30))
     227
     228        self.disableSelectionButton = QtWidgets.QPushButton(self)
     229        self.disableSelectionButton.setGeometry(QtCore.QRect(250, 330, 90, 30))
    212230
    213231        self.removeSelectionButton = QtWidgets.QPushButton(self)
    214         self.removeSelectionButton.setGeometry(QtCore.QRect(320, 330, 120, 30))
     232        self.removeSelectionButton.setGeometry(QtCore.QRect(350, 330, 90, 30))
    215233
    216234        self.setWindowTitle("Remove Login Configurations")
    217         self.firstRow.setText("\n      BI Number".ljust(25)+"     Full Name".ljust(25)+"  Username".ljust(25) + "\n")
    218235        self.selectAllButton.setText("Select All")
    219         self.removeSelectionButton.setText("Remove Selection")
     236        self.disableSelectionButton.setText("Disable")
     237        self.removeSelectionButton.setText("Delete")
    220238
    221239        self.selectAllButton.clicked.connect(self.selectAllEvent)
    222240        self.removeSelectionButton.clicked.connect(self.removeSelectionEvent)
    223 
    224         self.messageBox = QtWidgets.QMessageBox(self)
    225         self.selectedAll = False
     241        self.tabwidget.currentChanged.connect(self.updateTabList)
     242        self.enabledCombosList.itemChanged.connect(self.updateTabList)
     243        self.disabledCombosList.itemChanged.connect(self.updateTabList)
    226244
    227245    def centerOnScreen(self):
     
    231249
    232250    def buildLocalCombos(self):
    233         self.comboslist.clear()
     251        self.enabledCombosList.clear()
    234252        localCombos = config.listLocalCombos()
    235253        for combo in localCombos:
     
    238256            item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
    239257            item.setData(QtCore.Qt.CheckStateRole, QtCore.QVariant(QtCore.Qt.Unchecked))
    240             self.comboslist.addItem(item)
     258            self.enabledCombosList.addItem(item)
     259
     260    def buildDisabledCombos(self):
     261        self.disabledCombosList.clear()
     262        disabledCombos = config.listDisabledCombos()
     263        for combo in disabledCombos:
     264            number, name, user = combo[0], combo[1], combo[2]
     265            item = QtWidgets.QListWidgetItem("\n" + number.ljust(25) + name.ljust(25) + user.ljust(25) + "\n")
     266            item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
     267            item.setData(QtCore.Qt.CheckStateRole, QtCore.QVariant(QtCore.Qt.Unchecked))
     268            self.disabledCombosList.addItem(item)
     269
     270    def updateTabList(self):
     271        if self.hasAllItemsChecked():
     272            self.selectAllButton.setText("Unselect All")
     273        else:
     274            self.selectAllButton.setText("Select All")
     275
     276    def hasAllItemsChecked(self):
     277        if self.tabwidget.currentIndex() == 0:
     278            for i in range(self.enabledCombosList.count()):
     279                item = self.enabledCombosList.item(i)
     280                if item.checkState() == QtCore.Qt.Unchecked:
     281                    return False
     282            return True
     283        else:
     284            for i in range(self.disabledCombosList.count()):
     285                item = self.disabledCombosList.item(i)
     286                if item.checkState() == QtCore.Qt.Unchecked:
     287                    return False
     288            return True
    241289
    242290    def selectAllEvent(self):
    243         if self.selectedAll:
     291        if self.hasAllItemsChecked():
    244292            self.unselectAllCombos()
    245293            self.selectAllButton.setText("Select All")
    246             self.selectedAll = False
    247294        else:
    248295            self.selectAllCombos()
    249296            self.selectAllButton.setText("Unselect All")
    250             self.selectedAll = True
    251297
    252298    def selectAllCombos(self):
    253         for i in range(self.comboslist.count()):
    254             item = self.comboslist.item(i)
    255             item.setCheckState(QtCore.Qt.Checked)
     299        if self.tabwidget.currentIndex() == 0:
     300            for i in range(self.enabledCombosList.count()):
     301                item = self.enabledCombosList.item(i)
     302                item.setCheckState(QtCore.Qt.Checked)
     303        else:
     304            for i in range(self.disabledCombosList.count()):
     305                item = self.disabledCombosList.item(i)
     306                item.setCheckState(QtCore.Qt.Checked)
    256307
    257308    def unselectAllCombos(self):
    258         for i in range(self.comboslist.count()):
    259             item = self.comboslist.item(i)
    260             item.setCheckState(QtCore.Qt.Unchecked)
     309        if self.tabwidget.currentIndex() == 0:
     310            for i in range(self.enabledCombosList.count()):
     311                item = self.enabledCombosList.item(i)
     312                item.setCheckState(QtCore.Qt.Unchecked)
     313        else:
     314            for i in range(self.disabledCombosList.count()):
     315                item = self.disabledCombosList.item(i)
     316                item.setCheckState(QtCore.Qt.Unchecked)
    261317
    262318    def removeSelectionEvent(self):
    263319        ret = []
    264320        message = "\n     BI Number".ljust(25) + "      Full Name".ljust(25) + "       Username".ljust(25) + "\n"
    265         for i in range(self.comboslist.count()):
    266             item = self.comboslist.item(i)
     321        for i in range(self.enabledCombosList.count()):
     322            item = self.enabledCombosList.item(i)
    267323            if item.checkState() == QtCore.Qt.Checked:
    268324                message += "     " + item.text().strip() + "\n"
Note: See TracChangeset for help on using the changeset viewer.