File indexing completed on 2024-05-19 05:50:39

0001 /*************************************************************************************
0002  *  Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org>              *
0003  *                                                                                   *
0004  *  This program is free software; you can redistribute it and/or                    *
0005  *  modify it under the terms of the GNU General Public License                      *
0006  *  as published by the Free Software Foundation; either version 2                   *
0007  *  of the License, or (at your option) any later version.                           *
0008  *                                                                                   *
0009  *  This program is distributed in the hope that it will be useful,                  *
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0012  *  GNU General Public License for more details.                                     *
0013  *                                                                                   *
0014  *  You should have received a copy of the GNU General Public License                *
0015  *  along with this program; if not, write to the Free Software                      *
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0017  *************************************************************************************/
0018 
0019 #include <QProcess>
0020 #include <QDebug>
0021 #include <iostream>
0022 
0023 int issueMount(const QStringList &arguments)
0024 {
0025     QProcess proc;
0026     proc.start("mount", arguments);
0027     proc.waitForFinished();
0028 
0029     std::cerr << proc.readAllStandardError().toStdString() << std::endl;
0030     std::cerr << proc.readAllStandardOutput().toStdString() << std::endl;
0031 
0032     return proc.exitCode();
0033 }
0034 
0035 int main(int argc, char** argv)
0036 {
0037     if (argc < 7) {
0038         std::cerr << "Not enough arguments" << std::endl;
0039         return 1;
0040     }
0041 
0042     QString sambaDir = QString::fromUtf8(QByteArray::fromBase64(argv[2]));
0043     QString mountPoint = QString::fromUtf8(QByteArray::fromBase64(argv[3]));
0044     const QString share = QStringLiteral("//") + argv[1] + sambaDir;
0045     QString uid (argv[4]);
0046     QString username(QString::fromUtf8(QByteArray::fromBase64(argv[5])));
0047     QString password(QString::fromUtf8(QByteArray::fromBase64(argv[6])));
0048 
0049     QString options;
0050     if (username != "none" && !username.isEmpty()) {
0051         options.append("username=" + username);
0052     } else {
0053         options.append("guest");
0054     }
0055     if (password != "none" && !password.isEmpty()) {
0056         options.append(",password=" + password);
0057     }
0058 
0059     options.append(",uid=" + uid);
0060 
0061     const QStringList arguments({ "-t", "cifs", share, mountPoint, "-o", options });
0062 
0063     auto code = issueMount(arguments);
0064     if (code != 0) {
0065         code = issueMount(QStringList(arguments) << QStringList{QStringLiteral("-o"), QStringLiteral("vers=1.0")});
0066     }
0067     return code;
0068 }