Fossil SCM
Optional extra arguments to the "user" command allow one to specify the new password or contact information on the command-line without waiting for a prompt. This makes the "user" command usable from shell-scripts.
Commit
f6c0201af702efa125900c7da6c575ec5a73e6ed
Parent
e146d800ac37390…
1 file changed
+21
-10
+21
-10
| --- src/user.c | ||
| +++ src/user.c | ||
| @@ -165,17 +165,17 @@ | ||
| 165 | 165 | ** |
| 166 | 166 | ** %fossil user list |
| 167 | 167 | ** |
| 168 | 168 | ** List all users known to the repository |
| 169 | 169 | ** |
| 170 | -** %fossil user new ?USERNAME? | |
| 170 | +** %fossil user new ?USERNAME? ?CONTACT-INFO? ?PASSWORD? | |
| 171 | 171 | ** |
| 172 | 172 | ** Create a new user in the repository. Users can never be |
| 173 | 173 | ** deleted. They can be denied all access but they must continue |
| 174 | 174 | ** to exist in the database. |
| 175 | 175 | ** |
| 176 | -** %fossil user password USERNAME | |
| 176 | +** %fossil user password USERNAME ?PASSWORD? | |
| 177 | 177 | ** |
| 178 | 178 | ** Change the web access password for a user. |
| 179 | 179 | */ |
| 180 | 180 | void user_cmd(void){ |
| 181 | 181 | int n; |
| @@ -186,23 +186,30 @@ | ||
| 186 | 186 | n = strlen(g.argv[2]); |
| 187 | 187 | if( n>=2 && strncmp(g.argv[2],"new",n)==0 ){ |
| 188 | 188 | Blob passwd, login, contact; |
| 189 | 189 | |
| 190 | 190 | if( g.argc>=4 ){ |
| 191 | - blob_zero(&login); | |
| 192 | - blob_append(&login, g.argv[3], -1); | |
| 191 | + blob_init(&login, g.argv[3], -1); | |
| 193 | 192 | }else{ |
| 194 | 193 | prompt_user("login: ", &login); |
| 195 | 194 | } |
| 196 | 195 | if( db_exists("SELECT 1 FROM user WHERE login=%B", &login) ){ |
| 197 | 196 | fossil_fatal("user %b already exists", &login); |
| 198 | 197 | } |
| 199 | - prompt_user("contact-info: ", &contact); | |
| 200 | - prompt_for_password("password: ", &passwd, 1); | |
| 198 | + if( g.argc>=5 ){ | |
| 199 | + blob_init(&contact, g.argv[4], -1); | |
| 200 | + }else{ | |
| 201 | + prompt_user("contact-info: ", &contact); | |
| 202 | + } | |
| 203 | + if( g.argc>=6 ){ | |
| 204 | + blob_init(&passwd, g.argv[5], -1); | |
| 205 | + }else{ | |
| 206 | + prompt_for_password("password: ", &passwd, 1); | |
| 207 | + } | |
| 201 | 208 | db_multi_exec( |
| 202 | 209 | "INSERT INTO user(login,pw,cap,info)" |
| 203 | - "VALUES(%B,%B,'jnor',%B)", | |
| 210 | + "VALUES(%B,%B,'v',%B)", | |
| 204 | 211 | &login, &passwd, &contact |
| 205 | 212 | ); |
| 206 | 213 | }else if( n>=2 && strncmp(g.argv[2],"default",n)==0 ){ |
| 207 | 214 | user_select(); |
| 208 | 215 | if( g.argc==3 ){ |
| @@ -226,17 +233,21 @@ | ||
| 226 | 233 | db_finalize(&q); |
| 227 | 234 | }else if( n>=2 && strncmp(g.argv[2],"password",2)==0 ){ |
| 228 | 235 | char *zPrompt; |
| 229 | 236 | int uid; |
| 230 | 237 | Blob pw; |
| 231 | - if( g.argc!=4 ) usage("password USERNAME"); | |
| 238 | + if( g.argc!=4 && g.argc!=5 ) usage("password USERNAME ?NEW-PASSWORD?"); | |
| 232 | 239 | uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.argv[3]); |
| 233 | 240 | if( uid==0 ){ |
| 234 | 241 | fossil_fatal("no such user: %s", g.argv[3]); |
| 235 | 242 | } |
| 236 | - zPrompt = mprintf("new passwd for %s: ", g.argv[3]); | |
| 237 | - prompt_for_password(zPrompt, &pw, 1); | |
| 243 | + if( g.argc==5 ){ | |
| 244 | + blob_init(&pw, g.argv[4], -1); | |
| 245 | + }else{ | |
| 246 | + zPrompt = mprintf("new passwd for %s: ", g.argv[3]); | |
| 247 | + prompt_for_password(zPrompt, &pw, 1); | |
| 248 | + } | |
| 238 | 249 | if( blob_size(&pw)==0 ){ |
| 239 | 250 | printf("password unchanged\n"); |
| 240 | 251 | }else{ |
| 241 | 252 | db_multi_exec("UPDATE user SET pw=%B WHERE uid=%d", &pw, uid); |
| 242 | 253 | } |
| 243 | 254 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -165,17 +165,17 @@ | |
| 165 | ** |
| 166 | ** %fossil user list |
| 167 | ** |
| 168 | ** List all users known to the repository |
| 169 | ** |
| 170 | ** %fossil user new ?USERNAME? |
| 171 | ** |
| 172 | ** Create a new user in the repository. Users can never be |
| 173 | ** deleted. They can be denied all access but they must continue |
| 174 | ** to exist in the database. |
| 175 | ** |
| 176 | ** %fossil user password USERNAME |
| 177 | ** |
| 178 | ** Change the web access password for a user. |
| 179 | */ |
| 180 | void user_cmd(void){ |
| 181 | int n; |
| @@ -186,23 +186,30 @@ | |
| 186 | n = strlen(g.argv[2]); |
| 187 | if( n>=2 && strncmp(g.argv[2],"new",n)==0 ){ |
| 188 | Blob passwd, login, contact; |
| 189 | |
| 190 | if( g.argc>=4 ){ |
| 191 | blob_zero(&login); |
| 192 | blob_append(&login, g.argv[3], -1); |
| 193 | }else{ |
| 194 | prompt_user("login: ", &login); |
| 195 | } |
| 196 | if( db_exists("SELECT 1 FROM user WHERE login=%B", &login) ){ |
| 197 | fossil_fatal("user %b already exists", &login); |
| 198 | } |
| 199 | prompt_user("contact-info: ", &contact); |
| 200 | prompt_for_password("password: ", &passwd, 1); |
| 201 | db_multi_exec( |
| 202 | "INSERT INTO user(login,pw,cap,info)" |
| 203 | "VALUES(%B,%B,'jnor',%B)", |
| 204 | &login, &passwd, &contact |
| 205 | ); |
| 206 | }else if( n>=2 && strncmp(g.argv[2],"default",n)==0 ){ |
| 207 | user_select(); |
| 208 | if( g.argc==3 ){ |
| @@ -226,17 +233,21 @@ | |
| 226 | db_finalize(&q); |
| 227 | }else if( n>=2 && strncmp(g.argv[2],"password",2)==0 ){ |
| 228 | char *zPrompt; |
| 229 | int uid; |
| 230 | Blob pw; |
| 231 | if( g.argc!=4 ) usage("password USERNAME"); |
| 232 | uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.argv[3]); |
| 233 | if( uid==0 ){ |
| 234 | fossil_fatal("no such user: %s", g.argv[3]); |
| 235 | } |
| 236 | zPrompt = mprintf("new passwd for %s: ", g.argv[3]); |
| 237 | prompt_for_password(zPrompt, &pw, 1); |
| 238 | if( blob_size(&pw)==0 ){ |
| 239 | printf("password unchanged\n"); |
| 240 | }else{ |
| 241 | db_multi_exec("UPDATE user SET pw=%B WHERE uid=%d", &pw, uid); |
| 242 | } |
| 243 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -165,17 +165,17 @@ | |
| 165 | ** |
| 166 | ** %fossil user list |
| 167 | ** |
| 168 | ** List all users known to the repository |
| 169 | ** |
| 170 | ** %fossil user new ?USERNAME? ?CONTACT-INFO? ?PASSWORD? |
| 171 | ** |
| 172 | ** Create a new user in the repository. Users can never be |
| 173 | ** deleted. They can be denied all access but they must continue |
| 174 | ** to exist in the database. |
| 175 | ** |
| 176 | ** %fossil user password USERNAME ?PASSWORD? |
| 177 | ** |
| 178 | ** Change the web access password for a user. |
| 179 | */ |
| 180 | void user_cmd(void){ |
| 181 | int n; |
| @@ -186,23 +186,30 @@ | |
| 186 | n = strlen(g.argv[2]); |
| 187 | if( n>=2 && strncmp(g.argv[2],"new",n)==0 ){ |
| 188 | Blob passwd, login, contact; |
| 189 | |
| 190 | if( g.argc>=4 ){ |
| 191 | blob_init(&login, g.argv[3], -1); |
| 192 | }else{ |
| 193 | prompt_user("login: ", &login); |
| 194 | } |
| 195 | if( db_exists("SELECT 1 FROM user WHERE login=%B", &login) ){ |
| 196 | fossil_fatal("user %b already exists", &login); |
| 197 | } |
| 198 | if( g.argc>=5 ){ |
| 199 | blob_init(&contact, g.argv[4], -1); |
| 200 | }else{ |
| 201 | prompt_user("contact-info: ", &contact); |
| 202 | } |
| 203 | if( g.argc>=6 ){ |
| 204 | blob_init(&passwd, g.argv[5], -1); |
| 205 | }else{ |
| 206 | prompt_for_password("password: ", &passwd, 1); |
| 207 | } |
| 208 | db_multi_exec( |
| 209 | "INSERT INTO user(login,pw,cap,info)" |
| 210 | "VALUES(%B,%B,'v',%B)", |
| 211 | &login, &passwd, &contact |
| 212 | ); |
| 213 | }else if( n>=2 && strncmp(g.argv[2],"default",n)==0 ){ |
| 214 | user_select(); |
| 215 | if( g.argc==3 ){ |
| @@ -226,17 +233,21 @@ | |
| 233 | db_finalize(&q); |
| 234 | }else if( n>=2 && strncmp(g.argv[2],"password",2)==0 ){ |
| 235 | char *zPrompt; |
| 236 | int uid; |
| 237 | Blob pw; |
| 238 | if( g.argc!=4 && g.argc!=5 ) usage("password USERNAME ?NEW-PASSWORD?"); |
| 239 | uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.argv[3]); |
| 240 | if( uid==0 ){ |
| 241 | fossil_fatal("no such user: %s", g.argv[3]); |
| 242 | } |
| 243 | if( g.argc==5 ){ |
| 244 | blob_init(&pw, g.argv[4], -1); |
| 245 | }else{ |
| 246 | zPrompt = mprintf("new passwd for %s: ", g.argv[3]); |
| 247 | prompt_for_password(zPrompt, &pw, 1); |
| 248 | } |
| 249 | if( blob_size(&pw)==0 ){ |
| 250 | printf("password unchanged\n"); |
| 251 | }else{ |
| 252 | db_multi_exec("UPDATE user SET pw=%B WHERE uid=%d", &pw, uid); |
| 253 | } |
| 254 |