1 Index: samba-3.0.24/source/Makefile
2 ===================================================================
3 --- samba-3.0.24.orig/source/Makefile 2008-08-07 15:56:45.000000000 +0200
4 +++ samba-3.0.24/source/Makefile 2008-08-07 15:56:45.000000000 +0200
7 MY_PASS_OBJ = libsmb/smbdes.o lib/md4.o lib/arc4.o
9 -bin/smbpasswd: utils/avm_smbpasswd.o $(MY_PASS_OBJ)
10 +bin/smbpasswd: utils/owrt_smbpasswd.o $(MY_PASS_OBJ)
12 - @$(CC) $(FLAGS) -o $@ utils/avm_smbpasswd.o $(MY_PASS_OBJ) \
13 + @$(CC) $(FLAGS) -o $@ utils/owrt_smbpasswd.o $(MY_PASS_OBJ) \
17 Index: samba-3.0.24/source/utils/owrt_smbpasswd.c
18 ===================================================================
19 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
20 +++ samba-3.0.24/source/utils/owrt_smbpasswd.c 2008-08-07 15:58:25.000000000 +0200
23 + * Copyright (C) John Crispin <blogic@openwrt.org>
25 + * This program is free software; you can redistribute it and/or modify it
26 + * under the terms of the GNU General Public License as published by the
27 + * Free Software Foundation; either version 2 of the License, or (at your
28 + * option) any later version.
30 + * This program is distributed in the hope that it will be useful, but WITHOUT
31 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
32 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
35 + * You should have received a copy of the GNU General Public License along with
36 + * this program; if not, write to the Free Software Foundation, Inc., 675
37 + * Mass Ave, Cambridge, MA 02139, USA. */
39 +#include "includes.h"
42 +void E_md4hash(const char *passwd, uchar p16[16])
45 + smb_ucs2_t wpwd[129];
48 + len = strlen(passwd);
49 + for (i = 0; i < len; i++) {
50 +#if __BYTE_ORDER == __LITTLE_ENDIAN
51 + wpwd[i] = (unsigned char)passwd[i];
53 + wpwd[i] = (unsigned char)passwd[i] << 8;
58 + len = len * sizeof(int16);
59 + mdfour(p16, (unsigned char *)wpwd, len);
63 +/* returns -1 if user is not present in /etc/passwd*/
64 +int find_uid_for_user(char *user)
67 + FILE *fp = fopen("/etc/passwd", "r");
72 + printf("failed to open /etc/passwd");
78 + if(fgets(t, 255, fp))
81 + p1 = strchr(t, ':');
82 + if(p1 && (p1 - t == strlen(user)) && (strncmp(t, user, strlen(user))) == 0)
84 + p1 = strchr(t, ':');
87 + p2 = strchr(++p1, ':');
90 + p1 = strchr(++p2, ':');
99 + printf("No valid user found in /etc/passwd\n");
107 +void insert_user_in_smbpasswd(char *user, char *line)
110 + FILE *fp = fopen("/etc/samba/smbpasswd", "r+");
114 + printf("failed to open /etc/samba/smbpasswd");
120 + if(fgets(t, 255, fp))
123 + p = strchr(t, ':');
124 + if(p && (p - t == strlen(user)) && (strncmp(t, user, strlen(user))) == 0)
126 + fseek(fp, -strlen(line), SEEK_CUR);
139 +void delete_user_from_smbpasswd(char *user)
142 + FILE *fp = fopen("/etc/samba/smbpasswd", "r+");
146 + printf("failed to open /etc/samba/smbpasswd");
152 + if(fgets(t, 255, fp))
155 + p = strchr(t, ':');
156 + if(p && (p - t == strlen(user)) && (strncmp(t, user, strlen(user))) == 0)
158 + fpos_t r_pos, w_pos;
160 + fgetpos(fp, &r_pos);
162 + w_pos.__pos -= strlen(t);
163 + while(fgets(t2, 256, fp))
165 + fsetpos(fp, &w_pos);
167 + r_pos.__pos += strlen(t2);
168 + w_pos.__pos += strlen(t2);
169 + fsetpos(fp, &r_pos);
171 + ftruncate(fileno(fp), w_pos.__pos);
182 +int main(int argc, char **argv)
185 + uchar new_nt_p16[NT_HASH_LEN];
187 + int smbpasswd_present;
188 + char smbpasswd_line[256];
193 + printf("usage for openwrt_smbpasswd - \n\t%s USERNAME PASSWD\n\t%s -del USERNAME\n", argv[0], argv[0]);
196 + if(strcmp(argv[1], "-del") == 0)
198 + printf("deleting user %s\n", argv[2]);
199 + delete_user_from_smbpasswd(argv[2]);
202 + uid = find_uid_for_user(argv[1]);
206 + E_md4hash(argv[2], new_nt_p16);
207 + s = smbpasswd_line;
208 + s += snprintf(s, 256 - (s - smbpasswd_line), "%s:%u:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:", argv[1], uid);
209 + for(g = 0; g < 16; g++)
210 + s += snprintf(s, 256 - (s - smbpasswd_line), "%02X", new_nt_p16[g]);
211 + snprintf(s, 256 - (s - smbpasswd_line), ":[U ]:LCT-00000001:\n");
213 + insert_user_in_smbpasswd(argv[1], smbpasswd_line);