File: ssh_create.pl

package info (click to toggle)
gforge 3.1-31sarge5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,148 kB
  • ctags: 11,865
  • sloc: sql: 27,860; php: 25,574; perl: 7,124; xml: 3,152; sh: 2,586; ansic: 315; makefile: 143
file content (42 lines) | stat: -rwxr-xr-x 1,093 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl
#
# $Id: ssh_create.pl,v 1.3 2002/12/23 13:17:14 lo-lan-do Exp $
#
# ssh_create.pl - Dumps SSH authorized_keys into users homedirs on the cvs server.
#

require("/usr/lib/gforge/lib/include.pl");  # Include all the predefined functions and variables

my @ssh_key_file = open_array_file($file_dir."dumps/ssh_dump");
my ($username, $ssh_keys, $ssh_dir);

#print("\n\n	Processing Users\n\n");
while ($ln = pop(@ssh_key_file)) {
	chop($ln);

	($username, $uid, $ssh_key) = split(":", $ln);

	$ssh_key =~ s/\#\#\#/\n/g;
	$username =~ tr/[A-Z]/[a-z]/;
	$uid += $uid_add;

	push @user_authorized_keys, $ssh_key . "\n";

	$ssh_dir = "$homedir_prefix$username/.ssh";

	if (! -d $ssh_dir) {
		mkdir $ssh_dir, 0755;
	}

	#print("Writing authorized_keys for $username: ");

	write_array_file("$ssh_dir/authorized_keys", @user_authorized_keys);
	system("chown $uid:$uid $homedir_prefix$username");
	system("chown $uid:$uid $ssh_dir");
	system("chmod 0644 $ssh_dir/authorized_keys");
	system("chown $uid:$uid $ssh_dir/authorized_keys");

	#print ("Done\n");

	undef @user_authorized_keys;
}