openssl and coreutils and more

Osor Hirutonis osor at case.edu
Tue Dec 5 08:43:58 PST 2006


Robert Connolly wrote:
> Is this correct?:

It works.

> $ cat nologin.S
> .section .data
> message:
>    .ascii "This account is currently not available.\n\0"
> .section .text
> .globl _start
> _start:
>    movl $4, %eax
>    movl $42, %edx
>    movl $message, %ecx
>    movl $1, %ebx
>    int $0x80
>    movl $1, %eax
>    movl $1, %ebx
>    int $0x80
> 
> $ as -o nologin.o nologin.S
> $ ld -o nologin nologin.o
> $ ./nologin ; echo $?
> This account is currently not available.
> 1

A few suggestions:
1.) You don’t need the null byte at the end of message (because the last
    argument of write() is how many bytes to be written — it doesn’t
    care about null-terminated strings).
2.) Though it might increase the size a smidgen, you might not want to
    hardcode the string size into the program (instead, add a symbol
    len that is the length of the string. E.g.,

message:
    .ascii "This account is currently not available.\n"
    len = . - message

    And then use $len in place of $42.
3.) You are writing an error message to stdout. Why not change that to
    stderr (I do know everyone else also writes to stdout, but why?)?
4.) The “real” nologin (from shadow) will write to syslog. That’s
    helpful (at least to me) from a sysadmin standpoint.

P.S.
Just for fun, here’s one for x86-64 assembler:

.section .data
message:
   .ascii "This account is currently not available.\n"
   len = . - message
.section .text
.globl _start
_start:
   movq $len, %rdx
   movq $message, %rsi
#  movq $2, %rdi
   movq $1, %rdi
   movq $1, %rax
   syscall

   movq $1, %rdi
   movq $60,%rax
   syscall



More information about the hlfs-dev mailing list