-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: urcd
action: commit
revision:
path_from:
revision_from: d565c1f58221ab792c6f0bfe8c4f8a9c2d54ff97:
path_to:
revision_to:

git.thebackupbox.net

urcd

git://git.thebackupbox.net/urcd

commit d565c1f58221ab792c6f0bfe8c4f8a9c2d54ff97
Author: root <root@localhost.(none)>
Date:   Fri Dec 26 14:31:03 2014 +0000

    [urcd] ...

diff --git a/src/urcd.pyx b/src/urcd.pyx

index cb5b41b0b606391663e66b0668de728e47a70e2e..

index ..cf066e01843b784d6883aca71b78a4dee3806834 100644

--- a/src/urcd.pyx
+++ b/src/urcd.pyx
@@ -80,7 +80,6 @@ Src = dict()
 Mask = dict()
 active_clients = dict()
 channel_struct = dict() ### operations assume nick is in channel_struct[dst]['names'] if dst in channels ###
-struct_channel = dict(names=collections.deque([],CHANLIMIT), topic=None)
 channels = collections.deque([],CHANLIMIT)
 bytes = [(chr(i),i) for i in xrange(0,256)]
 motd = open('env/motd','rb').read().split('\n')
@@ -104,18 +103,18 @@ if URCDB:
  try: active_clients = db['active_clients']
  except: pass

- while len(Src) > CHANLIMIT*CHANLIMIT: del Src[Src[0]]
- while len(Mask) > CHANLIMIT*CHANLIMIT: del Mask[Mask[0]]
- while len(channel_struct) > CHANLIMIT: del channel_struct[channel_struct[0]]
- while len(active_clients) > CHANLIMIT*CHANLIMIT: del active_clients[active_clients[0]]
+ while len(Src) > CHANLIMIT*CHANLIMIT: del Src[Src.keys()[0]]
+ while len(Mask) > CHANLIMIT*CHANLIMIT: del Mask[Mask.keys()[0]]
+ while len(channel_struct) > CHANLIMIT: del channel_struct[channel_struct.keys()[0]]
+ while len(active_clients) > CHANLIMIT*CHANLIMIT: del active_clients[active_clients.keys()[0]]

-for dst in channel_struct:
+for dst in channel_struct.keys():
  channel_struct[dst]['names'] = collections.deque(list(channel_struct[dst]['names']),CHANLIMIT)
  if channel_struct[dst]['topic']: channel_struct[dst]['topic'] = channel_struct[dst]['topic'][:TOPICLEN]
  for src in channel_struct[dst]['names']:
-  if not src in active_clients: active_clients[src] = now
-  if not src in Mask: Mask[src] = serv
-  if not src in Src: Src[src] = src
+  if not src in active_clients.keys(): active_clients[src] = now
+  if not src in Mask.keys(): Mask[src] = serv
+  if not src in Src.keys(): Src[src] = src

 def try_read(fd,buflen):
  try: return os.read(fd,buflen)
@@ -133,7 +132,7 @@ def try_write(fd,buffer):
    time.sleep(1)

 ### nacl-20110221's randombytes() not compatible with chroot ###
-devurandomfd = os.open('/dev/urandom',os.O_RDONLY)
+devurandomfd = os.open("/dev/urandom",os.O_RDONLY)
 def randombytes(n): return try_read(devurandomfd,n)

 ### NaCl's crypto_sign / crypto_sign_open API sucks ###
@@ -154,7 +153,7 @@ if URCCRYPTOBOXDIR:
  for dst in os.listdir(URCCRYPTOBOXDIR):
   if URCCRYPTOBOXPFS and dst in os.listdir(URCCRYPTOBOXPFS):
    pk,sk=crypto_box_keypair()
-   urccryptoboxpfsdb[dst.lower()] = {'pubkey':pk,'seckey':sk,'tmpkey':randombytes(32)}
+   urccryptoboxpfsdb[dst.lower()] = {"pubkey":pk,"seckey":sk,"tmpkey":randombytes(32)}
    del pk, sk
   if URCCRYPTOBOXSECKEYDIR and dst in os.listdir(URCCRYPTOBOXSECKEYDIR):
    urccryptoboxdb[dst.lower()] = crypto_box_beforenm(
@@ -255,29 +254,29 @@ def sock_write(*argv): ### (buffer, dst, ...) ###
  dst = argv[1].lower() if len(argv) > 1 else str()

  if dst[-4:] == 'serv' and not dst[0] in ['#','&','!','+']:
-  try_write(wr,':'+dst+'!ERROR@'+serv+' NOTICE '+Nick+' :security: outgoing message blocked\n')
+  try_write(wr,":"+dst+"!ERROR@"+serv+" NOTICE "+Nick+" :security: outgoing message blocked\n")
   return

- if URCSIGNSECKEYDIR and dst and dst in urcsignseckeydb: signseckey = urcsignseckeydb[dst]
+ if URCSIGNSECKEYDIR and dst and dst in urcsignseckeydb.keys(): signseckey = urcsignseckeydb[dst]
  elif URCSIGNSECKEY: signseckey = URCSIGNSECKEY
  else: signseckey = str()

- if URCSECRETBOXDIR and dst and dst in urcsecretboxdb: seckey = urcsecretboxdb[dst]
+ if URCSECRETBOXDIR and dst and dst in urcsecretboxdb.keys(): seckey = urcsecretboxdb[dst]
  else: seckey = str()

- if URCCRYPTOBOXDIR and dst and dst in urccryptoboxdb: crypto_box_seckey = urccryptoboxdb[dst]
+ if URCCRYPTOBOXDIR and dst and dst in urccryptoboxdb.keys(): crypto_box_seckey = urccryptoboxdb[dst]
  else: crypto_box_seckey = str()

  ### URCCRYPTOBOX ###
  if crypto_box_seckey:
   buflen += 16 + padlen
   nonce = taia96n_pack(taia96n_now())+'\x04\x00\x00\x00'+randombytes(8)
-  if not dst in urccryptoboxpfsdb:
+  if not dst in urccryptoboxpfsdb.keys():
    buffer = chr(buflen>>8)+chr(buflen%256)+nonce+crypto_secretbox(buffer+randombytes(padlen),nonce,crypto_box_seckey)
   else:
    buflen += 32 + 16
-   buffer = chr(buflen>>8)+chr(buflen%256)+nonce+crypto_secretbox(urccryptoboxpfsdb[dst]['pubkey']+
-    crypto_box(buffer+randombytes(padlen),nonce,urccryptoboxpfsdb[dst]['tmpkey'],urccryptoboxpfsdb[dst]['seckey']),
+   buffer = chr(buflen>>8)+chr(buflen%256)+nonce+crypto_secretbox(urccryptoboxpfsdb[dst]["pubkey"]+
+    crypto_box(buffer+randombytes(padlen),nonce,urccryptoboxpfsdb[dst]["tmpkey"],urccryptoboxpfsdb[dst]["seckey"]),
     nonce,crypto_box_seckey
    )

@@ -322,11 +321,11 @@ while 1:
     if src in channel_struct[dst]['names']:
      try_write(wr,':'+Src[src]+'!URCD@'+Mask[src]+' QUIT :IDLE\n')
      break
-   for dst in channel_struct:
+   for dst in channel_struct.keys():
     if src in channel_struct[dst]['names']: channel_struct[dst]['names'].remove(src)
    del active_clients[src]
-   if src in Mask: del Mask[src]
-   if src in Src: del Src[src]
+   if src in Mask.keys(): del Mask[src]
+   if src in Src.keys(): del Src[src]
  del names

  if URCDB and now - sync >= TIMEOUT:
@@ -372,7 +371,7 @@ while 1:
     elif len(cmd) == 128: URCSIGNSECKEY = unhex(cmd)
     elif len(cmd) == 64 or len(cmd) == 192:
      URCCRYPTOBOXSECKEY,URCSIGNSECKEY = unhex(cmd[:64]),unhex(cmd[64:])
-     for dst in urccryptoboxpassdb:
+     for dst in urccryptoboxpassdb.keys():
       urccryptoboxdb[dst] = crypto_box_beforenm(urccryptoboxpassdb[dst],URCCRYPTOBOXSECKEY)
     else: try_write(wr,':'+serv+' 464 :ERR_PASSWDMISMATCH\n')
    except: try_write(wr,':'+serv+' 464 :ERR_PASSWDMISMATCH\n')
@@ -409,7 +408,7 @@ while 1:
     Nick, nick = src, src.lower()
     continue
    Src[nick], Mask[nick] = Nick, serv
-   for dst in channel_struct:
+   for dst in channel_struct.keys():
     if dst in channels:
      channel_struct[dst]['names'].remove(src.lower())
      if nick in channel_struct[dst]['names']:
@@ -466,11 +465,11 @@ while 1:
     dst, cmd, msg = re_SPLIT(buffer,4)[1:4]
     msg = crypto_hash_sha512(msg+dst.lower())[32:64] if not msg in ['x','?'] else str()
    except: dst, cmd, msg = re_SPLIT(buffer,2)[1],str(),str()
-   if cmd == '+k' and len(msg)==32 and dst.lower() in channels and len(urcsecretboxdb)<=CHANLIMIT:
+   if cmd == '+k' and len(msg)==32 and dst.lower() in channels and len(urcsecretboxdb.keys())<=CHANLIMIT:
     urcsecretboxdb[dst.lower()], URCSECRETBOXDIR = msg, 1
-   elif cmd =='-k' and dst.lower() in urcsecretboxdb:
+   elif cmd =='-k' and dst.lower() in urcsecretboxdb.keys():
     del urcsecretboxdb[dst.lower()]
-   if dst.lower() in urcsecretboxdb:
+   if dst.lower() in urcsecretboxdb.keys():
     try_write(wr,':'+serv+' 324 '+Nick+' '+dst+' +kn')
     try_write(wr,'\n') if URCDB else try_write(wr,'s\n')
    else: try_write(wr,':'+serv+' 324 '+Nick+' '+dst+' +n\n')
@@ -493,7 +492,7 @@ while 1:

   elif re_CLIENT_WHO(buffer):
    dst = re_SPLIT(buffer,2)[1].lower()
-   if dst in channel_struct:
+   if dst in channel_struct.keys():
     for src in channel_struct[dst]['names']:
      try_write(wr,':'+serv+' 352 '+Nick+' '+dst+' '+Src[src]+' '+Mask[src]+' '+Src[src]+' '+Src[src]+' H :0 '+Src[src]+'\n')
    try_write(wr,':'+serv+' 315 '+Nick+' '+dst+' :RPL_ENDOFWHO\n')
@@ -528,7 +527,10 @@ while 1:
     if msg and not msg in ['x','?']:
      URCSECRETBOXDIR = 1
      urcsecretboxdb[dst.lower()] = crypto_hash_sha512(msg+dst)[32:64]
-    if not dst in channel_struct: channel_struct[dst] = struct_channel
+    if not dst in channel_struct.keys(): channel_struct[dst] = dict(
+     names = collections.deque([],CHANLIMIT),
+     topic = None,
+    )
     elif nick in channel_struct[dst]['names']: channel_struct[dst]['names'].remove(nick)
     try_write(wr,
      ':'+Nick+'!'+user+'@'+serv+' JOIN :'+dst+'\n'
@@ -555,10 +557,10 @@ while 1:

   elif re_CLIENT_LIST(buffer):
    try_write(wr,':'+serv+' 321 '+Nick+' CHANNELS :USERS NAMES\n')
-   for dst in channel_struct:
+   for dst in channel_struct.keys():
     if channel_struct[dst]['names']:
      try_write(wr,':'+serv+' 322 '+Nick+' '+dst+' '+str(len(channel_struct[dst]['names'])))
-     if dst in urcsecretboxdb:
+     if dst in urcsecretboxdb.keys():
       if URCDB: try_write(wr,' :[+kn] ')
       else: try_write(wr,' :[+kns] ')
      else: try_write(wr,' :[+n] ')
@@ -577,7 +579,7 @@ while 1:

  while server_revents(0) and not client_revents(0):

-  AUTH, buffer = str(), try_read(sd,2+12+4+8+1024)
+  AUTH, buffer = "", try_read(sd,2+12+4+8+1024)
   if len(buffer)<2+12+4+8: continue

   ### Block Malicious /NICK *Serv attacks
@@ -592,8 +594,8 @@ while 1:
    except: src, cmd, dst = buffer[2+12+4+8+1:].split('!',1)[0].lower(), str(), str()

    if URCSIGNPUBKEYDIR \
-   and dst in urcsignpubkeydb \
-   and src in urcsignpubkeydb[dst]:
+   and dst in urcsignpubkeydb.keys() \
+   and src in urcsignpubkeydb[dst].keys():
     try:
      if _crypto_sign_open(buffer[:buflen-64],buffer[-64:],urcsignpubkeydb[dst][src]):
       buffer = re_USER('!VERIFIED@',buffer[2+12+4+8:].split('\n',1)[0],1)
@@ -610,7 +612,7 @@ while 1:
   ### URCSECRETBOX ###
   elif buffer[2+12:2+12+4] == '\x02\x00\x00\x00':
    if not URCSECRETBOXDIR: continue
-   for dst in urcsecretboxdb:
+   for dst in urcsecretboxdb.keys():
     msg = crypto_secretbox_open(buffer[2+12+4+8:],buffer[2:2+12+4+8],urcsecretboxdb[dst])
     if msg: break
    if not msg: continue
@@ -619,7 +621,7 @@ while 1:
   ### URCSIGNSECRETBOX ###
   elif buffer[2+12:2+12+4] == '\x03\x00\x00\x00':
    if not URCSECRETBOXDIR: continue
-   for dst in urcsecretboxdb:
+   for dst in urcsecretboxdb.keys():
     msg = crypto_secretbox_open(buffer[2+12+4+8:],buffer[2:2+12+4+8],urcsecretboxdb[dst])
     if msg: break
    if not msg: continue
@@ -632,8 +634,8 @@ while 1:
    except: src, cmd, dst = buffer[2+12+4+8+1:].split('!',1)[0].lower(), str(), str()

    if URCSIGNPUBKEYDIR \
-   and dst in urcsignpubkeydb \
-   and src in urcsignpubkeydb[dst]:
+   and dst in urcsignpubkeydb.keys() \
+   and src in urcsignpubkeydb[dst].keys():
     try:
      if _crypto_sign_open(buffer[:buflen-64],buffer[-64:],urcsignpubkeydb[dst][src]):
       buffer = re_USER('!VERIFIED@',buffer[2+12+4+8:].split('\n',1)[0],1)
@@ -650,13 +652,13 @@ while 1:
   ### URCCRYPTOBOX ###
   elif buffer[2+12:2+12+4] == '\x04\x00\x00\x00':
    if not URCCRYPTOBOXDIR: continue
-   for src in urccryptoboxdb:
+   for src in urccryptoboxdb.keys():
     msg = crypto_secretbox_open(buffer[2+12+4+8:],buffer[2:2+12+4+8],urccryptoboxdb[src])
     if msg: break
    if not msg: continue
-   if src in urccryptoboxpfsdb:
-     urccryptoboxpfsdb[src]['tmpkey'] = msg[:32]
-     msg = crypto_box_open(msg[32:],buffer[2:2+12+4+8],msg[:32],urccryptoboxpfsdb[src]['seckey'])
+   if src in urccryptoboxpfsdb.keys():
+     urccryptoboxpfsdb[src]["tmpkey"] = msg[:32]
+     msg = crypto_box_open(msg[32:],buffer[2:2+12+4+8],msg[:32],urccryptoboxpfsdb[src]["seckey"])
      if not msg:
        try_write(wr,':'+Src[src]+'!ERROR@'+Mask[src]+' NOTICE '+Nick+' :unable to decrypt message\n')
        continue
@@ -679,23 +681,26 @@ while 1:
   buffer += '\n'

   if re_SERVER_PRIVMSG_NOTICE_TOPIC_INVITE_PART(buffer):
-   src = buffer[1:].split('!',1)[0].lower()
+   src = buffer.split(':',2)[1].split('!',1)[0].lower()
    if len(src)>NICKLEN: continue
    active_clients[src] = now
-   Src[src] = buffer[1:].split('!',1)[0]
-   Mask[src] = buffer.split('@',1)[1].split(' ',1)[0]
+   Src[src] = buffer.split(':',2)[1].split('!',1)[0]
+   Mask[src] = buffer.split(':',2)[1].split('@',1)[1].split(' ',1)[0]
    cmd, dst = re_SPLIT(buffer.lower(),3)[1:3]
-   if dst in urcsecretboxdb and AUTH != dst: continue
+   if dst in urcsecretboxdb.keys() and AUTH != dst: continue
    if dst[0] in ['#','&','!','+']:
     if len(dst)>CHANNELLEN: continue
-    if not dst in channel_struct:
-     if len(channel_struct)>=CHANLIMIT:
-      for dst in channel_struct:
+    if not dst in channel_struct.keys():
+     if len(channel_struct.keys())>=CHANLIMIT:
+      for dst in channel_struct.keys():
        if not dst in channels:
         del channel_struct[dst]
         break
       dst = re_SPLIT(buffer,3)[2].lower()
-     channel_struct[dst] = struct_channel
+     channel_struct[dst] = dict(
+      names = collections.deque([],CHANLIMIT),
+      topic = None,
+     )
     if cmd == 'topic':
      msg = buffer.split(':',2)[2].split('\n',1)[0][:TOPICLEN]
      if not msg: continue
@@ -720,22 +725,25 @@ while 1:
    if dst == nick or dst in channels: try_write(wr,buffer)

   elif re_SERVER_JOIN(buffer):
-   src = buffer[1:].split('!',1)[0].lower()
+   src = buffer.split(':',2)[1].split('!',1)[0].lower()
    if len(src)>NICKLEN: continue
    active_clients[src] = now
-   Src[src] = buffer[1:].split('!',1)[0]
-   Mask[src] = buffer.split('@',1)[1].split(' ',1)[0]
-   dst = buffer.split(' :',1)[1].split('\n',1)[0].lower()
+   Src[src] = buffer.split(':',2)[1].split('!',1)[0]
+   Mask[src] = buffer.split(':',2)[1].split('@',1)[1].split(' ',1)[0]
+   dst = buffer.split(':')[2].split('\n',1)[0].lower()
    if len(dst)>CHANNELLEN: continue
-   if dst in urcsecretboxdb and AUTH != dst: continue
-   if not dst in channel_struct:
-    if len(channel_struct)>=CHANLIMIT:
-     for dst in channel_struct:
+   if dst in urcsecretboxdb.keys() and AUTH != dst: continue
+   if not dst in channel_struct.keys():
+    if len(channel_struct.keys())>=CHANLIMIT:
+     for dst in channel_struct.keys():
       if not dst in channels:
        del channel_struct[dst]
        break
-     dst = buffer.split(' :',1)[1].split('\n',1)[0].lower()
-    channel_struct[dst] = struct_channel
+     dst = buffer.split(':')[2].split('\n',1)[0].lower()
+    channel_struct[dst] = dict(
+     names = collections.deque([],CHANLIMIT),
+     topic = None,
+    )
    if src != nick and not src in channel_struct[dst]['names']:
     if dst in channels:
      try_write(wr,buffer)
@@ -748,35 +756,39 @@ while 1:
     channel_struct[dst]['names'].append(src)

   elif re_SERVER_QUIT(buffer):
-   src = buffer[1:].split('!',1)[0].lower()
+   src = buffer.split(':',2)[1].split('!',1)[0].lower()
    if src == nick or len(src)>NICKLEN: continue
    cmd = '\x01'
-   for dst in channel_struct:
+   for dst in channel_struct.keys():
     if src in channel_struct[dst]['names']:
      channel_struct[dst]['names'].remove(src)
      if cmd == '\x01' and dst in channels:
       try_write(wr,buffer)
       cmd = '\x00'
-   if src in active_clients: del active_clients[src]
-   if src in Mask: del Mask[src]
-   if src in Src: del Src[src]
+   if src in active_clients.keys():
+    del active_clients[src]
+    del Mask[src]
+    del Src[src]

   elif re_SERVER_KICK(buffer):
    cmd = buffer.split(':',2)[1].split('!',1)[0].lower()
    dst, src = re_SPLIT(buffer.lower(),4)[2:4]
    if len(cmd)>NICKLEN or len(src)>NICKLEN or len(dst)>CHANNELLEN: continue
    active_clients[cmd] = now
-   Src[src] = buffer[1:].split('!',1)[0]
-   Mask[src] = buffer.split('@',1)[1].split(' ',1)[0]
-   if dst in urcsecretboxdb and AUTH != dst: continue
-   if not dst in channel_struct:
-    if len(channel_struct)>=CHANLIMIT:
-     for dst in channel_struct:
+   Src[src] = buffer.split(':',2)[1].split('!',1)[0]
+   Mask[src] = buffer.split(':',2)[1].split('@',1)[1].split(' ',1)[0]
+   if dst in urcsecretboxdb.keys() and AUTH != dst: continue
+   if not dst in channel_struct.keys():
+    if len(channel_struct.keys())>=CHANLIMIT:
+     for dst in channel_struct.keys():
       if not dst in channels:
        del channel_struct[dst]
        break
      dst = re_SPLIT(buffer,3)[2].lower()
-    channel_struct[dst] = struct_channel
+    channel_struct[dst] = dict(
+     names = collections.deque([],CHANLIMIT),
+     topic = None,
+    )
    if src != nick:
     dst = re_SPLIT(buffer,3)[2].lower()
     if src in channel_struct[dst]['names']:

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 14:42:52 2024