Skip to content

Commit

Permalink
CP-50079: Remove unused unixpwd function and its associated tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Sultanov <[email protected]>
  • Loading branch information
last-genius authored and lindig committed Jul 16, 2024
1 parent aa02b52 commit a0464a7
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 247 deletions.
36 changes: 0 additions & 36 deletions unixpwd/c/Makefile

This file was deleted.

117 changes: 0 additions & 117 deletions unixpwd/c/main.c

This file was deleted.

57 changes: 0 additions & 57 deletions unixpwd/c/unixpwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,60 +202,3 @@ unixpwd_setspw(const char *user, char *password)
ulckpwdf();
return 0;
}

char *
unixpwd_unshadow(void)
{
struct spwd spw,
*sp;
struct passwd pwd,
*pw;
char pwbuf[BUFLEN];
char spbuf[BUFLEN];

char *buf;
int size,
cur;

size = 1024;
cur = 0;
buf = malloc(size);
if (!buf) {
return NULL;
}

setpwent();
while (1) {
char tmp[BUFLEN];
int written;

if (getpwent_r(&pwd, pwbuf, BUFLEN, &pw) != 0 || !pw)
break;
getspnam_r(pw->pw_name, &spw, spbuf, BUFLEN, &sp);

written = snprintf(tmp, BUFLEN, "%s:%s:%d:%d:%s:%s:%s\n",
pw->pw_name,
sp ? sp->sp_pwdp : pw->pw_passwd,
pw->pw_uid,
pw->pw_gid,
pw->pw_gecos, pw->pw_dir, pw->pw_shell);
if (written >= BUFLEN) {
endpwent();
free(buf);
return NULL;
}
while (cur + written > size) {
size = size << 1;
buf = realloc(buf, size);
if (!buf) {
endpwent();
return NULL;
}
}
strncpy(buf + cur, tmp, size - cur);
cur += written;
}
endpwent();

return buf;
}
7 changes: 0 additions & 7 deletions unixpwd/c/unixpwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
char *unixpwd_get(const char *user);
char *unixpwd_getpwd(const char *user);
char *unixpwd_getspw(const char *user);
/*
* return /etc/passwd as a string but with entries from shadow passwords
* when they exist. The returned string must be passed to free(). On
* error, returns NULL and errno set.
*/

char *unixpwd_unshadow(void);

/*
* update password for user in /etc/passwd and /etc/shadow respectively
Expand Down
18 changes: 0 additions & 18 deletions unixpwd/c/unixpwd_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,3 @@ caml_unixpwd_setspw(value caml_user, value caml_password)
caml_failwith(strerror(rc));
CAMLreturn(Val_unit);
}

CAMLprim value
caml_unixpwd_unshadow(value unused)
{
CAMLparam1(unused);
char *passwords;
CAMLlocal1(str);

passwords = unixpwd_unshadow();
if (passwords == NULL && errno != 0)
caml_failwith(strerror(errno));
if (passwords == NULL)
caml_failwith("unspecified error in caml_unixpwd_unshadow()");

str = caml_copy_string(passwords);
free(passwords);
CAMLreturn(str);
}
4 changes: 0 additions & 4 deletions unixpwd/src/unixpwd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ module Stubs = struct
external setpwd : string -> string -> unit = "caml_unixpwd_setpwd"

external setspw : string -> string -> unit = "caml_unixpwd_setspw"

external unshadow : unit -> string = "caml_unixpwd_unshadow"
end

exception Error of string
Expand All @@ -39,5 +37,3 @@ let get user = wrap (fun () -> Stubs.get user)
let setpwd user pwd = wrap (fun () -> Stubs.setpwd user pwd)

let setspw user pwd = wrap (fun () -> Stubs.setspw user pwd)

let unshadow () = wrap Stubs.unshadow
7 changes: 0 additions & 7 deletions unixpwd/src/unixpwd.mli
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,3 @@ val setspw : string -> string -> unit
* for [user] in /etc/passwd and /etc/shadow, respectively. They raise
* [Error] on error.
*)

val unshadow : unit -> string

(* [unshadow] returns the contents of /etc/passwd as a string with
* passwords from /etc/shadow for users that have a corresponding entry.
* Raises [Error] on error.
*)
1 change: 0 additions & 1 deletion unixpwd/test/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ let default_user = "unixpwd"
let cycle user rounds n =
let pw = Printf.sprintf "unixpwd-%06d" n in
Unixpwd.setspw user pw ;
ignore (Unixpwd.unshadow () |> String.length) ;
assert (Unixpwd.getspw user = pw) ;
Unixpwd.setpwd user pw ;
assert (Unixpwd.getpwd user = pw) ;
Expand Down

0 comments on commit a0464a7

Please sign in to comment.