Commit e77d36c3 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

crit: Beautify unix names recode

Unix socket name can be a string with any bytes in it. So to
print the name we use base64 encoding. Doing so doesn't allow
to see the socket name when it contains only printable chars.

So here's the custom encoding for bytes fields, that can be
used for custom conversion.
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 5e3509ba
...@@ -9,6 +9,7 @@ message CRIU_Opts { ...@@ -9,6 +9,7 @@ message CRIU_Opts {
optional bool dev = 4; // Device major:minor packed optional bool dev = 4; // Device major:minor packed
optional bool odev = 5; // ... in old format optional bool odev = 5; // ... in old format
optional string dict = 6; optional string dict = 6;
optional string conv = 7;
} }
extend google.protobuf.FieldOptions { extend google.protobuf.FieldOptions {
......
...@@ -37,7 +37,7 @@ message unix_sk_entry { ...@@ -37,7 +37,7 @@ message unix_sk_entry {
* Abstract name may contain \0 at any point, * Abstract name may contain \0 at any point,
* so we need to carry it as byte sequence... * so we need to carry it as byte sequence...
*/ */
required bytes name = 11; required bytes name = 11 [(criu).conv = "unix_name"];
optional sk_shutdown shutdown = 12; optional sk_shutdown shutdown = 12;
......
...@@ -60,6 +60,9 @@ def _marked_as_odev(field): ...@@ -60,6 +60,9 @@ def _marked_as_odev(field):
def _marked_as_dict(field): def _marked_as_dict(field):
return field.GetOptions().Extensions[opts_pb2.criu].dict return field.GetOptions().Extensions[opts_pb2.criu].dict
def _custom_conv(field):
return field.GetOptions().Extensions[opts_pb2.criu].conv
mmap_prot_map = [ mmap_prot_map = [
('PROT_READ', 0x1), ('PROT_READ', 0x1),
('PROT_WRITE', 0x2), ('PROT_WRITE', 0x2),
...@@ -157,6 +160,33 @@ def encode_dev(field, value): ...@@ -157,6 +160,33 @@ def encode_dev(field, value):
else: else:
return dev[0] << kern_minorbits | dev[1] return dev[0] << kern_minorbits | dev[1]
def encode_base64(value):
return value.encode('base64')
def decode_base64(value):
return value.decode('base64')
def encode_unix(value):
return value.encode('quopri')
def decode_unix(value):
return value.decode('quopri')
encode = { 'unix_name': encode_unix }
decode = { 'unix_name': decode_unix }
def get_bytes_enc(field):
c = _custom_conv(field)
if c:
return encode[c]
else:
return encode_base64
def get_bytes_dec(field):
c = _custom_conv(field)
if c:
return decode[c]
else:
return decode_base64
def is_string(value): def is_string(value):
return isinstance(value, unicode) or isinstance(value, str) return isinstance(value, unicode) or isinstance(value, str)
...@@ -167,7 +197,7 @@ def _pb2dict_cast(field, value, pretty = False, is_hex = False): ...@@ -167,7 +197,7 @@ def _pb2dict_cast(field, value, pretty = False, is_hex = False):
if field.type == FD.TYPE_MESSAGE: if field.type == FD.TYPE_MESSAGE:
return pb2dict(value, pretty, is_hex) return pb2dict(value, pretty, is_hex)
elif field.type == FD.TYPE_BYTES: elif field.type == FD.TYPE_BYTES:
return value.encode('base64') return get_bytes_enc(field)(value)
elif field.type == FD.TYPE_ENUM: elif field.type == FD.TYPE_ENUM:
return field.enum_type.values_by_number.get(value, None).name return field.enum_type.values_by_number.get(value, None).name
elif field.type in _basic_cast: elif field.type in _basic_cast:
...@@ -233,7 +263,7 @@ def _dict2pb_cast(field, value): ...@@ -233,7 +263,7 @@ def _dict2pb_cast(field, value):
# and non-repeated messages need special treatment # and non-repeated messages need special treatment
# in this case, and are hadled separately. # in this case, and are hadled separately.
if field.type == FD.TYPE_BYTES: if field.type == FD.TYPE_BYTES:
return value.decode('base64') return get_bytes_dec(field)(value)
elif field.type == FD.TYPE_ENUM: elif field.type == FD.TYPE_ENUM:
return field.enum_type.values_by_name.get(value, None).number return field.enum_type.values_by_name.get(value, None).number
elif field.type in _basic_cast: elif field.type in _basic_cast:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment