Skip to content

Commit

Permalink
Unix: Disable 'crypt' command on Python >= 3.13
Browse files Browse the repository at this point in the history
The module is not available anymore
  • Loading branch information
progval committed May 5, 2024
1 parent 9767f2d commit 73806ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
1 change: 0 additions & 1 deletion plugins/Internet/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def testDns(self):
'Host not found.')

def testWhois(self):
self.assertNotError('internet whois ohio-state.edu')
self.assertNotError('internet whois microsoft.com')
self.assertNotError('internet whois inria.fr')
self.assertNotError('internet whois slime.com.au')
Expand Down
44 changes: 25 additions & 19 deletions plugins/Unix/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@
import re
import pwd
import sys
import crypt
import errno
import random
import select
import struct
import subprocess
import shlex

try:
import crypt
except ImportError:
# Python >= 3.13
crypt = None

import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import *
Expand Down Expand Up @@ -119,25 +124,26 @@ def pid(self, irc, msg, args):
irc.reply(format('%i', os.getpid()), private=True)
pid = wrap(pid, [('checkCapability', 'owner')])

_cryptre = re.compile(b'[./0-9A-Za-z]')
@internationalizeDocstring
def crypt(self, irc, msg, args, password, salt):
"""<password> [<salt>]
if crypt is not None: # Python < 3.13
_cryptre = re.compile(b'[./0-9A-Za-z]')
@internationalizeDocstring
def crypt(self, irc, msg, args, password, salt):
"""<password> [<salt>]
Returns the resulting of doing a crypt() on <password>. If <salt> is
not given, uses a random salt. If running on a glibc2 system,
prepending '$1$' to your salt will cause crypt to return an MD5sum
based crypt rather than the standard DES based crypt.
"""
def makeSalt():
s = b'\x00'
while self._cryptre.sub(b'', s) != b'':
s = struct.pack('<h', random.randrange(-(2**15), 2**15))
return s
if not salt:
salt = makeSalt().decode()
irc.reply(crypt.crypt(password, salt))
crypt = wrap(crypt, ['something', additional('something')])
Returns the resulting of doing a crypt() on <password>. If <salt> is
not given, uses a random salt. If running on a glibc2 system,
prepending '$1$' to your salt will cause crypt to return an MD5sum
based crypt rather than the standard DES based crypt.
"""
def makeSalt():
s = b'\x00'
while self._cryptre.sub(b'', s) != b'':
s = struct.pack('<h', random.randrange(-(2**15), 2**15))
return s
if not salt:
salt = makeSalt().decode()
irc.reply(crypt.crypt(password, salt))
crypt = wrap(crypt, ['something', additional('something')])

@internationalizeDocstring
def spell(self, irc, msg, args, word):
Expand Down

0 comments on commit 73806ec

Please sign in to comment.