]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
Bug 512: add QualifyPWD and PWD checking support
authorLee Howard <faxguy@howardsilvan.com>
Fri, 5 Mar 2004 02:41:38 +0000 (02:41 +0000)
committerLee Howard <faxguy@howardsilvan.com>
Fri, 5 Mar 2004 02:41:38 +0000 (02:41 +0000)
faxd/FaxRecv.c++
faxd/ServerConfig.c++
faxd/ServerConfig.h
man/hylafax-config.4f
util/FaxRecvInfo.c++
util/FaxRecvInfo.h

index f4b5af65903036785e4c955dae81282868462849..ea3bbb786b8483a12b1a17cc6b8fee7fe47be89f 100644 (file)
@@ -154,32 +154,43 @@ FaxServer::recvDocuments(TIFF* tif, FaxRecvInfo& info, FaxRecvInfoArray& docs, f
     u_int ppm = PPM_EOP;
     pageStart = Sys::now();
     for (;;) {
+       bool okToRecv = true;
+       fxStr reason;
        modem->getRecvSUB(info.subaddr);                // optional subaddress
+       /*
+        * Check a received TSI/PWD against the list of acceptable
+        * patterns defined for the server.  This form of access
+        * control depends on the sender passing a valid TSI/PWD.
+        * Note that to accept/reject unspecified values one
+        * should match "<UNSPECIFIED>".
+        *
+        * NB: Caller-ID access control is done elsewhere; prior
+        *     to answering a call.
+        */
        if (!modem->getRecvTSI(info.sender))            // optional TSI
            info.sender = "<UNSPECIFIED>";
        if (qualifyTSI != "") {
-           /*
-            * Check a received TSI against the list of acceptable
-            * TSI patterns defined for the server.  This form of
-            * access control depends on the sender passing a valid
-            * TSI.  Note that to accept/reject an unspecified TSI
-            * one should match "<UNSPECIFIED>".
-            *
-            * NB: Caller-ID access control is done elsewhere; prior
-            *     to answering a call.
-            */
-           bool okToRecv = isTSIOk(info.sender);
+           okToRecv = isTSIOk(info.sender);
+           reason = "Permission denied (unnacceptable client TSI)";
            traceServer("%s TSI \"%s\"", okToRecv ? "ACCEPT" : "REJECT",
                (const char*) info.sender);
-           if (!okToRecv) {
-               emsg = "Permission denied (unacceptable client TSI)";
-               info.time = (u_int) getFileTransferTime();
-               info.reason = emsg;
-               docs[docs.length()-1] = info;
-               notifyDocumentRecvd(info);
-               TIFFClose(tif);
-               return (false);
-           }
+       }
+       if (!modem->getRecvPWD(info.passwd))            // optional PWD
+           info.passwd = "<UNSPECIFIED>";
+       if (qualifyPWD != "") {
+           okToRecv = isPWDOk(info.passwd);
+           reason = "Permission denied (unnacceptable client PWD)";
+           traceServer("%s PWD \"%s\"", okToRecv ? "ACCEPT" : "REJECT",
+               (const char*) info.passwd);
+       }
+       if (!okToRecv) {
+           emsg = reason;
+           info.time = (u_int) getFileTransferTime();
+           info.reason = emsg;
+           docs[docs.length()-1] = info;
+           notifyDocumentRecvd(info);
+           TIFFClose(tif);
+           return (false);
        }
        setServerStatus("Receiving from \"%s\"", (const char*) info.sender);
        recvOK = recvFaxPhaseD(tif, info, ppm, emsg);
index 019416cda1329ab516751316cd9f1c38778a05e2..efc19aa67da0cc65ad52ec2661506c545399597e 100644 (file)
 ServerConfig::ServerConfig()
 {
     lastTSIModTime = 0;
+    lastPWDModTime = 0;
     tsiPats = NULL;
+    pwdPats = NULL;
     acceptTSI = NULL;
+    acceptPWD = NULL;
     dialRules = NULL;
     setupConfig();
 }
@@ -49,7 +52,9 @@ ServerConfig::~ServerConfig()
 {
     delete dialRules;
     delete acceptTSI;
+    delete acceptPWD;
     delete tsiPats;
+    delete pwdPats;
 }
 
 void
@@ -80,6 +85,7 @@ ServerConfig::S_stringtag ServerConfig::strings[] = {
 { "longdistanceprefix",        &ServerConfig::longDistancePrefix },
 { "internationalprefix",&ServerConfig::internationalPrefix },
 { "qualifytsi",                &ServerConfig::qualifyTSI },
+{ "qualifypwd",                &ServerConfig::qualifyPWD },
 { "uucplockdir",       &ServerConfig::uucpLockDir,     UUCP_LOCKDIR },
 { "uucplocktype",      &ServerConfig::uucpLockType,    UUCP_LOCKTYPE },
 };
@@ -301,6 +307,13 @@ ServerConfig::isTSIOk(const fxStr& tsi)
     return (qualifyTSI == "" ? true : checkACL(tsi, tsiPats, *acceptTSI));
 }
 
+bool
+ServerConfig::isPWDOk(const fxStr& pwd)
+{
+    updatePatterns(qualifyPWD, pwdPats, acceptPWD, lastPWDModTime);
+    return (qualifyPWD == "" ? true : checkACL(pwd, pwdPats, *acceptPWD));
+}
+
 /*
  * Update pattern arrays if a file patterns has
  * been changed since the last time we read it.
index 081eee9021ee34c15269cba926f22b1cc8239442..1d92e64300b9dce64e28fccc03f288319c36de21 100644 (file)
@@ -66,8 +66,11 @@ private:
     mode_t     uucpLockMode;           // UUCP lock file creation mode
     u_int      uucpLockTimeout;        // UUCP stale lock file timeout
     time_t     lastTSIModTime;         // last mod time of TSI patterns file
+    time_t     lastPWDModTime;         // last mod time of PWD patterns file
     REArray*   tsiPats;                // recv tsi patterns
+    REArray*   pwdPats;                // recv PWD patterns
     fxBoolArray* acceptTSI;            // accept/reject matched tsi
+    fxBoolArray* acceptPWD;            // accept/reject matched PWD
     fxStr      logFacility;            // syslog facility to direct trace msgs
 
     static S_stringtag strings[];
@@ -94,6 +97,7 @@ protected:
 public:
     SpeakerVolume speakerVolume;       // volume control
     fxStr      qualifyTSI;             // if set, no recv w/o acceptable tsi
+    fxStr      qualifyPWD;             // if set, no recv w/o acceptable PWD
     u_int      noCarrierRetrys;        // # times to retry on no carrier
     mode_t     recvFileMode;           // protection mode for received files
     mode_t     deviceMode;             // protection mode for modem device
@@ -124,6 +128,7 @@ public:
     UUCPLock*  getUUCPLock(const fxStr& deviceName);
 
     bool       isTSIOk(const fxStr& tsi);
+    bool       isPWDOk(const fxStr& pwd);
 
     virtual void vconfigError(const char* fmt, va_list ap) = 0;
     virtual void vconfigTrace(const char* fmt, va_list ap) = 0;
index f046687d6a7444f74444853c9b39346bae499191..d550a13e72541992ae72977c4e755685a06967c5 100644 (file)
@@ -171,6 +171,7 @@ PostScriptTimeout\(S1       integer \s-1300\s+1     timeout on \*(Ps interpreter runs (sec
 PriorityScheduling     boolean \s-1\fIsee below\fP\s+1 use available priority job scheduling mechanism
 PS2FaxCmd\(S1  string  \s-1bin/ps2fax\s+1      \*(Ps \s-1RIP\s+1 command script
 QualifyCID     string  \-      file of Caller-ID or DNIS patterns for checking inbound calls
+QualifyPWD     string  \-      file of \s-1PWD\s+1 patterns for qualifying senders
 QualifyTSI     string  \-      file of \s-1TSI\s+1 patterns for qualifying senders
 RecvDataFormat string  \s-1adaptive\s+1        format for received facsimile data
 RecvFileMode   octal   \s-10600\s+1    protection mode to use for received facsimile files
@@ -1030,6 +1031,17 @@ and
 parameters must also be setup to reflect the manner in which
 the modem returns Caller-ID status or DNIS data information to the host.
 .TP
+.B QualifyPWD
+A string that specifies whether or not the identity of 
+calling facsimile machines should be checked against an access
+control list before receiving facsimile.
+If 
+.B QualifyPWD
+is non-null, then only messages from facsimile machines identified
+in the file specified by the string (typically \fBetc/passwd\fP)
+will be accepted; similar to
+.B QualifyTSI.
+.TP
 .B QualifyTSI
 A string that specifies whether or not the identity of 
 calling facsimile machines should be checked against an access
index 3bb0a0a5348b9255a99e10da9ddc2f1fb1372665..e686ad69d9216f4c3a0701aec737c288dfaca18a 100644 (file)
@@ -35,6 +35,7 @@ FaxRecvInfo::FaxRecvInfo(const FaxRecvInfo& other)
     , qfile(other.qfile)
     , commid(other.commid)
     , sender(other.sender)
+    , passwd(other.passwd)
     , subaddr(other.subaddr)
     , params(other.params)
     , reason(other.reason)
@@ -49,13 +50,14 @@ FaxRecvInfo::~FaxRecvInfo() {}
 fxStr
 FaxRecvInfo::encode() const
 {
-    return fxStr::format("%x,%x,%x,%s,%s,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\""
+    return fxStr::format("%x,%x,%x,%s,%s,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\""
        , time
        , npages
        , params.encode()
        , (const char*) qfile
        , (const char*) commid
        , (const char*) sender
+       , (const char*) passwd
        , (const char*) subaddr
        , (const char*) reason
        , (const char*) cidname
@@ -91,7 +93,12 @@ FaxRecvInfo::decode(const char* cp)
     cp = strchr(cp+1, '"');
     if (cp == NULL || cp[1] != ',' || cp[2] != '"')
        return (false);
-    subaddr = cp+1;
+    passwd = cp+1;
+    passwd.resize(sender.next(0,'"'));
+    cp = strchr(cp+1, '"');
+    if (cp == NULL || cp[1] != ',' || cp[2] != '"')
+       return (false);
+    reason = cp+3;                     // +1 for "/+1 for ,/+1 for "
     subaddr.resize(subaddr.next(0,'"'));
     cp = strchr(cp+1, '"');
     if (cp == NULL || cp[1] != ',' || cp[2] != '"')
index 722f9dcfda60c79fef135c188b702bf582a41933..ddedfa7af2867daa2a6cc6fcb5cd765de4d24925 100644 (file)
@@ -38,6 +38,7 @@ public:
     u_short    npages;         // total number of pages/page number
     fxStr      commid;         // communication identifier
     fxStr      sender;         // sender's TSI
+    fxStr      passwd;         // sender's PWD
     fxStr      subaddr;        // subaddressing information
     u_int      time;           // time on the phone
     Class2Params params;       // transfer parameters