LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2010, 01:39 PM   #1
don_wombat_73
Member
 
Registered: Sep 2005
Posts: 60

Rep: Reputation: 15
modify a username being returned to a radius server


I'm trying to compose a tcl script to read a username from our radius server, and modify if it matches a couple of conditions.

First off, here is a typical username that I would want to modify: 0900000023000003780a2202fc0000229f

This is a hex string returned from a dslam. The issue is that the last 8 characters of the string can change on a whim. So I can't use it for authentication data. However, character's 19 through 26 contain the IP address of the device. So 0a2202fc equals the IP address 10.34.2.252. I will have a list of all the devices I will need to compare against.

So here is my plan:

1) Read the username
2) If the length of the username equals 34, send it through an if/else loop
a) Read characters 19~26
b) Comapre them to a(n) external file/array that has 300+ objects - Need help here
c) If the value stored in the array matches the 8 digit hex string pulled from the 19~26 of the username being sent, truncated the last 8 characters
i.e. 0900000023000003780a2202fc0000229f will be modified to 0900000023000003780a2202fc
d) send the new username through
3) ELSE do nothing and send the username through as presented.

With my elementary knowledge of tcl, I got a start with this.

proc ProcessBASIP {request response environ} {
set username [ $request get User-Name ]

if { [ string length $username ] == 34} {
string equal
string trimright
# SETUP NEW USERNAME
$environ put User-Name $NEW_username
}
else {
$environ put User-Name $username
}

That's as far as I have gotten. I understand some computer languages, but regular expressions and tcl are a bit above me.

Any help you can give me would be appreciated.

Thanks,
Don

Last edited by don_wombat_73; 03-01-2010 at 01:41 PM.
 
Old 03-02-2010, 09:25 PM   #2
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
Does it have to be tcl?
I've been meaning to learn tcl for over a decade, but I've learned less than you.

But shell script is a different story. I think it could easily do what you want.

Here's something to look at.
Code:
#!/bin/sh
N=0900000023000003780a2202fc0000229f

if [ ${#N} = 34 ]; then
    printf "IP is %d.%d.%d.%d\n" 0x${N:18:2} 0x${N:20:2} \
                                 0x${N:22:2} 0x${N:24:2}
    IP=${N:18:8}

    # Assume the file is in the format: "IP name comment"

    while read FILE_IP FILE_NAME REMAINDER; do
        if [ $IP = "$FILE_IP" ]; then
            USERNAME="$FILE_NAME"
            break
        fi
    done < FILE.txt
else
    USERNAME="$N"
fi

echo "USERNAME is $USERNAME"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
RADIUS server ayush1440 Linux - Server 1 06-24-2008 12:14 PM
How To Modify Username KAOZ_IT Linux - Newbie 5 01-28-2007 08:36 PM
pppoe server+radius server configuration ye_adam Linux - Networking 2 01-12-2006 02:36 PM
what is a radius server barrythai Mandriva 3 03-03-2005 10:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration