QStringList UserManagerBackend::getAllGroups(int minId, int maxId) { if (groupList.empty()) { refreshGroups(); } QStringList result; QMap<int, Group>::Iterator it; qDebug() << "Generating new group list for UI..."; for ( it = groupList.begin(); it != groupList.end(); ++it ) { if ((! it->getDeleted()) && (((it->getGid() >= minId) || (minId == -1) ) && ((it->getGid() <= maxId) || (maxId == -1 )))) { result.append(it->getGroupname()); } } qDebug() << "Done Generating new group list for UI..."; return result; }
void MConfig::refresh() { int i = tabWidget->currentIndex(); switch (i) { case 1: refreshRestore(); buttonApply->setEnabled(false); buttonOk->setEnabled(true); break; case 2: refreshDesktop(); buttonApply->setEnabled(true); buttonOk->setEnabled(false); break; case 3: refreshGroups(); buttonApply->setEnabled(false); buttonOk->setEnabled(true); break; case 4: refreshMembership(); buttonApply->setEnabled(false); buttonOk->setEnabled(true); break; default: refreshAdd(); refreshDelete(); buttonApply->setEnabled(false); buttonOk->setEnabled(true); break; } }
bool UserManagerBackend::commit() { //Process users QMap<QString, User>::Iterator userIt; QStringList args; for ( userIt = userList.begin(); userIt != userList.end(); ++userIt ) { args.clear(); switch(userIt->getStatus()) { case 1: //Modify User qDebug() << "Modifying user " << userIt->getUsername(); if ( ! chroot.isEmpty() ) args << chroot << "pw"; args << "usermod"; args << userIt->getUsername(); // Only change home-dir on non-encrypted users if ( ! userIt->getEnc() ) { args << "-d"; args << userIt->getHome(); } args << "-s"; args << userIt->getShell(); args << "-c"; args << userIt->getFullname(); if ( ! chroot.isEmpty() ) QProcess::execute("chroot", args); else QProcess::execute("pw", args); if (userIt->getPassword() != "") { // Refuse to continue if we are trying to change PW // On an encrypted users homedir if ( userIt->getEnc() ) { qDebug() << "Cannot change encrypted password: "******"Changing password: "******"/tmp/.XXXXXXXX"); if ( rfile.open() ) { QTextStream stream( &rfile ); stream << userIt->getClearPassword(); rfile.close(); } if ( ! chroot.isEmpty() ) system("cat " + rfile.fileName().toLatin1() + " | chroot " + chroot.toLatin1() + " pw usermod " + userIt->getUsername().toLatin1() + " -h 0 "); else system("cat " + rfile.fileName().toLatin1() + " | pw usermod " + userIt->getUsername().toLatin1() + " -h 0 "); rfile.remove(); } break; case 2: { //Add User qDebug() << "Adding user " << userIt->getUsername(); // Create the new home-directory if ( chroot.isEmpty() ) { system("/usr/local/share/pcbsd/scripts/mkzfsdir.sh " + userIt->getHome().toLatin1() ); system("pw groupadd " + userIt->getUsername().toLatin1() ); } else { system("mkdir -p " + chroot.toLatin1() + "/" + userIt->getHome().toLatin1() + " 2>/dev/null" ); system("chroot " + chroot.toLatin1() + " ln -s /usr/home /home 2>/dev/null" ); system("chroot " + chroot.toLatin1() + " pw groupadd " + userIt->getUsername().toLatin1() ); } if ( ! chroot.isEmpty() ) args << chroot << "pw"; args << "useradd"; args << userIt->getUsername(); args << "-c"; args << userIt->getFullname(); args << "-m"; args << "-d"; args << userIt->getHome(); args << "-s"; args << userIt->getShell(); if (userIt->getGid() != -1) { args << "-g"; args << QString::number(userIt->getGid()); } else { args << "-g"; args << userIt->getUsername(); } args << "-G"; args << "operator"; if ( ! chroot.isEmpty() ) QProcess::execute("chroot", args); else QProcess::execute("pw", args); QTemporaryFile nfile("/tmp/.XXXXXXXX"); if ( nfile.open() ) { QTextStream stream( &nfile ); stream << userIt->getClearPassword(); nfile.close(); } if ( ! chroot.isEmpty() ) system("cat " + nfile.fileName().toLatin1() + " | chroot " + chroot.toLatin1() + " pw usermod " + userIt->getUsername().toLatin1() + " -h 0 "); else system("cat " + nfile.fileName().toLatin1() + " | pw usermod " + userIt->getUsername().toLatin1() + " -h 0 "); nfile.remove(); if ( chroot.isEmpty() ) { qDebug() << "Enabling Flash Plugin for " << userIt->getUsername(); QString flashCmd = "su " + userIt->getUsername() + " -c \"flashpluginctl on\""; system(flashCmd.toLatin1()); } // Set permissions if ( chroot.isEmpty() ) system("chown -R " + userIt->getUsername().toLatin1() +":" + userIt->getUsername().toLatin1() + " " + userIt->getHome().toLatin1() ); else system("chroot " + chroot.toLatin1() + " chown -R " + userIt->getUsername().toLatin1() +":" + userIt->getUsername().toLatin1() + " " + userIt->getHome().toLatin1() ); // Are we enabling encryption? if ( userIt->getEnc() ) { QProcess::execute("enable_user_pefs", QStringList() << userIt->getUsername() << userIt->getClearPassword() ); } break; } case 3: //Delete User qDebug() << "Deleting user " << userIt->getUsername(); if(userIt->getEnc()) { // Unmount PEFS system("umount " + userIt->getHome().toLatin1() ); } if ( ! chroot.isEmpty() ) args << chroot << "pw"; args << "userdel"; args << userIt->getUsername(); if(userIt->getDeleteHome()) { args << "-r"; system("/usr/local/share/pcbsd/scripts/rmzfsdir.sh " + userIt->getHome().toLatin1() ); } if ( ! chroot.isEmpty() ) QProcess::execute("chroot", args); else QProcess::execute("pw", args); break; } } refreshUsers(); //Process groups QMap<int, Group>::Iterator groupIt; for ( groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt ) { args.clear(); switch(groupIt->getStatus()) { case 1: //Modify Group qDebug() << "Modifying group " << groupIt->getGroupname(); if ( ! chroot.isEmpty() ) args << chroot << "pw"; args << "groupmod"; args << groupIt->getGroupname(); args << "-M"; args << groupIt->getMembers().join(","); if ( ! chroot.isEmpty() ) QProcess::execute("chroot", args); else QProcess::execute("pw", args); break; case 2: //Add Group qDebug() << "Adding group " << groupIt->getGroupname(); if ( ! chroot.isEmpty() ) args << chroot << "pw"; args << "groupadd"; args << groupIt->getGroupname(); args << "-M"; args << groupIt->getMembers().join(","); if ( ! chroot.isEmpty() ) QProcess::execute("chroot", args); else QProcess::execute("pw", args); break; case 3: //Delete Group qDebug() << "Deleting group " << groupIt->getGroupname(); if ( ! chroot.isEmpty() ) args << chroot << "pw"; args << "groupdel"; args << groupIt->getGroupname(); if ( ! chroot.isEmpty() ) QProcess::execute("chroot", args); else QProcess::execute("pw", args); break; } } refreshGroups(); emit groupsChanged(); emit usersChanged(); return true; }