5 #include <QCryptographicHash>
39 , _passwordFile(passwdFile)
65 QJsonObject d = r->
_data.object();
67 bool auth = r->
_path ==
"";
69 QString user = auth ? d[
"username"].toString(
"") : r->
_path;
70 QString pass = d[
"password"].toString(
"");
72 QString hash = auth ? QCryptographicHash::hash(pass.toUtf8(),QCryptographicHash::Md5).toHex() :
"[0-9A-F]+";
75 if (!passwd.open(QIODevice::ReadOnly | QIODevice::Text))
82 QRegExp prx( QString(
"%1 %2 ?(\\d*) ?\"?([^\"]*)\"?\\s?([^\\s]*)\n").arg(user).arg(hash), Qt::CaseInsensitive );
83 while (!passwd.atEnd())
85 QString line( passwd.readLine() );
87 if (prx.exactMatch(line))
90 int c = prx.capturedTexts().length();
93 d[
"uidnumber"] = c > 1 ? prx.cap(1).toInt() : 0;
94 d[
"realname"] = c > 2 && prx.cap(2).size() ? prx.cap(2) : user;
95 d[
"groups"] = (c > 3) ? QJsonArray::fromStringList(prx.cap(3).split(
",")) : QJsonArray();
101 r->
_data.setObject(d);
124 if (!passwd.open(QIODevice::ReadOnly | QIODevice::Text))
133 QRegExp prx( QString(
"([^\\s]*) ([^\\s]*) ?(\\d*) ?\"?([^\"]*)\"?\\s?([^\\s]*)\n") );
134 while (!passwd.atEnd())
136 QString line( passwd.readLine() );
138 if (prx.exactMatch(line))
141 int c = prx.capturedTexts().length();
148 QString username = prx.cap(1);
149 o[username] = QJsonObject { {
"username", username }, {
"uidnumber", prx.cap(3).toInt() }, {
"realname", prx.cap(4).trimmed().size() ? prx.cap(4) : username } };
153 case 3: { QString username = prx.cap(1);
154 o[username] = QJsonObject { {
"username", username }, {
"uidnumber", prx.cap(3).toInt() }, {
"realname", username } };
158 case 2: { QString username = prx.cap(1);
159 o[username] = QJsonObject { {
"username", username }, {
"uidnumber", 0 }, {
"realname", username } };
175 QJsonObject u = r->
_data.object();
179 r->
_data.setObject(u);
The base class for authenticating users.
QString _passwordFile
The filesystem path to the passwd file.
virtual void ls(VFS_request *r)
List the users available for this auth method.
Q_INVOKABLE VFS_passwd(QString file)
virtual QString reportDetails()
Additional details for a generated report.
virtual void read(VFS_request *r)
Perform an authentication request by read()ing from this node.
The base class for all requests between nodes.
QString _initialPath
the target path when the request was made (relative to the responder)
QString _reason
if something (probably bad) happened, this is the reason
QString _path
the target path remnant... the remaining path element once the request has found its target
bool _success
if the request was successfully completed
QJsonDocument _data
the request payload