Wednesday, August 26, 2009

Modifying the boot loader in Vista

I miss boot.ini. Why isn't there a GUI version of bcdedit?

I could run bcdedit, but I could not read the boot loader store without admin permission. I found a useful link that had the secret to running cmd with admin permission: type cmd in the search window in the start menu and hit CTRL-SHIFT-ENTER. So obvious.

bcdedit /? will show all the options.

bcdedit /v will show all the boot choices, including the annoying ID.

bcdedit /delete ID /cleanup will delete a choice from the list, as long as you get the ID correct.

If the partition has already been deleted, then this will not work!!!

bcdedit /deletevalue ID type will remove the entry, if you know the type.

bcdedit /? /TYPES will tell you more about the types.

bcdedit /deletevalue ID DESCRIPTION desc should remove the entry, but it doesn't, of course.

The problem that I have is that I have already deleted the Windows 7 partition, so none of the commands work. If I use the current OS, then they work. For instance,

bcdedit /set description "Vista Sucks"

works beautifully. I can even use the ID as

bcdedit /set ID description "Vista Really Sucks"

According to several posts, the /delete command should work but it doesn't.

The solution was to download easybcd

Wednesday, June 24, 2009

Fedora 11 Installing Samba

yum install samba
version 3.3.2-0.33.fc11

cd /etc/samba
mv smb.conf smb.conf.backup
vi smb.conf
[global]
workgroup = wrkgrp
netbios name = smbserver
security = SHARE
load printers = No
default service = global
path = /home
available = No
encrypt passwords = yes
[share]
writeable = yes
admin users = smbuser
path = /home/share
force user = root
valid users = smbuser
public = yes
available = yes

save and exit

add user smbuser to local and smb
useradd smbuser
passwd smbuser
smbpasswd -a smbuser

/etc/init.d/smb restart

new use z: \\ip\share passwd username

I could not connect from Windows.

I changed security to user: it still didn't work.

I am now reading an online Samba book.
http://us1.samba.org/samba/docs/man/Samba-HOWTO-Collection/


testparm is a command that will test the configuration of the samba conf file.
testparm /etc/samba/smb.conf

The file passes the test.

Optimize the file and strip all comments with
testparm -s source dest

SWAT is a web-based config tool. I will look into that after I get the conf file working.

Display all shares that are defined on a host:
smbclient -L hostname

This asks for a password for the current user. Even if I am logged in as the smb user, I am unable to connect.

Do an anonymous login by addeng -N to the command. I am able to see the share that I created.

Connect to home dir:
smbclient //host/user
This also requires password and fails.

/etc/sysconfig/network contains nameservers and hostname.
Where is the alias for eth0 and wlan0 defined? There is no /etc/modprobe.conf

Name resolution of DHCP addresses needs to be hardcoded, which defeats DHCP. I found a link,
http://www.cameratim.com/computing/linux/using-bind-as-a-local-dns-server, that indicates how to get around this. I will investigate later; for now I am hardcoding the DHCP address.

I failed to start nmb. Both the nmb and smb services must be running.
service smb start
service nmb start

Test if all the appropriate services are running (from http://troy.jdmz.net/samba/fw/):
# service smb stop
# netstat -ln > netstat-ln-smb.before
# service smb start
# netstat -ln > netstat-ln-smb.after
# diff netstat-ln-smb.*

Open firewall for udp and tcp in the /etc/sysconfig/iptables file:
-A INPUT -p udp -m udp --dport 137 -j ACCEPT
-A INPUT -p udp -m udp --dport 138 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT

Then restart the firewall
service iptables restart

The smbserver is now visible from the Window machine. I am still unable to connect to a share.

Tried a simple config from http://us6.samba.org/samba/docs/man/Samba-Guide/simple.html#draft-smbconf
[global]
workgroup = MIDEARTH
security = SHARE

[Plans]
path = /plans
read only = Yes
guest ok = Yes

When I tried smbclient -L server -Uroot%passwd, I got an error about LANMAN authorization. I fixed it by adding the following to the global section of the conf file and restarted smb:
client lanman auth = Yes
lanman auth = Yes

I can now see the server and the share (though I changed the name of the workgroup, but windows still sees the old one); however, when I try to access the share, my Linux security warns me that someone is trying to access my home directory. I placed the share in my home directory, so the error is correct. I will move the share. I just noticed that on Linux, the new workgroup name is not recognized, either.

I seem to being editing the wrong smb.conf file. The changes that I am making are not being implemented. I am editing /etc/samba/smb.conf ... No, I am editing the correct file, but the workgroup command in the global section is changing the domain, but not the workgroup.

I tried following the advice of the AVC warning: setsebool -P samba_enable_home_dirs=1, it did not resolve the problem.

I am still getting the home dir error; eventhough I moved the directory to the root. I will try moving it to /tmp ... Did not work.

I have added the following share
[homes]
browseable = ok
guest ok = yes


I can now access homes, but it opens my root directory.

I am able to mount a windows share with
mount.cifs //ip/path /mnt
It asks for a password.

I found a page on printing from linux to a windows printer: http://www.math.colostate.edu/~reinholz/freebsd/smb_print_client.html

In the original smb.conf, there are comments about SELinux for home directories and domains.
setsebool -P samba-domain-controller on
setsebool -P samba-enable-home-dirs on

There is also a comment about setting samba-share-t for new directories, for allowing SELinux to write to a dir.

Use the command ls -ldZ to see the context for a directory.

I used the original smb.conf file and I can access home directories.

Installing Fedora 11 on Eee PC

Fedora is using anaconda 11.5.0.59 as its installer.

Graphical screen with fedora logo: click Next.
Select Language: Next
Select Keyboard: Next
Finding storage devices ...
Name this computer - Hostname: eeepc: Next
Map of globe; select city in time zone: America/NY: next (check box for System clock uses UTC: checked)
root password: Next
Partition drives: sda and sdb; sda contains /boot: Next
Write changes to disk
Failed! Could not mount /boot

Restarted
...
Write changes to disk
Installation packages: Office and Productivity; Installation repo; Customize later:Next
Checking Dependencies
Starting Install
Installing 1091 packages

Congratulations. Reboot and install updates.

Additional configuration: Forward
License info: Forward
Create user (can set up network login here): Forward
Set date: Forward
SMOLT is hardware profiler; send profile: Finish

Thursday, May 28, 2009

JSP include tag versus include directive

The first thing to note is that if either of these directives fails, then the page stops loading.

The directive will accept a relative path from the current location; the tag must have a path that starts with /, which is the root of the web application, not the root of the server.

The difference between the two is how they handle dynamic content. The tag includes the output of the dynamic reference in the page at runtime; the directive includes the contents of the dynamic reference when the including JSP is compiled into a servlet.

I am hard pressed to devise an example using JSPS that has different output for the tag and the directive. The directive can only include actual files, so the directive is useless if CGI or PHP files are to be included.

If the tag includes a reference to a servlet, be sure that the servlet does not close the output stream. This is a problem for a servlet that forwards to a JSP, since the output stream is closed after the forward is complete.

Both by-pass the security constraints in the web.xml file. Both can access WEB-INF, directly.

Both can only include resources that are in the web application.



I just read on another site that the difference is when they are loaded.

The tag loads at runtime.

<jsp:include page="includedPage" /> 

The directive loads at compile time.

<%@ include file="banner.jsp" %> 

From http://stackoverflow.com/questions/9188478/how-to-implement-a-include-jsp-tag

Friday, May 22, 2009

Connecting with JDBC to SQL Server

My tale of woe that has a happy ending.

I wanted to connect to SQL Server 2005 using JDBC. I verified the connection string and used standard code to test the connection.

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=Northwind;user=x;password=x;";
Connection con = DriverManager.getConnection(connectionUrl);
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.toString());
} catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: " + cE.toString());
}
When I ran the code, I received this error
com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
WARNING: ConnectionID:1 Prelogin error: host localhost port 1433 Unexpected response status:0
Actually, I received that error multiple times and eventually received a stack trace of

SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "The driver received an unexpected pre-login response. Verify the connection properties and check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. This driver can be used only with SQL Server 2000 or later.

I then checked many sites for this message, but none had the exact message.

I tried logging into SQL Server directly, using the SQL Server Management Express program. I was able to log in with my user account, but could not access the Northwind or pubs databases. I conferred with some colleagues and needed to set the server with mixed access: Windows and SQL. There was an old account that I had created, named sa. I reactivated it and changed its password. I logged on with it and then updated my Windows login account with sysadmin rights. After this, I was able to connect to the Northwind and pubs databases; however, I still received the original error when I tried to connect to the database using JDBC.

After more searching, I found the Code Ranch site which talked about removing dynamic ports and setting a static port in the SQL Server Configuration Manager. I tried to follow the instructions, but my server would not restart with a static port of 1433. I then tried to access the server from JDBC using the dynamic port and was able to connect.

Next, I tried to connect to the database using Hibernate. I used the JDBC driver from microsoft, the package for the driver is com.microsoft.sqlserver.jdbc.SQLServerDriver. The Hibernate dialect for SQL Server is org.hibernate.dialect.SQLServerDialect. I was unable to connect. I used the same URL as I used when connecting with Java, jdbc:sqlserver://localhost:3346/Northwind. The dynamic port is 3346, the name of the database is Northwind.

There was a helpful post about clients and servers that guided me to the SQL Server Configuration Manager again. This time, I started to understand what I was seeing. There is the SQL server and the SQL client. The client was using port 1433, the server was using port 3346. I changed the client to 3346, but I still had an error.

The error was an SSL error. I found a helpful link about certificates, but I was unclear about exporting my certificates and lost them. Since this link referred to installing SQL Server after deleting the certificates, I am downloading Server 2008. I am hoping that a new installation will miraculously have no problems!

The referring page also had some information about not installing the old certificates, but creating a new one. I am investigating. It refers to a program named SelfSSL.exe.

I did not pursue the creation of a certificate, since the reference was for IIS. I did complete the new installation of SQL Server 2008. I am able to access sqlcmd from the command line and am able to connect to the server from Java. I did not have to tweak any parameters, both the client and the server were using 1433 and TCP/IP was enabled.

I did have one confusion, that may have been the basis of a lot of my problems: I didn't know what a schema was in SQL Server. According to MicroSoft, a schema is like a namespace for tables that can be accessed. If you don't have the correct schema, then you can't see all the tables. The default schema is dbo. Once I changed all my tables to that schema, I was able to connect and see them in NetBeans database services.

I still could not connect using Hibernate. I decided to reinstall MySQL, since I was missing the GUI admin app. After installing, I followed an excellent tutorial on using MySQL in NetBeans. I also found an excellent tutorial for using NetBeans to reverse engineer tables to create POJOs. Once I had these tutorials running, I tackled SQL Server 2008.

I modified the process from the tutorial to create the POJO for two tables from the Northwind database. I found an excellent tutorial for installing Northwind and pubs databases, which for some reason are not included in the install of SQL Server. Once I had the table, I changed the database to the SQL Server instead of MySQL. I have included the important properties below.
   <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;databaseName=mydb</property>
<property name="hibernate.connection.username">name</property>
<property name="hibernate.connection.password">pass</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
The only difference that I could see from what I had used before was the current session context class; however, in my last iteration of testing before the reinstall, I omitted the dialect. That was probably the big error.

It finally works. In review, I had a problem with SQL Server 2005 that I never resolved; the new installation works without a hitch; I probably had a problem with schemas in the 2005 tests.
 

Sunday, May 3, 2009

Enabling SSI in Apache Tomcat 6.0

I used the filter option for SSI in Tomcat 5.5. When I upgraded to Tomcat 6.0, I had to use the servlet option. When I used the filter option I received the error

SEVERE: Error filterStart

The web.xml file that I used had a comment about renaming a Jar file; however, it seems that the comment is left over from 5.5. There is no such Jar file in 6.0. The comment was also missing the instruction to uncomment the servlet mapping for the ssi servlet.

In summary, follow these steps to enable SSI in Tomcat 6.0

  1. Use the servlet, not the filter.
  2. Uncomment the servlet definition and servlet mapping for the ssi servlet in web.xml.
  3. Mark the context as privileged.

Tuesday, March 3, 2009

Serialization

There are several ways to implement serialization in .NET. The simplest way is to mark the class as Serializable and then to create a formatter to do the serialization. Fields that are not serializable can be marked as such and will not be serialized.
[Serializable]
public class SomeClass {
//mark members that are not serializable
[NonSerialized] SomeNoneSerializedType t;
}
The formatter can be created in any class that needs to serialize the above class.
public void SomeSaveHandler(Object sender, EventArgs e) {

using (SaveFileDialog dlg = new SaveFileDialog())
{
if (dlg.ShowDialog() != DialogResult.OK) return;
using (Stream stream =
new FileStream(dlg.FileName, FileMode.Create, FileAccess.Write))
{
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, instanceSomeClass);
}
}
}
Deserialization is similar.
public void SomeOpenHandler(Object sender, EventArgs e) {

using (OpenFileDialog dlg = new OpenFileDialog())
{
if (dlg.ShowDialog() != DialogResult.OK) return;
using (Stream stream =
new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read))
{
IFormatter formatter = new BinaryFormatter();
SomeClass someClass = (SomeClass) formatter.Deserialize(stream);
}
}
}
More than one object can be serialized by having additional calls to serialize; one for each object. During deserialization, make a corresponding call to deserialize for each object that was serialized; use the same order when deserializing as was used when serializing.

For elements that are calculated fields, they can be recalculated after the object has been deserialized, by implementing the IDeserializationCallback interface. Define the callback method OnDeserialization to instantiate any calculated fields. The parameter to this method is not implemented at this time, so it is always null.
[Serializable]
public class SomeClass: IDerializationCallback {
//mark members that are not serializable
[NonSerialized] SomeNoneSerializedType t;

public void OnDeserialization(object sender) {
t = SomeCalculation();
}
}


The other method to serialize takes a different approach. Instead of assuming that everything is serializable, it assumes that nothing is serializable. Instead of indicating what should not be serialized, the class must specifically serialize each element. This technique is implemented in the interface ISerializable. Define the method GetObjectData and define a constructor that will be used during deserialization.
[Serializable]
public class SomeClass : ISerializable {
SomeType t;
SomeNoneSerializedType non;

public SomeClass(
SerializationInfo info, StreamingContext context)
{
t = (SomeType) info.GetValue("myType", typeof(SomeType));
non = SomeCalculation();
}

public void GetObjectData(
SerializationInfo info, StreamingContext context)
{
info.AddValue("myType", t);
}
}
Call info.AddValue for every member that needs to be serialized. Call info.GetValue for every member that needs to be deserialized.

There is no need for the deserialization callback interface, since calculated fields can be instantiated in the deserialization constructor.

This technique is useful for classes that extend a non-serializable class. The first technique will fail, if the base class cannot be serialized. By using the second technique and specifically serializing each element, the base class does not need to be serializable. The trick in this case is to make sure that any other constructors also get called when the deserialization constructor is called.

For the class that has to serialize this class, there is no difference when creating a formatter for either of these techniques. The calling class just calls serialize and deserialize on the formatter, it is up to the serializable class to determine how it will serialize.



It is possible to add methods to a class that will serialize/deserialize the class by creating a formatter. This encapsulates the entire process of serializing the class so that the class that is doing the serialization will not have to implement the details for creating the formatter.

The second technique is the preferred technique for implementing such methods. While the first technique could be used, its simplicity is lost, since it is not possible to deserialize into this. In order to make the first technique work from a method in the class, it would be necessary to deserialize into another class and then copy member by member into the current class. Another possible implementation would be to serialize/deserialize member by member.

More Blogs

Followers