[PC-BSD Commits] r16092 - pcbsd/current/src-qt4/pc-usermanager

svn at pcbsd.org svn at pcbsd.org
Thu Mar 29 12:41:31 PDT 2012


Author: kris
Date: 2012-03-29 19:41:31 +0000 (Thu, 29 Mar 2012)
New Revision: 16092

Modified:
   pcbsd/current/src-qt4/pc-usermanager/main.cpp
   pcbsd/current/src-qt4/pc-usermanager/maindlgcode.cpp
   pcbsd/current/src-qt4/pc-usermanager/maindlgcode.h
   pcbsd/current/src-qt4/pc-usermanager/pcbsdusermanager.cpp
   pcbsd/current/src-qt4/pc-usermanager/pcbsdusermanager.h
   pcbsd/current/src-qt4/pc-usermanager/simpledlgcode.cpp
   pcbsd/current/src-qt4/pc-usermanager/simpledlgcode.h
   pcbsd/current/src-qt4/pc-usermanager/usermanagerback.cpp
   pcbsd/current/src-qt4/pc-usermanager/usermanagerback.h
Log:

Make the pc-usermanager aware of jails with new -warden flag



Modified: pcbsd/current/src-qt4/pc-usermanager/main.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-usermanager/main.cpp	2012-03-29 19:28:30 UTC (rev 16091)
+++ pcbsd/current/src-qt4/pc-usermanager/main.cpp	2012-03-29 19:41:31 UTC (rev 16092)
@@ -20,7 +20,21 @@
     qDebug() << "Locale:" << langCode;
 
     PCBSDUserManager w; 
+
+    if ( argc >= 2)
+    {
+       QString chkarg = argv[1];
+       // Running in a warden jail?
+       if ( chkarg == "-warden" )
+         if ( argc == 4 )
+           w.setWardenMode(QString(argv[2]), QString(argv[3]));
+         else {
+           qDebug() << "Usage: -warden <directory> <ip>";
+           exit(1);
+         }
+    }
 	
+    w.setupUMDialogs();
     w.show();
     a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
     return a.exec();

Modified: pcbsd/current/src-qt4/pc-usermanager/maindlgcode.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-usermanager/maindlgcode.cpp	2012-03-29 19:28:30 UTC (rev 16091)
+++ pcbsd/current/src-qt4/pc-usermanager/maindlgcode.cpp	2012-03-29 19:41:31 UTC (rev 16092)
@@ -34,10 +34,12 @@
 #include <qpushbutton.h>
 #include <qtooltip.h>
         
-void mainDlgCode::programInit(UserManagerBackend *back)
+void mainDlgCode::programInit(UserManagerBackend *back, QString dir)
 {
     setEnabled(false);
     
+    chroot = dir;
+
     this->back = back;
     availablePointer = 0;
     memberPointer = 0;

Modified: pcbsd/current/src-qt4/pc-usermanager/maindlgcode.h
===================================================================
--- pcbsd/current/src-qt4/pc-usermanager/maindlgcode.h	2012-03-29 19:28:30 UTC (rev 16091)
+++ pcbsd/current/src-qt4/pc-usermanager/maindlgcode.h	2012-03-29 19:41:31 UTC (rev 16092)
@@ -40,7 +40,7 @@
     { 
       setupUi(this);
     }
-    void programInit(UserManagerBackend *back);
+    void programInit(UserManagerBackend *back, QString);
     void updateUserList();
     void updateShellList();
     void updateGroupList();
@@ -75,6 +75,7 @@
     QColor red;
     QColor orange;
     bool systemChange;
+    QString chroot;
     
     void enableEdits(bool enable);
     

Modified: pcbsd/current/src-qt4/pc-usermanager/pcbsdusermanager.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-usermanager/pcbsdusermanager.cpp	2012-03-29 19:28:30 UTC (rev 16091)
+++ pcbsd/current/src-qt4/pc-usermanager/pcbsdusermanager.cpp	2012-03-29 19:41:31 UTC (rev 16092)
@@ -41,11 +41,11 @@
        connect(pushClose, SIGNAL(clicked()), this, SLOT(slotClose()));
        connect(pushSave, SIGNAL(clicked()), this, SLOT(slotSave()));
 
-       back = new UserManagerBackend();
+       back = new UserManagerBackend(wDir);
        advancedGui = new mainDlgCode();
-       advancedGui->programInit(back);
+       advancedGui->programInit(back, wDir);
        simpleGui = new SimpleDlgCode();
-       simpleGui->programInit(back);
+       simpleGui->programInit(back, wDir);
        layout->addWidget(simpleGui);
  
        connect(advancedGui, SIGNAL(changed( bool )), this, SLOT(configChanged()));
@@ -117,3 +117,10 @@
 {
     slotClose();
 }
+
+void PCBSDUserManager::setWardenMode(QString d, QString ip)
+{
+  wDir = d;
+  wIP = ip;
+  setWindowTitle(tr("Editing Users for Jail:") + " " + wIP );
+}

Modified: pcbsd/current/src-qt4/pc-usermanager/pcbsdusermanager.h
===================================================================
--- pcbsd/current/src-qt4/pc-usermanager/pcbsdusermanager.h	2012-03-29 19:28:30 UTC (rev 16091)
+++ pcbsd/current/src-qt4/pc-usermanager/pcbsdusermanager.h	2012-03-29 19:41:31 UTC (rev 16092)
@@ -42,11 +42,12 @@
     PCBSDUserManager() : QDialog()
     {
        setupUi(this);
-       setupUMDialogs();
+       //setupUMDialogs();
     }
     
     ~PCBSDUserManager();
     void setupUMDialogs();
+    void setWardenMode(QString, QString);
     virtual void closeEvent(QCloseEvent*);
 
 public slots:
@@ -64,6 +65,8 @@
     SimpleDlgCode *simpleGui;
     QGridLayout *layout;
     bool changesMade;
+    QString wDir;
+    QString wIP;
 };
 
 #endif

Modified: pcbsd/current/src-qt4/pc-usermanager/simpledlgcode.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-usermanager/simpledlgcode.cpp	2012-03-29 19:28:30 UTC (rev 16091)
+++ pcbsd/current/src-qt4/pc-usermanager/simpledlgcode.cpp	2012-03-29 19:41:31 UTC (rev 16092)
@@ -33,11 +33,12 @@
 #include <QDebug>
 #include "../config.h"
 
-void SimpleDlgCode::programInit(UserManagerBackend *back)
+void SimpleDlgCode::programInit(UserManagerBackend *back, QString dir)
 {
     this->back = back;
     userImage = QPixmap(PREFIX + "/share/icons/crystalsvg/48x48/kdm/user_male.png");
     systemChange = false;
+    chroot = dir;
     
     refreshUsers();
     
@@ -65,6 +66,13 @@
     userList->clear();
     
     qDebug() << "All Users in list:" << users;
+
+    // If no users setup yet, lets diable the details and return
+    if ( users.isEmpty() ) {
+      frame->setEnabled(false); 
+      return;
+    }
+    frame->setEnabled(true); 
     for ( QStringList::Iterator it = users.begin(); it != users.end(); ++it )
     {
 	new QListWidgetItem(userImage, *it + " (" + back->getUser(*it)->getFullname() + ")", userList);

Modified: pcbsd/current/src-qt4/pc-usermanager/simpledlgcode.h
===================================================================
--- pcbsd/current/src-qt4/pc-usermanager/simpledlgcode.h	2012-03-29 19:28:30 UTC (rev 16091)
+++ pcbsd/current/src-qt4/pc-usermanager/simpledlgcode.h	2012-03-29 19:41:31 UTC (rev 16092)
@@ -40,7 +40,7 @@
     {
         setupUi(this);
     }
-    void programInit(UserManagerBackend *back);
+    void programInit(UserManagerBackend *back, QString);
     
 private:
     UserManagerBackend *back;
@@ -49,6 +49,7 @@
     bool systemChange;
     ChangePassCode *changePassUi;
     SimpleAddCode *addUserUi;
+    QString chroot;
     
 public slots:
     void advancedPressed();

Modified: pcbsd/current/src-qt4/pc-usermanager/usermanagerback.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-usermanager/usermanagerback.cpp	2012-03-29 19:28:30 UTC (rev 16091)
+++ pcbsd/current/src-qt4/pc-usermanager/usermanagerback.cpp	2012-03-29 19:41:31 UTC (rev 16092)
@@ -28,8 +28,9 @@
 #include <QUrl>
 #include <QFileInfo>
 
-UserManagerBackend::UserManagerBackend() {
-   programInit();
+UserManagerBackend::UserManagerBackend(QString dir) {
+    chroot = dir;
+    programInit();
 }
 
 void UserManagerBackend::programInit() {
@@ -61,7 +62,7 @@
 void UserManagerBackend::refreshUsers() {
     qDebug() << "Refreshing user list...";
     userList.clear();
-    QFile userFile("/etc/passwd");
+    QFile userFile(chroot + "/etc/passwd");
     if ( userFile.open(QIODevice::ReadOnly) ) {
 	QTextStream stream(&userFile);
 	stream.setCodec("UTF-8");
@@ -94,7 +95,7 @@
 
 QStringList UserManagerBackend::getShells() {
     QStringList result;
-    QFile shellFile("/etc/shells");
+    QFile shellFile(chroot + "/etc/shells");
     if ( shellFile.open(QIODevice::ReadOnly) ) {
 	QTextStream stream(&shellFile);
 	stream.setCodec("UTF-8");
@@ -141,7 +142,7 @@
 void UserManagerBackend::refreshGroups() {
     qDebug() << "Refreshing group list...";
     groupList.clear();
-    QFile groupFile("/etc/group");
+    QFile groupFile(chroot + "/etc/group");
     if ( groupFile.open(QIODevice::ReadOnly) ) {
 	QTextStream stream(&groupFile);
 	stream.setCodec("UTF-8");
@@ -351,6 +352,8 @@
             case 1:
                 //Modify User
                 qDebug() << "Modifying user " << userIt->getUsername();
+		if ( ! chroot.isEmpty() )
+		   args << chroot << "pw";
                 args << "usermod";
                 args << userIt->getUsername();
                 args << "-d";
@@ -359,20 +362,30 @@
                 args << userIt->getShell();
                 args << "-c";
                 args << userIt->getFullname();
-		QProcess::execute("pw", args);
+		if ( ! chroot.isEmpty() )
+		   QProcess::execute("chroot", args);
+		else
+		   QProcess::execute("pw", args);
                 
                 if (userIt->getPassword() != "")
                 {
 		    args.clear();
+		    if ( ! chroot.isEmpty() )
+		       args << chroot << "chpass";
                     args << "-p";
                     args << userIt->getPassword();
                     args << userIt->getUsername();
-		    QProcess::execute("chpass", args);
+		    if ( ! chroot.isEmpty() )
+		      QProcess::execute("chroot", args);
+		    else 
+		      QProcess::execute("chpass", args);
                 }
                 break;
             case 2:
                 //Add User
                 qDebug() << "Adding user " << userIt->getUsername();
+		if ( ! chroot.isEmpty() )
+		   args << chroot << "pw";
                 args << "useradd";
                 args << userIt->getUsername();
                 args << "-c";
@@ -389,21 +402,34 @@
                 args << "-G";
                 args << "operator";
                 if (validateHome(userIt->getHome()) == 3) { args << "-m"; }
-		QProcess::execute("pw", args);
+		if ( ! chroot.isEmpty() )
+		   QProcess::execute("chroot", args);
+		else
+		   QProcess::execute("pw", args);
                 
 		args.clear();
+		if ( ! chroot.isEmpty() )
+		   args << chroot << "chpass";
                 args << "-p";
                 args << userIt->getPassword();
                 args << userIt->getUsername();
-		QProcess::execute("chpass", args);
+		if ( ! chroot.isEmpty() )
+		   QProcess::execute("chroot", args);
+		else
+		   QProcess::execute("chpass", args);
                 break;
             case 3:
                 //Delete User
                 qDebug() << "Deleting user " << userIt->getUsername();
+		if ( ! chroot.isEmpty() )
+		   args << chroot << "pw";
                 args << "userdel";
                 args << userIt->getUsername();
                 if(userIt->getDeleteHome()) args << "-r";
-		QProcess::execute("pw", args);
+		if ( ! chroot.isEmpty() )
+		   QProcess::execute("chroot", args);
+		else
+		   QProcess::execute("pw", args);
                 break;
         }
     }
@@ -420,27 +446,42 @@
             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(",");
-		QProcess::execute("pw", args);
+		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(",");
-		QProcess::execute("pw", args);
+		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();
-		QProcess::execute("pw", args);
+		if ( ! chroot.isEmpty() )
+		   QProcess::execute("chroot", args);
+		else
+		   QProcess::execute("pw", args);
                 break;
 	}
     }

Modified: pcbsd/current/src-qt4/pc-usermanager/usermanagerback.h
===================================================================
--- pcbsd/current/src-qt4/pc-usermanager/usermanagerback.h	2012-03-29 19:28:30 UTC (rev 16091)
+++ pcbsd/current/src-qt4/pc-usermanager/usermanagerback.h	2012-03-29 19:41:31 UTC (rev 16092)
@@ -37,7 +37,7 @@
 class UserManagerBackend : public QObject {
     Q_OBJECT
 public:
-    UserManagerBackend();
+    UserManagerBackend(QString);
     void programInit();
     QStringList getAllUsers(int minId = 1000, int maxId = 65532); //Set variables to -1 to ignore
     User* getUser(const QString &user);
@@ -70,6 +70,7 @@
     QRegExp passwordRegExp;
     QRegExp groupnameRegExp;
     QProcess *pw;
+    QString chroot;
     
 signals:
     void usersChanged();



More information about the Commits mailing list