~mateo-salta/nitroshare/nitroshare

« back to all changes in this revision

Viewing changes to src/CFileReceiver.cpp

  • Committer: Nathan Osman
  • Date: 2012-06-20 04:12:55 UTC
  • Revision ID: admin@quickmediasolutions.com-20120620041255-q9h0r4phyz3x6vqw
Implemented security policy for incoming files... even though they still aren't properly stored on the receiving end.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
#include <cstring>
18
18
#include <QFile>
 
19
#include <QList>
 
20
#include <QRegExp>
19
21
#include <QSettings>
20
22
 
 
23
#include <CAcceptPromptDialog.h>
21
24
#include <CFileReceiver.h>
22
25
#include <defaults.h>
23
26
 
27
30
    connect(this, SIGNAL(readyRead()), SLOT(OnReadyRead()));
28
31
 
29
32
    setSocketDescriptor(handle);
 
33
    m_hostname = peerAddress().toString();
30
34
}
31
35
 
32
36
void CFileReceiver::OnReadyRead()
42
46
            m_read_buffer.clear();
43
47
 
44
48
            // Continue to the next stage of the transfer
45
 
            write("CONTINUE");
46
 
            m_state = WaitingForTransfer;
 
49
            if(TestAgainstPolicy(m_header))
 
50
            {
 
51
                write("CONTINUE");
 
52
                m_state = WaitingForTransfer;
 
53
            }
47
54
        }
48
55
    }
49
56
    else
57
64
    }
58
65
}
59
66
 
60
 
bool CFileReceiver::TestAgainstPolicy(QString)
 
67
bool CFileReceiver::TestAgainstPolicy(CFileHeader header)
61
68
{
62
69
    QSettings settings;
63
70
    int policy = settings.value("Security/IncomingPolicy", Defaults::Security::IncomingPolicy).toInt();
69
76
    // Next check if we need to prompt the user
70
77
    if(policy == Defaults::Security::AcceptPrompt)
71
78
    {
72
 
        //...
 
79
        QList<CFileHeader> files;
 
80
        files.append(header);
 
81
 
 
82
        CAcceptPromptDialog dialog(m_hostname, files);
 
83
        return dialog.exec();
73
84
    }
74
85
 
 
86
    // Perform the regular expression match
 
87
    QRegExp pattern(settings.value("Security/IncomingPattern", Defaults::Security::IncomingPattern).toString());
 
88
    if(pattern.indexIn(header.filename) == -1)
 
89
        return false;
 
90
 
75
91
    return true;
76
92
}