Martin's Tex-Blog

Posts on programming and generally technical topics

Archive for the ‘Linux’ Category

Using private/public key for authentication in Putty

leave a comment »


If you want to make your life easier and no longer need to enter password, follow these steps:

1. Use PuttyGen to generate public/private keys and save them to local folder as my_key.ppk and my_key.pub.
2. Store my_key.ppk to ~\.ssh\authorized_keys2 file, remember to convert it to openssh format:
– remove two first lines and one last line
– add ssh-rsa followed with one space
3. In putty specify my_key.ppk in Connection->SSH->Auth setting
4. You might also need to:
$ chmod 600 ~/.ssh/authorized_keys2
$ chmod 700 ~/.ssh/
on server

You might also add my_key.ppk to Putty Pageant which will provide your key automatically to Putty.

Now if all is working ok, you might want to add your login username to Conenction->Data->Auto-login username editbox. No more username/login prompts.

This procedure is required by some other software like TortoiseGIT.

Advertisements

Written by Marcin

December 10, 2011 at 11:13 pm

Posted in Linux

Advanced serialization tips

leave a comment »


Seralization knowledge not fully covered by official training kit.  These are actually notes from CLR via C# chapter 24.

1. SoapFormatter as of .NET 3.5 is obsolete, for production code use XmlSerializer or DataContractSerializer.
2. Instances can be deep cloned using binary serialization, remember to set:
bin_formatter.Context = new StreamingContext(StreamingContextStates.Clone);
3. You can serialize multiple objects to single stream
4. If You serialize instances of objects which are located in custom loaded assemblies (using LoadFrom), then SerializationExceptin might be thrown. To load assembly when requested, implement delegate that matches System.ResolveEventHandler and register this method with System.AppDomain’s AssemblyResolve event just before deserialization and remove it after it.
5. If some of the objects in the graph are not serializable, then exception will be thrown. It is thrown not before serialization, it can happen any time during it. This can cause resulting stream to contain corrupt data. In order to fail gracefully, serialize to memory stream, and if all is ok, send it to network stream etc.
6. The SerializableAttribute custom attribute may be applied to reference types (class), value types (struct), enumerated types (enum), and delegate types (delegate) only. But since enumerated types and delegates are serializable by default, it makes no sense to add this attribute to them.
7. Serializable attribute is not being inherited, if super class is non serializable then subclasses are not either.
8. Do not set Serializable to automatically generated properties, their names can change during compilation, making it not possible to deserialize.
9. Formatters makes use of FormatterServices class for serialization and deserialization, steps are as follows:

Serialization:
– Call FormatterServices.GetSerializableMembers to get MemberInfo[].
– Then call FormatterServices.GetObjectData to get array of values for each MemberInfo instance in the above array.
– Store assembly identity and type’s full name.
– Store each member, their type, name and value.

Deserialization:
– Load assembly identity information and if required load it. Call FormatterServices.GetTypeFromAssembly. This call returns System.Type that represents object to be deserialized.
– Call FormatterServices.GetUninitializedObject with previously returned System.Type, this returns an non-constructed object, with fields set to zero values.
– Now call FormatterServices.GetSerializableMembers to get MemberInfo[]. Those members will need to be deserialized.
– Formatter creates object data from the stream, those will be values of our members.
– With all prepared data call FormatterServices.PopulateObjectMembers, it requires reference to object, MemberInfo[] and Object[] – with values (deserialized in step above).

10. Implementation of ISerializable interface (to get freedom of how serialization happens and get rid of slow reflection), requires implementing its methods in each subclass, and also calling in them, super class versions.
11. Always add followng attribute to your ISerializable.GetObjectdata: [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]. This will prevent outside code from using this method in some malicious ways.
12. When using SerializationInfo class in c-tor, you should call the same Get* methods types as in ISerializable.GetObjectData. If there is a mismatch when deserializing given data, framework will try to convert it with IFormatterConverter, which internally calls System.Convert for core types. For other types it uses type’s IConvertible implementation.
13. SerializationInfo also provides enumerator, which returns SerializationEntry instances.
14. To custom serialize class which base type does not implement ISerializable, use this.GetType().BaseType, and serialize/deserialize it manually. This might be not possible with private fields.
15. Serializing a Type as a different Type, and Deserializing as a different object. This is of use when using singletons, DBNull object. For serialization:
– Add to ISerialization.GetObjectData, SerializationInfo.SetType() method call. As a parameter specify type of custom class that derives from IObjectReference.
16. Serialization surrogates: this is a technique that allows to serialize types not designed for serialization, to deserialize type to a new version, etc.. It is realized by createing class that implements ISerializationSurrogate interface. Its methods GetObjectData and SetObjectData are used for serialization and deserialization. In orderd to let Formatter know about our serializing surrogate implementation, create and initilize SurrogateSelector class and set it to Formatters SurrogateSelector property.
17. The BinaryFormatter class has a bug that prevents a surrogate from serializing objects with references to each other. For fix look into CLR Via C#.
18. Finally there is a technique to deserialize data to a different object than the one used during serialization. This is of use when new version of type is created, or type is moved to other assembly, client want to deserialize data from server to different local type. To use it implement SerializationBinder abstract class, and set it to Formatter’s Binder property.

Below are notes from other sources:

19. ObjectManager tracks deserialized objects. Formatter uses it to check if given reference is backward reference – its object was already deserialized, or it is forward reference – instance was not yet deserialized – this requires recording fixup with ObjectManager. Fixup means that reference will be assigned correct object in the future when actual object will get deserialized.
20. Marshaling is the process of packaging and sending remote procedure calls across process and application boundaries using serialization and deserialization.

Written by Marcin

March 27, 2011 at 4:50 pm

Posted in Linux, MCTS 70-536

Tagged with

putty and Ctrl + s that blocks screen

leave a comment »


When you press Ctrl + s under putty, then your linux session will freeze and screen will not update. In my case I mostly had to restart my session which was quite annoying even though I use screen. Quicker solution is to press Ctrl + q. This is what many websites/blogs will tell you.

I am writing it here just to remind me of it, since I constantly forget that trick.

Written by Marcin

December 9, 2010 at 11:05 pm

Posted in Linux, Uncategorized

Configure firefox to use proxy using ssh

leave a comment »


If you own some remote server access over ssh, then you can easily tunell all your http request over it. Under linux ssh tool is available by default, under windows its best to install Cygwin with ssh. After that all you have to do is issue following command:

$ ssh -ND localhost:8080 $USER@$REMOTE_SERVER

where localhost:8080 means that ssh will bind to localhost on port 8080, $USER is the name of your user account on remote server $REMOTE_SERVER.

after that you need to configure firefox to. Under firefox : enter Tools->Options->Advanced->Network->Settings, choose manual configuration and fill “Host Socks” with localhost:8080.

and thats all

Written by Marcin

November 18, 2009 at 7:40 am

Posted in Linux

Compiling synergy on OpenSuse 11.1 x64 with gcc 4.3.2

leave a comment »


Here are some hints on how to make synergy work on OpenSuse 11.1.

1. Fix bugs in code that originate from using gcc version 4.3.2, this were all because of missing header files, like cstdlib, memory, string.h. These are no longer being auto added by other general headers and must be added manually.

2. Later on I had to disable compiler errors on warnings. Otherwise I would have to make more code fixes, these is probably also caused by newer version of gcc than the one used by synergy developers.

3. Step 2 – required changes in configure.in, which resulted in errors with autoconf and automake. I was missing aclocal-1.6 and automake-1.6, but I did have newer versions aclocal-1.10 and automake-1.10, so the simple solution was to symlink new binary file names to older file names.

after that synergyc compiled properly, and did properly connect to my synergy server located on windows box.

Written by Marcin

September 27, 2009 at 6:27 pm

Posted in Linux

How do you use your linux box?

leave a comment »


By that I meant whether you use it normally as a separate operating system on your hard disk, or maybe use it in some fancy way. I would like to describe here how I set up my linux work environment. My main work is under windows os and this wont change in some time, and I really don’t like reseting computer to switch to linux box working in dual boot. The solution was to use VMWare Player with Ubuntu image, I quickly stopped using VMWare window which is from my perspective not user friendly, and installed No Machine client, whose window seamlessly integrates with Windows GUI. Now I can do my programming on linux and windows at the same time. There are still some problems with Samba and accessing windows folders, but I hope to fix it soon.

Written by Marcin

July 7, 2009 at 6:35 am

Posted in Linux

Experiences with update from OpenSuse 11 to 11.1 (x86_64)

leave a comment »


Update went without any problems, following problems appeared later on:

1. After first reboot system hang at “Starting Service Jexec”. Recomended solution is to disable this service, to do it you can use your DVD disk and enter “Recovery System” from its start menu, then mount linux partition to be able to enter yast, in my case it was:

mount /dev/sda1 /mnt
mount -o bind /proc /mnt/proc
mount -o bind /sys /mnt/sys
mount -o bind /dev /mnt/dev
chroot /mnt

to find your partition use:

fdisk -l

after that disable jexec in yast : System->System Services->System Services (Runlevel)

2. Later on I could not enter Kde (3.5), the problem was that ATI drivers needed to be reinstalled for new kernel – that was expected. To be able to enter Kde, enter sax2 in shell, this will reset your driver. Then when in Kde you can navigate to Ati website for new driver.

3. Installation of new drivers ( ATI ).

yast2 -i kernel-source make gcc libgcc
wget https://a248.e.akamai.net/f/674/9206/0/www2.ati.com/drivers/linux/64bit/ati-driver-installer-9-1-x86.x86_64.run
sh ati-driver-installer-9-1-x86.x86_64.run
shutdown -r now

that was for ATI Mobility Radeon HD 3400 Series for x86_64 architecture. Funny thing is that on ATI website I had to choose non-mobile category, at first I thought I am installing wrong driver for desktop PC.

After reboot it works great, I even have hi resolution view at system startup (after grub), this didn’t work with previous kernel/ATI driver. But I will have to use vga=0 in grub config as I explain in 4 ­čśŽ

4. Suspend to disk works properly, resume from disk – does not. There seems to be problems with display driver at startup – right after grub. I was able to properly resume only after entering vga=0 in grub config.

Written by Marcin

February 17, 2009 at 6:57 am

Posted in Linux